Java AWT ComponentListener handle component event

Description

Java AWT ComponentListener handle component 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");
   }/*from w  ww  .  j  a  va 2  s. com*/

   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