home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java by Example
/
jbecd.bin
/
JBE-CD
/
NTUsers
/
JBECODE.ZIP
/
JavaByExample
/
chap10
/
WhileApplet.java
< prev
Wrap
Text File
|
1996-02-07
|
992b
|
42 lines
import java.awt.*;
import java.applet.*;
public class WhileApplet extends Applet
{
TextField textField1;
TextField textField2;
public void init()
{
textField1 = new TextField(5);
textField2 = new TextField(5);
add(textField1);
add(textField2);
textField1.setText("1");
textField2.setText("10");
}
public void paint(Graphics g)
{
g.drawString("Enter start and end values above.", 50, 45);
String s = textField1.getText();
int start = Integer.parseInt(s);
s = textField2.getText();
int end = Integer.parseInt(s);
int total = 0;
int count = start;
while (count <= end)
total += count++;
s = "The total is: ";
s += String.valueOf(total);
g.drawString(s, 80, 70);
}
public boolean action(Event event, Object arg)
{
repaint();
return true;
}
}