import java.applet.*; import java.awt.*; import java.awt.event.*; //import java.util.Stack; public class SillyApplet extends Applet implements ActionListener, ItemListener { private Button stopAndGo = new Button("stop"); private Checkbox mood = new Checkbox("happy"); private TextField dataValue = new TextField("", 10); private Label result; public void init() { add(stopAndGo); stopAndGo.addActionListener(this); add(dataValue); dataValue.addActionListener(this); add(mood); mood.addItemListener(this); result = new Label("______________________________"); } public void actionPerformed(ActionEvent e) { if (e.getSource() == stopAndGo) if (stopAndGo.getLabel().equals("stop")) stopAndGo.setLabel("go"); else stopAndGo.setLabel("stop"); else if (e.getSource() == dataValue) try { int num = (new Integer(dataValue.getText())).intValue(); dataValue.setText("" + 2 * num); } catch (NumberFormatException p) { System.out.println("Bad number in datavalue"); } } public void itemStateChanged(ItemEvent e) { if (mood.getState()) result.setText("Call home"); else result.setText("take a nap - you'll feel better"); } }