/*
This class is a basic extension of the Applet class. It would generally
be used as the main class with a Java browser or the AppletViewer. But
an instance can be added to a subclass of Container. To use this applet
with a browser or the AppletViewer, create an html file with the
following code:
itoa
You can add controls to itoa with Cafe Studio.
(Menus can be added only to subclasses of Frame.)
*/
import java.awt.*;
import java.applet.*;
public class itoa extends Applet {
Label prompt;
TextField input;
int n = 0, yPos = 70;
public void init() {
prompt = new Label("Please enter non-negative number: ");
input = new TextField(8);
add(prompt);
add(input);
}
public void paint(Graphics g) {
showStatus("The number is: " + n);
do {
g.drawString("The next digit is: " + (char) (n % 10 + '0'), 50, yPos += 15 );
} while ( (n /= 10) > 0 );
}
public boolean action(Event event, Object o) {
n = Integer.parseInt( input.getText());
input.setText("");
yPos = 70;
repaint();
return true;
}
}