home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java by Example
/
jbecd.bin
/
JBE-CD
/
NTUsers
/
JBECODE.ZIP
/
JavaByExample
/
chap17
/
FontApplet2.java
< prev
next >
Wrap
Text File
|
1996-02-22
|
1KB
|
41 lines
import java.awt.*;
import java.applet.*;
public class FontApplet2 extends Applet
{
TextField textField;
public void init()
{
textField = new TextField(10);
add(textField);
textField.setText("32");
}
public void paint(Graphics g)
{
String s = textField.getText();
int height = Integer.parseInt(s);
Font font = new Font("TimesRoman", Font.PLAIN, height);
g.setFont(font);
FontMetrics fontMetrics = g.getFontMetrics(font);
height = fontMetrics.getHeight();
int row = 80;
g.drawString("This is the first line.", 70, row);
row += height;
g.drawString("This is the second line.", 70, row);
row += height;
g.drawString("This is the third line.", 70, row);
row += height;
g.drawString("This is the fourth line.", 70, row);
}
public boolean action(Event event, Object arg)
{
repaint();
return true;
}
}