FileDocCategorySizeDatePackage
HelloApplet.javaAPI DocExample1206Tue Jan 02 14:44:18 GMT 2001None

HelloApplet

public class HelloApplet extends JApplet
HelloApplet is a simple applet that toggles a message when you click on a Draw button.

Fields Summary
protected boolean
requested
The flag which controls drawing the message.
Constructors Summary
Methods Summary
public voiddo_the_work()
paint() is an AWT Component method, called when the component needs to be painted.

		/* If the Draw button is selected, draw something */
		if (requested) {
			showStatus("Welcome to Java!");
		} else {
			showStatus("");	// retract welcome? :-)
		}
	
public voidinit()
init() is an Applet method called by the browser to initialize

		JButton b;
		requested = false;
		Container cp = (Container)getContentPane();
		cp.setLayout(new FlowLayout());
		cp.add(b = new JButton("Draw/Don't Draw"));
		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();
			}
		});