The
listener interface for receiving ancestor moved and resized events.
When the hierarchy to which the Component belongs changes by the
resizing or movement of an ancestor, the relevant method in the
listener object is invoked, and the HierarchyEvent is passed to it.
void
ancestorMoved(HierarchyEvent e)
Called
when an ancestor of the source is moved.
void
ancestorResized(HierarchyEvent e)
Called
when an ancestor of the source is resized.
import java.awt.*; import java.awt.event.*; class HierarchyBoundsListenerInterfEx implements HierarchyBoundsListener{ public void ancestorMoved(HierarchyEvent e){ System.out.println("Hierarchy Added"); } public void ancestorResized(HierarchyEvent e){ System.out.println("Hierarchy Removed"); } }
import java.awt.event.*; import javax.swing.*; import java.awt.*; import java.io.*; class HierarchyBoundsListenerEx{ public static void main(String args[])throws Exception{ JFrame myFrame = new JFrame("Event Handling Example"); JButton button1 = new JButton("Button 1"); HierarchyBoundsListenerInterfEx obj1 = new HierarchyBoundsListenerInterfEx(); int count = 0; myFrame.setVisible(true); myFrame.setSize(250, 250); String str; /* Register Focus Lister */ myFrame.getContentPane().addHierarchyBoundsListener(obj1); /* Add Buttons to Button */ myFrame.add(button1); } }
Output
No comments:
Post a Comment