// W2app.java click on points, connect the dots import java.awt.*; import java.applet.*; import java.awt.event.*; public class W2app extends Applet { int x, y, b; int xp[] = new int[100]; int yp[] = new int[100]; int n; boolean connect; public void init() { n=0; connect=false; this.addMouseListener (new mousePressHandler()); } class mousePressHandler extends MouseAdapter { public void mousePressed (MouseEvent e) { x = e.getX(); y = e.getY(); b = e.getButton(); xp[n]=x; yp[n]=y; if(b==3 && n>0) { connect=true; } else { n++; } requestFocus(); getAppletContext().showStatus("at x="+x+" y="+y+" b="+b); // debug print repaint(); } } public void paint(Graphics g) { // draw a boundary g.drawRect(1, 30, 298, 268); g.drawString("press button 1 for point, press button 3 to connect", 15, 20); for(int i=0; i