Java JFrame handle component shown, hidden, moved, resized event

Description

Java JFrame handle component shown, hidden, moved, resized event

import java.awt.Dimension;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

import javax.swing.JFrame;

class My implements ComponentListener {
   public void componentHidden(ComponentEvent e) {
      System.out.println("componentHidden");
   }//  w w w  .  j av a  2  s  .  co  m

   public void componentMoved(ComponentEvent e) {
      System.out.println("componentMoved");
   }

   public void componentResized(ComponentEvent e) {
      System.out.println("componentResized");

   }

   public void componentShown(ComponentEvent e) {
      System.out.println("component shown");
   }
}

public class Main extends JFrame {
   public Main() {
      addComponentListener(new My());
   }

   public static void main(String[] arg) {
      Main m = new Main();

      m.setVisible(true);
      m.setSize(new Dimension(300, 100));
      m.setLocation(50, 50);
   }
}



PreviousNext

Related