Graphic Java

This activity introduces working with fonts. In particular, this activity focuses on working with the size of a font. Working with fonts requires the use of the setFont method. The interesting thing about the setFont method is that it takes an argument of type Font. Here's an example:

   g.setFont(new Font("TimesRoman", Font.PLAIN, 12));
Any call to drawString following setFont will be displayed with that font until a new font is set. The student will need to call setFont seven times in this assignment. Each call will be identical except for the number provided to the last argument of Font. The student doesn't need to know this, but the Font method is the constructor of the Font class. So, this is an example of calling a method within another method. The above all can also be separated into two lines as in:
   Font f1 = new Font("TimesRoman", Font.PLAIN, 24);
   g.setFont(f1);
Either way of setting the font will work the same way. In complicated programs requiring lots of calls to setFont it is best to create global Font objects so that new Font objects aren't constructed each time the paint method is called. But for this activity the student doesn't need to be concerned about these issues.
EXAMPLE:
This applet is an approximation of what the student will be expected to create. No code will be offered since the student will need to experiment with the use of the setFont method in order to successfully complete this activity.

x

ASSIGNMENT:
The student will select a short phrase (at least fifteen letters long) and repeatedly display that phrase using different font sizes in the applet area. (Creative students may elect to use different phrases.) The phrase must be displayed seven times using the following font sizes: 12, 18, 24, 30, 36, 40, 48.