Answers for "jframe draggable"

0

java draggable jframe

class MyWindow extends JFrame {
  int posX=0,posY=0;
  
  public MyWindow(){
   	this.setUndecorated(true);
  	this.addMouseListener(new MouseAdapter()
	{
   		public void mousePressed(MouseEvent e)
   		{
      		posX=e.getX();
      		posY=e.getY();
   		}
	});
  }
}
Posted by: Guest on March-06-2021
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

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language