Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
Different components have their font set, when the button is clicked. Clicking repeatedly causes some components to undergo a font enlargement.
For the TextField we create a new font from scratch :
and set it.
Arguments are type, style and size.
The same is done with the List, lst, but with a different, bold, font.
With the Label, lbl, we take a different approach. We ask it for its current font :...
and we use its size to create a new font instance.
Same is done for the TextArea, but here two styles are combined into one bit-pattern by using the logical OR, | .
Java Fonts to choose from.
The Graphics class also has a setFont method, so in a paint method you can issue :
gr.setFont ( .... );
before you do a gr.drawString .
Font.ITALIC and Font.BOLD are actually ints with values 2 and 1, respectively, so their bit-patterns are :
0000 0000 0000 0000 0000 0000 0000 0010
0000 0000 0000 0000 0000 0000 0000 0001
If these two are logically OR'ed, this is the resulting bit-pattern :
0000 0000 0000 0000 0000 0000 0000 0011
As of 1.2, there's the class java.awt.GraphicsEnvironment, that contains some convenient methods, such as getAvailableFontFamilyNames. This returns a String array containing the fonts that are available on the underlying platform, so you can fine-tune your application for a specific operating system. This, however, makes your code impure.