// Written by: Darren Gates & Ray Klefstad // Date: January 2000 // School: U.C. Irvine import java.awt.*; import java.awt.event.*; import java.applet.*; public class ButtonsExample extends Applet implements ActionListener { private boolean colored; public void init() { colored = false; Button myButton = new Button("Click Me!"); // so actionPerformed will be called myButton.addActionListener(this); add(myButton); } public void actionPerformed(ActionEvent e) { if (colored == false) { setBackground(Color.cyan); colored = true; } else { setBackground(Color.lightGray); colored = false; } } }