//Mousing.java generic mouse actions import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Mousing extends JApplet { int [] X; //points clicked so far int [] Y; int numPoints=0; //number of points so far int connectDots; public void init() { X = new int[1000]; //"limited" to 1000 points Y = new int[1000]; connectDots = JOptionPane.showConfirmDialog(null,"Connect the dots?", "connect the dots?", JOptionPane.YES_NO_OPTION); //incantation that responds to mouse click events: addMouseListener( //anonymous inner class overrides mouseClicked. //creates a $1 class file which must be uuploaded to web site new MouseAdapter() { public void mouseClicked( MouseEvent event) { int x = event.getX(); //gets X coord of mouse click event int y = event.getY(); showStatus("("+x+","+y+")"); X[numPoints] = x; //store it in array of points Y[numPoints] = y; numPoints++; //one more point so far repaint(); } } ); //incantation that responds to mouse move events: addMouseMotionListener( //anonymous inner class overrides mouseMoved //creates a $2 class file which must be uuploaded to web site new MouseMotionAdapter() { public void mouseMoved( MouseEvent event) { showStatus("("+event.getX()+","+event.getY()+")"); } } ); } public void paint ( Graphics g ) { super.paint( g ); g.setColor(Color.RED); //display all points so far: if (connectDots == JOptionPane.YES_OPTION) { g.fillOval(X[0]-2,Y[0]-2,3,3); //first point for (int i=1; i