Hello ,,,
am having trouble while making a drag and drop label
i wrote a code i'v seen on youtube , but after compiling i had punsh of Exception and i don't know why !!
can any one help me writing a drag and drop code , i'll post the code i'v wrote ,,
project about dragging label and drop it in another place on frame ...

Code :

import java.awt.event.*;
import javax.swing.*;

public class mouseDragandDrop extends JFrame implements MouseListener , MouseMotionListener {

    private boolean drag = false ;

    private JLabel lbl ;

    public mouseDragandDrop ()
    {
        try
        {
        lbl = new JLabel ("drag & drop");

        lbl.setBounds(0, 0, 100, 20);

        lbl.addMouseListener(this);
        lbl.addMouseMotionListener(this);


        add(lbl);
        }
        catch (Exception e)
        {
            System.out.println("Error is : " + e);
        }
    }

    @Override
    public void mouseClicked(MouseEvent e) {

    }

    @Override
    public void mousePressed(MouseEvent e) {
        drag =true ;
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        drag = false ;
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void mouseExited(MouseEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void mouseDragged(MouseEvent e) {
                if(drag == true )
        {
            lbl.setBounds(lbl.getBounds().x+e.getX(),lbl.getBounds().y+e.getY(), 100, 20);
        }
    }

    @Override
    public void mouseMoved(MouseEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public static void main (String args [])
    {
        mouseDragandDrop m = new mouseDragandDrop ();
        m.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        m.setSize(400, 400);
        m.setLocationRelativeTo(null);
        m.setVisible(true);
    }
}

i think that the proplem is in the drag code :

    public void mouseDragged(MouseEvent e) {
                if(drag == true )
        {
            lbl.setBounds(lbl.getBounds().x+e.getX(),lbl.getBounds().y+e.getY(), 100, 20);
        }
    }

thx for your help in advance ...`

i had punsh of Exception

Are you still getting errors? Please post the full text of the error messages.

error is about 3000 lines i'll post some of the Exception

    run:
    Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not supported yet.
        at movementgame.mouseDragandDrop.mouseEntered(mouseDragandDrop.java:57)
        at java.awt.Component.processMouseEvent(Component.java:6514)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
        at java.awt.Component.processEvent(Component.java:6270)
        at java.awt.Container.processEvent(Container.java:2229)
        at java.awt.Component.dispatchEventImpl(Component.java:4861)
        at java.awt.Container.dispatchEventImpl(Container.java:2287)
        at java.awt.Component.dispatchEvent(Component.java:4687)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
        at java.awt.LightweightDispatcher.trackMouseEnterExit(Container.java:4620)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4474)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
        at java.awt.Container.dispatchEventImpl(Container.java:2273)
        at java.awt.Window.dispatchEventImpl(Window.java:2713)
        at java.awt.Component.dispatchEvent(Component.java:4687)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
        at java.awt.EventQueue.access$000(EventQueue.java:101)
        at java.awt.EventQueue$3.run(EventQueue.java:666)
        at java.awt.EventQueue$3.run(EventQueue.java:664)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
        at java.awt.EventQueue$4.run(EventQueue.java:680)
        at java.awt.EventQueue$4.run(EventQueue.java:678)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
    Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not supported yet.
        at movementgame.mouseDragandDrop.mouseEntered(mouseDragandDrop.java:57)
        at java.awt.Component.processMouseEvent(Component.java:6514)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
        at java.awt.Component.processEvent(Component.java:6270)
        at java.awt.Container.processEvent(Container.java:2229)
        at java.awt.Component.dispatchEventImpl(Component.java:4861)
        at java.awt.Container.dispatchEventImpl(Container.java:2287)
        at java.awt.Component.dispatchEvent(Component.java:4687)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
        at java.awt.LightweightDispatcher.trackMouseEnterExit(Container.java:4620)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4474)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
        at java.awt.Container.dispatchEventImpl(Container.java:2273)
        at java.awt.Window.dispatchEventImpl(Window.java:2713)
        at java.awt.Component.dispatchEvent(Component.java:4687)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
        at java.awt.EventQueue.access$000(EventQueue.java:101)
        at java.awt.EventQueue$3.run(EventQueue.java:666)
        at java.awt.EventQueue$3.run(EventQueue.java:664)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
        at java.awt.EventQueue$4.run(EventQueue.java:680)
        at java.awt.EventQueue$4.run(EventQueue.java:678)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
    Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not supported yet.
        at movementgame.mouseDragandDrop.mouseEntered(mouseDragandDrop.java:57)
        at java.awt.Component.processMouseEvent(Component.java:6514)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
        at java.awt.Component.processEvent(Component.java:6270)
        at java.awt.Container.processEvent(Container.java:2229)
        at java.awt.Component.dispatchEventImpl(Component.java:4861)
        at java.awt.Container.dispatchEventImpl(Container.java:2287)
        at java.awt.Component.dispatchEvent(Component.java:4687)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
        at java.awt.LightweightDispatcher.trackMouseEnterExit(Container.java:4620)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4474)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
        at java.awt.Container.dispatchEventImpl(Container.java:2273)
        at java.awt.Window.dispatchEventImpl(Window.java:2713)
        at java.awt.Component.dispatchEvent(Component.java:4687)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
        at java.awt.EventQueue.access$000(EventQueue.java:101)
        at java.awt.EventQueue$3.run(EventQueue.java:666)
        at java.awt.EventQueue$3.run(EventQueue.java:664)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
        at java.awt.EventQueue$4.run(EventQueue.java:680)
        at java.awt.EventQueue$4.run(EventQueue.java:678)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

    BUILD SUCCESSFUL (total time: 4 seconds)

hope u can find what's wrong :S

Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not supported yet.
at movementgame.mouseDragandDrop.mouseEntered(mouseDragandDrop.java:57)

Look at line 57 in your program. What statement is there? Why is it there? Do some research about what that statement does. See how many places in the code that same statement is used.

it check's if the mouse dragged or not ..
is there any thing wrong with it ?

hmmm i just read the error correctly , what should i search for , can u help me withthat ?!
or just explain to me what to od ?!

omg i just removed the code

throw new UnsupportedOperationException("Not supported yet.");

throw new UnsupportedOperationException("Not supported yet.");

and it worked :S shame on me ,,

i'v wasted your time ...

thx for your help sir :)

This question has already been answered. Start a new discussion instead.