init() is an Applet method called by the browser to initialize
JButton b;
requested = false;
Container cp = (Container)getContentPane();
cp.setLayout(new FlowLayout());
String buttonLabel = getParameter("buttonlabel");
if (buttonLabel == null) {
buttonLabel = "Draw/Don't Draw";
}
cp.add(b = new JButton(buttonLabel));
b.addActionListener(new ActionListener() {
/* Button - toggle the state of the "requested" flag, to draw or
* not to draw.
*/
public void actionPerformed(ActionEvent e) {
String arg = e.getActionCommand();
// Invert the state of the draw request.
requested = !requested;
do_the_work();
}
});