This is my program which is suppose to make the image draggable in JFrame .
package testing;
import java.io.*;
import java.util.*;
import java.security.*;
import javax.xml.bind.DatatypeConverter;
import java.lang.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Testing
{
static class CPanel extends JPanel
{
CPanel()
{
this.setPreferredSize(new Dimension(200,100));
icon = new ImageIcon("./src/testing/cal.png");
jl = new JLabel(icon);
this.add(jl);
}
class CMotionListener implements MouseMotionListener
{
public void mouseMoved(MouseEvent event)
{
}
public void mouseDragged(MouseEvent event)
{
}
}
JLabel jl ;
ImageIcon icon;
}
public static void main(String[] args)
{
JFrame jf = new JFrame();
jf.setPreferredSize(new Dimension(1000,1000));
CPanel cp = new CPanel();
jf.add(cp);
jf.pack();
jf.setVisible(true);
}
}
CMotionListener
implements MouseMotionListener
and the method mouseDragged
is supposed to be overridden so that when i clicked on the image and dragged it , it will be dragged along with my mouse .
My problem is I am unsure how to go about overriding the method mouseDragged
so that the image can be dragged along with the mouse .