
/*
 *  This applet demonstrates mouse events and mouse motion events.
 *  The user can click-and-drag on the applet to draw a line of
 *  big blue dots.  The user can right-click on the applet to
 *  clear the drawing.  (Note:  this applet does not redraw itself
 *  properly if it is covered up and then uncovered.  The user's
 *  drawing is not restored.)
 */

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

public class MouseDemo1 extends Applet 
                 implements MouseListener, MouseMotionListener {
                     

   /*
    *  The init() method is called by the system so that the
    *  applet will have a chance to initialize itself.  Here, I
    *  just set a background color and register the applet
    *  to listen for mouse events and mouse motion events
    *  on itself.
    */
   public void init() {
      setBackground( new Color(0,200,0) );
      addMouseListener(this);
      addMouseMotionListener(this);
   }
   
   
   /*
    *  The paint() method is called by the system when the applet
    *  has to paint or repaint itself.  Here, it just draws a
    *  border around the applet.  It does NOT restore any drawing
    *  that the user has done.
    */
   public void paint(Graphics g) {
      g.setColor( new Color(0,100,0) );
      g.drawRect( 0, 0, getSize().width-1, getSize().height-1);
      g.drawRect( 1, 1, getSize().width-3, getSize().height-3);
   }
   

   //----------- Methods required by the MouseMotion interface ---------
   
   public void mousePressed(MouseEvent evt) {
        // Check if user clicked the right mouse button.  If so,
        // call repaint() so the applet will be redrawn.  (This
        // effectively clears the applet.)
      if (evt.isMetaDown()) {
         repaint();
      }
   }

   public void mouseReleased(MouseEvent evt) {
   }

   public void mouseClicked(MouseEvent evt) {
   }

   public void mouseEntered(MouseEvent evt) {
   }

   public void mouseExited(MouseEvent evt) {
   }


   //------- Methods required by the MouseMotionListener interface -----
   
   public void mouseDragged(MouseEvent evt) {
        // Draw a big blue dot centeed at the mouse's (x,y) position.
      Graphics g; // A graphics context for drawing in the applet.
      int x, y;   // more convenient names for the mouse position
      x = evt.getX();
      y = evt.getY();
      g = getGraphics();
      g.setColor( Color.blue );
      g.fillOval( x-10, y-10, 21, 21 );
      g.dispose();
   }
   
   public void mouseMoved(MouseEvent evt) {
   }

} // end class MouseDemo1

