class Node extends JLabel implements MouseListener{
   int x,y;
   public Node(int x, int y){
      super(""); //or can be an icon
      setSize(2,2);
      this.x=x;
      this.y=y;
      setLocation(x,y);
      addMouseListener(this);
   }
   public int getX() ...getY()....
   public void mouseDragged(MouseEvent e){
      setLocation(e.getPoint());
   }
   ...... //other MouseListener methods
}abstract class MyShape{
   public abstract void draw(Graphics g);
}class Line extends MyShape{
   Node[] nodes=new Node[2];
   public Line(x1,y1,x2,y2){
      nodes[0]=new Node(x1,y1);....
   }
   public void draw(Graphics g){
      g.drawLine(nodes[0].getX(),nodes[0].getY(),.....);
   }
}IT'S JUST AN IDEA, HASN'T BEEN TESTED

解决方案 »

  1.   

    漏了一点,每次有node被托动,你的画板都应被更新,并调用所有MyShape.draw(Graphics)
      

  2.   

    看看这个 http://sourceforge.net/projects/jgraph/人家可是 Open source 的JGraph is the most powerful, lightweight, feature-rich, and thoroughly documented open-source graph component available for Java. It is accompanied by JGraphpad, the first free diagram editor for Java that offers XML, Drag and Drop and much more!
      

  3.   

    想自己写的话,看看这里:
    java.awt.dnd.*;
      

  4.   

    to shine333:我现在要画一个矩形的话,象word一样,能选中某个对象,并鼠标拖放改变大小