用数学公式两点确定一条直线然后是判断某点是否在直线上好像初中就有学:)

解决方案 »

  1.   

    这个方法我知道,只是图像界面的编程不熟,
    介绍一点儿这方面的资料?
      

  2.   

    // 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);
    }