//
import java.awt.*;

public class Example6 extends BufferedApplet
{
   int width = 0, height = 0, x, y;
   int colorMode = 0;

   public void render(Graphics g) {
      if (width == 0) {
         width  = bounds().width;
         height = bounds().height;
         x = width  / 2;
         y = height / 2;
      }

      // DRAW A CLEAR WHITE BACKGROUND

      g.setColor(Color.white);
      g.fillRect(0, 0, width, height);

      // DRAW A MESSAGE IN A BOX

      g.setColor(colorMode == 0 ? Color.blue : Color.red);
      g.drawRect(x, y-12, colorMode == 0 ? 33 : 53, 15);
      g.drawString(colorMode == 0 ? "hello" : "goodbye", x+3, y);
   }

   public boolean keyUp(Event e, int key) {
      switch (key) {
      case ' ':
        colorMode = 1 - colorMode;
        break;
      }
      damage = true;
      return true;
   }

   public boolean mouseDown(Event e, int x, int y) {
      setXY(x, y);
      return true;
   }

   public boolean mouseDrag(Event e, int x, int y) {
      setXY(x, y);
      return true;
   }

   void setXY(int x, int y) {
      this.x = x;
      this.y = y;
      damage = true;
   }
}