Java Swing Tutorial - Java ComponentEvent(Component source, int id) Constructor








Syntax

ComponentEvent(Component source, int id) constructor from ComponentEvent has the following syntax.

public ComponentEvent(Component source,    int id)

Example

In the following code shows how to use ComponentEvent.ComponentEvent(Component source, int id) constructor.

//from   w  ww  .ja v  a  2  s . co  m
import java.awt.Component;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

import javax.swing.JFrame;

public class Main implements ComponentListener {

  @Override
  public void componentShown(ComponentEvent evt) {
    System.out.println(evt.getID()== ComponentEvent.COMPONENT_FIRST);
    ComponentEvent event = new ComponentEvent((Component)evt.getSource(), ComponentEvent.COMPONENT_MOVED);
    
  }
  @Override
  public void componentResized(ComponentEvent e) {
    
  }
  @Override
  public void componentMoved(ComponentEvent e) {
  }
  @Override
  public void componentHidden(ComponentEvent e) { 
  }
  public static void main(String[] args) {
    JFrame frame = new JFrame("");
    frame.pack();
    
    frame.addComponentListener(new Main());
    frame.setVisible(true);
  }


}