import java.applet.*; import java.awt.*; import java.awt.event.*; // note this is not the recommended way // create an inner class which implements ActionListener public class Button11 extends Applet implements ActionListener { Color textColor; Font textFont; public void init () { setBackground (Color.lightGray); textColor = Color.red; textFont = new Font ("Serif", Font.BOLD, 24); Button btn = new Button ("Click"); add (btn); btn.addActionListener (this); } public void paint (Graphics g) { g.setColor (textColor); g.setFont (textFont); g.drawString ("Hello World!", 30, 60); } public void actionPerformed (ActionEvent ae) { System.out.println ("hi " + textColor); if (textColor == Color.red) textColor = Color.green; else if (textColor == Color.green) textColor = Color.blue; else if (textColor == Color.blue) textColor = Color.red; repaint (); } }