
// Applet displays the message "Hello World!".  When you click on
// the applet, the message changes colors, cycling through red,
// green, blue, and black

// David J. Eck, August 21, 1996

import java.awt.*;
import java.applet.*;

public class ColoredHelloWorld extends Applet {
            
    // displays a string "Hello World!" that changes
    // color when the user clicks on the applet
 
    private int currentColor = 1;  // initial color is red
 
    public void paint(Graphics g) {
       switch (currentColor) {  // select proper color for drawing
          case 0:
              g.setColor(Color.black); 
              break; 
          case 1:
              g.setColor(Color.red);
              break;
          case 2:
              g.setColor(Color.blue);
              break;
          case 3:
              g.setColor(Color.green);
              break;
       }
       g.drawString("Hello World!", 10, 30);
    }
    
    public boolean mouseDown(Event evt, int x, int y) {
       currentColor++;    // change the current color number
       if (currentColor > 3)
          currentColor = 0;
       repaint();        // ask the system to redraw the window
       return true;
    }
    
 }  // end of class ColoredHelloWorld

