import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class Main {
public static void main(String[] argv) throws Exception {
JTextField component = new JTextField();
component.addFocusListener(new MyFocusListener());
JFrame f = new JFrame();
f.add(component);
f.setSize(300, 300);
f.setVisible(true);
}
}
class MyFocusListener extends FocusAdapter {
public void focusGained(FocusEvent evt) {
System.out.println("component gained the focus");
}
public void focusLost(FocusEvent evt) {
System.out.println("component lost the focus");
}
}
|