home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-02-22 | 1.2 KB | 51 lines |
- import java.awt.*;
- import java.applet.*;
-
- public class FontApplet3 extends Applet
- {
- Button button;
- int fontNum;
-
- public void init()
- {
- button = new Button("Next Font");
- add(button);
- fontNum = 0;
- }
-
- public void paint(Graphics g)
- {
- Font font;
-
- if (fontNum == 0)
- font = new Font("Courier", Font.BOLD, 32);
- else if (fontNum == 1)
- font = new Font("TimesRoman", Font.BOLD, 32);
- else
- font = new Font("Helvetica", Font.BOLD, 32);
-
- g.setFont(font);
- FontMetrics fontMetrics = g.getFontMetrics(font);
- int height = fontMetrics.getHeight();
-
- int row = 80;
- g.drawString("This is the first line.", 20, row);
- row += height;
- g.drawString("This is the second line.", 20, row);
- row += height;
- g.drawString("This is the third line.", 20, row);
- row += height;
- g.drawString("This is the fourth line.", 20, row);
- }
-
- public boolean action(Event event, Object arg)
- {
- ++fontNum;
- if (fontNum == 3)
- fontNum = 0;
-
- repaint();
- return true;
- }
- }
-