/* 
	First.java

	java basics, 15-19.11.1999, juhuu@katastro.fi
*/

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

public class First extends Applet implements Runnable {
  Image imageDoubleBuffer;
  Graphics gDoubleBuffer;
  Thread engine = null;

  int x, y;

  int mousex, mousey;

  public void init() {
      // initialize double buffering
      imageDoubleBuffer = createImage(size().width, size().height);
      gDoubleBuffer = imageDoubleBuffer.getGraphics();
      gDoubleBuffer.setColor(Color.white);
      gDoubleBuffer.fillRect(0, 0, size().width, size().height);

      x = 50;
      y = 50;

      mousex = 0;
      mousey = 0;
  }

//----------------------------------------------------

  public void paint(Graphics g) {

	// clear the screen

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

	// draw an oval

    	gDoubleBuffer.setColor(Color.black);
    	gDoubleBuffer.fillOval(x, y + 30, 20, 50);  

	// draw all the stuff from the double buffer to the screen

	g.drawImage(imageDoubleBuffer, 0, 0, null);				
  }


//----------------------------------------------------


  // start the applet
  public void start() {
      if (engine == null) {
          engine = new Thread(this);
          engine.start();
      }
      showStatus(getAppletInfo());
  } 

  // stop the applet
  public void stop() {
     if (engine != null && engine.isAlive())
     {
         engine.stop();
     } 
     engine = null; 
  }

  public void run()
  {                  
     while (true)
     {
         try
         {
             repaint();
             Thread.sleep(10);
         } catch (InterruptedException e) {
             stop();
         }
     }                                  
  }

  public void update(Graphics g) {    
	paint(g);
  }

  // print to the console & browserstatus
  private void print(String s) {
    System.out.println(s); 		// console
    showStatus(s);         		// browser status  
  }

//---

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

  public boolean mouseMove(Event e, int x, int y)
  {
    mousex = x;
    mousey = y;
    return true;  
  }


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

//---

}
