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

public class HelloWeb3 extends Applet
{
   int messageX = 125 ;
   int messageY = 95 ;
   String theMessage ;
   Button theButton ;
   Color [] someColors =
   {
      Color.black, Color.red, Color.green,
      Color.blue, Color.magenta
   } ;
   int colorIndex ;

   public void init() 
   {
      theMessage = getParameter("message") ;
      theButton = new Button("Change Color") ;
      add(theButton) ;
   }
   
   public void paint( java.awt.Graphics gc ) 
   {
      gc.setColor( currentColor() ) ;
      gc.drawString( theMessage, messageX, messageY ) ;
   }

   public boolean action ( Event e, Object arg )
   {
      if ( e.target == theButton ) 
      {
         changeColor() ;
         return true ;
      }
      return false ;
   }

   public boolean mouseDrag ( Event evt, int x, int y ) 
   {
      messageX = x ;
      messageY = y ;
      repaint() ;
      return true ;
   }

   synchronized private Color currentColor() 
   {
      return someColors[ colorIndex ] ;
   }
 
   synchronized private void changeColor() 
   {
      if ( ++colorIndex == someColors.length )
      {
         colorIndex = 0 ;
      }
      theButton.setForeground( currentColor() ) ;
      repaint() ;
   }
}
