过路的大侠:  我刚刚开始学J2SE。
我要实现这样一个功能:“鼠标左键选中JLabel中的图片,然后拖动图片到另一个空的JLabel中,释放鼠标,图片就停留在新的JLabel中了“如何去实现这个功能阿?谢谢啦

解决方案 »

  1.   

    用一个模拟的DND:
         注册监听MouseListener MouseMotionListener,重新设置两个Label上的图片,之后重绘
      

  2.   

    jButton1.addMouseListener(new MouseAdapter() {
                public void  mousePressed(MouseEvent e) {
                    Point origin=new Point();
                    origin.x = e.getX();
                    origin.y = e.getY();
                }
            });
                    
            jButton1.addMouseMotionListener(new MouseMotionAdapter() {
                public void mouseDragged(MouseEvent e) {
                    Point p = jButton1.getLocation();
                    Point origin=new Point();
                    jButton1.setLocation(p.x + e.getX() - origin.x, p.y + e.getY()
                    - origin.y);
                    repaint();
                }
            });
    一段类似的代码,希望能给你点提示
      

  3.   

    DropTarget dt = new DropTarget(this, new DropAdapter());
    class DropAdapter extends java.awt.dnd.DropTargetAdapter{}