home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java by Example
/
jbecd.bin
/
JBE-CD
/
NTUsers
/
JBECODE.ZIP
/
JavaByExample
/
chap07
/
Applet5.java
< prev
next >
Wrap
Text File
|
1996-02-01
|
982b
|
42 lines
import java.awt.*;
import java.applet.*;
public class Applet5 extends Applet
{
TextField textField1;
TextField textField2;
public void init()
{
textField1 = new TextField(5);
textField2 = new TextField(5);
add(textField1);
add(textField2);
textField1.setText("0");
textField2.setText("0");
}
public void paint(Graphics g)
{
int value1;
int value2;
int sum;
g.drawString("Type a number in each box.", 40, 50);
g.drawString("The sum of the values is:", 40, 75);
String s = textField1.getText();
value1 = Integer.parseInt(s);
s = textField2.getText();
value2 = Integer.parseInt(s);
sum = value1 + value2;
s = String.valueOf(sum);
g.drawString(s, 80, 100);
}
public boolean action(Event event, Object arg)
{
repaint();
return true;
}
}