// sorry this program has not been tested or even compiled. // just want to give you some hint.class MyFrame extends JFrame { Point[] ps = new Point[2]; void init() { this.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { mouse_handler(e); } }); ... } void mouse_handler(MouseEvent e) { int x = e.get... int y = e.get... if(...) // distance of x,y to line greate than 123 return; ps[0]=ps[1] = null; repaint(); }public void paint(Graphics g) { super.paint(g); if(ps[0] != null) g.drawLine(ps[0].x,ps[0].y,ps[1].x, ps[2].y); }
介绍一点儿这方面的资料?
// just want to give you some hint.class MyFrame extends JFrame {
Point[] ps = new Point[2];
void init() {
this.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
mouse_handler(e);
}
});
...
}
void mouse_handler(MouseEvent e) {
int x = e.get...
int y = e.get...
if(...) // distance of x,y to line greate than 123
return;
ps[0]=ps[1] = null;
repaint();
}public void paint(Graphics g) {
super.paint(g);
if(ps[0] != null)
g.drawLine(ps[0].x,ps[0].y,ps[1].x, ps[2].y);
}