Java JFrame get window position after moving

Description

Java JFrame get window position after moving

import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;

import javax.swing.JFrame;

class MoveAdapter extends ComponentAdapter {
   public void componentMoved(ComponentEvent e) {
      int x = e.getComponent().getX();
      int y = e.getComponent().getY();
      System.out.println("x: " + x);
      System.out.println("y: " + y);
   }//from   w  ww. j  av a2 s .  c  o  m
}

public class Main {
   public static void main(String[] args) {
      JFrame f = new JFrame();

      f.addComponentListener(new MoveAdapter());

      f.setSize(310, 200);
      f.setLocationRelativeTo(null);
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      f.setVisible(true);
   }
}



PreviousNext

Related