Hello ,,,
i'v started learning Game programming with java before 1 week and now am developing a drag and drop game , and am having a trouble with MouseListener and MouseMotionListener / drag and drop methods /
i just wrote a simple code i'v seen on web but i had an error while compiling and don't know what is wrong with the code ,,
the whole code :

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

any one can help me resolving this error or maybe explain to me how to rewrite this code or what this code means :

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

      }

thx in advance ,,,

Error was that i have to delete the Exceptions

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.