Java Example Program/ Sample Source Code
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
class WindowGainedFocusDemo {
public static void main(String args[]) {
Frame frame = new Frame("WindowFocusListenerExample");
frame.pack();
frame.setSize(new Dimension(350, 250));
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.addWindowFocusListener(new WindowAdapter() {
public void windowGainedFocus(WindowEvent e) {
System.out
.println("WindowFocusListener method called: windowGainedFocus.");
}
public void windowLostFocus(WindowEvent e) {
System.out
.println("WindowFocusListener method called: windowLostFocus.");
}
});
}
} |
|
|