The
listener interface for receiving hierarchy changed events. When the
hierarchy to which the Component belongs changes, the
hierarchyChanged method in the listener object is invoked, and the
HierarchyEvent is passed to it.
import java.awt.*; import java.awt.event.*; class HierarchyListenerInterfEx implements HierarchyListener{ public void hierarchyChanged(HierarchyEvent e){ System.out.println("Hierarchy Changed"); } }
import java.awt.event.*; import javax.swing.*; import java.awt.*; import java.io.*; class HierarchyListenerEx{ public static void main(String args[])throws Exception{ JFrame myFrame = new JFrame("Event Handling Example"); JButton button1 = new JButton("Button 1"); HierarchyListenerInterfEx obj1 = new HierarchyListenerInterfEx(); int count = 0; myFrame.setSize(250, 250); /* Add Buttons to Button */ myFrame.add(button1); /* Register Focus Lister */ myFrame.getContentPane().addHierarchyListener(obj1); for(int i=0; i < 5; i++){ System.out.println("About to set visible status true"); myFrame.setVisible(true); Thread.sleep(3000); System.out.println("About to set visible status false"); myFrame.setVisible(false); } } }
Output
No comments:
Post a Comment