// W2frame.java click on points, connect the dots import java.awt.*; import java.awt.event.*; public class W2frame extends Frame { int boardSize; int x, y, b; int xp[] = new int[100]; int yp[] = new int[100]; int n; boolean connect; W2frame() { setTitle("W2frame"); setSize(400,400); setBackground(Color.white); setForeground(Color.black); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setVisible(true); 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(y>350) System.exit(0); if(b==3 && n>0) { connect=true; } else { n++; } requestFocus(); System.out.println("at x="+x+" y="+y+" b="+b); // debug print repaint(); } } public void paint(Graphics g) { // draw a boundary g.drawRect(20, 60, 360, 300); g.drawString("press button 1 for point, press button 3 to connect", 20, 50); g.drawString("press here to quit", 100, 380); for(int i=0; i