FileDocCategorySizeDatePackage
Click2.javaAPI DocExample3272Wed Apr 19 11:22:18 BST 2000None

Click2

public class Click2 extends Applet

Fields Summary
Color
puckColor
Box
puck
ColumnOfBoxes[]
targets
Constructors Summary
public Click2()

    MouseMotionListener movePuck = new MouseMotionAdapter() {
      public void mouseMoved(MouseEvent e)
      {
	int x = e.getX();
	int y = getSize().height - puck.getSize().height;
	puck.setLocation(x, y);
      }
    };

    /* Create a row of targets, i.e. columns of boxes, along
     * the top of the applet.  Each target column contains
     * between one and four boxes.
     */

    for(int i = 0; i < targets.length; i++) {
      int nBoxes = 1 + (int)(Math.random() * 4.0);
      float boxHue = (float)i / (float)targets.length;
      Color boxColor = Color.getHSBColor(boxHue, 0.5f, 0.85f);
      TargetListener tl = new TargetListener(boxColor.brighter());
      targets[i] = new ColumnOfBoxes(boxColor, nBoxes);
      targets[i].addMouseListener(tl);
      targets[i].addMouseMotionListener(tl);
      add(targets[i]);
    }

    add(puck);
    addMouseMotionListener(movePuck);
  
Methods Summary
public java.lang.StringgetAppletInfo()

 
    return "Click2 by Hans Mueller.  This version of the Click applet fixes Click1 by extending the nested TargetListener class with methods that redispatch the mouse motion events from the target columns to the applet.  Note that we're translating the events coordinates from the source components coordinate system to the applets coordinate system. This applet requires JDK 1.1.";
  
public java.lang.String[][]getParameterInfo()

    return null;
  
public static voidmain(java.lang.String[] args)

    WindowListener l = new WindowAdapter()
      {
	public void windowClosing(WindowEvent e) {System.exit(0);}
      };

    Frame f = new Frame("Click");
    f.addWindowListener(l); 
    f.add(new Click2());
    f.setSize(600, 400);
    f.show();