Answers for "Draggable jframe"

0

Draggable jframe

public class DragListener extends MouseInputAdapter
{
    Point location;
    MouseEvent pressed;
 
    public void mousePressed(MouseEvent me)
    {
        pressed = me;
    }
 
    public void mouseDragged(MouseEvent me)
    {
        Component component = me.getComponent();
        location = component.getLocation(location);
        int x = location.x - pressed.getX() + me.getX();
        int y = location.y - pressed.getY() + me.getY();
        component.setLocation(x, y);
     }
}
Posted by: Guest on July-01-2021

Browse Popular Code Answers by Language