Java by API/javax.swing.event/AncestorListener
Версия от 17:43, 31 мая 2010; (обсуждение)
implements AncestorListener
import javax.swing.JFrame;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
public class MainClass {
public static void main(String[] a) {
JFrame frame = new JFrame("Ancestor Sampler");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
AncestorListener ancestorListener = new AncestorListener() {
public void ancestorAdded(AncestorEvent ancestorEvent) {
System.out.println("Added");
}
public void ancestorMoved(AncestorEvent ancestorEvent) {
System.out.println("Moved");
}
public void ancestorRemoved(AncestorEvent ancestorEvent) {
System.out.println("Removed");
}
};
frame.getRootPane().addAncestorListener(ancestorListener);
frame.setSize(300, 200);
frame.setVisible(true);
frame.getRootPane().setVisible(false);
frame.getRootPane().setVisible(true);
}
}