我想做一个这样的图形界面:
可以拖放组件,并且组件间可以用连接线连接,在拖动组件时,连接线跟着动,并且连接线可以响应鼠标事件
请高手给说一下思路,或者给段程序
谢谢

解决方案 »

  1.   

    下面的Label都是注册过MouseMotionListener_drag_icon的.
    class MouseMotionListener_drag_icon implements MouseMotionListener {
    static JLabel temp; static int x, y; public void mouseMoved(MouseEvent e) {
    } public void mouseDragged(MouseEvent e) {
    temp = ((JLabel) e.getSource());
    x = temp.getX() + e.getX() - 10;
    y = temp.getY() + e.getY() - 10;
    if (x > ((Dimension) UI.drawPanel.getSize()).width - 25) {
    x = ((Dimension) UI.drawPanel.getSize()).width - 25;
    }
    if (x < 5) {
    x = 5;
    }
    if (y > ((Dimension) UI.drawPanel.getSize()).height - 25) {
    y = ((Dimension) UI.drawPanel.getSize()).height - 25;
    }
    if (y < 5) {
    y = 5;
    }
    temp.setLocation(x, y);
    UI.drawPanel.repaint();
    }
    }
      

  2.   

    至于连线,可以用drawLine()方法来画,当调用repaint()方法时,会自动更新画面,连线会自己跟着动.