Java Example Program/ Sample Source Code
import java.awt.BorderLayout;
import java.awt.Checkbox;
import java.awt.Frame;
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JSplitPane;
class GetChangeFlagsExample {
public static void main(String args[]) {
Frame frame = new Frame("HierarchyEventExample");
final Checkbox checkbox1 = new Checkbox("Checkbox 1");
final Checkbox checkbox2 = new Checkbox("Checkbox 2");
final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
splitPane.addHierarchyListener(new HierarchyListener() {
@Override
public void hierarchyChanged(HierarchyEvent e) {
long flags = e.getChangeFlags();
System.out.println(e.getSource());
if ((flags & HierarchyEvent.SHOWING_CHANGED) == HierarchyEvent.SHOWING_CHANGED) {
splitPane.setDividerLocation(.75);
}
}
});
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
splitPane.setTopComponent(checkbox1);
splitPane.setBottomComponent(checkbox2);
frame.add(splitPane, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}
} |
|
|