//Focus를 얻을때와 잃을때의 이벤트 처리 예제 입니다.
import java.awt.*;
import java.awt.event.*;
class FocusEventTest extends Frame implements FocusListener {
public FocusEventTest() {
super("Focus Event Test...");
setLayout(new FlowLayout());
Button b1 = new Button("Button1");
Button b2 = new Button("Button2");
TextField tf1 = new TextField("Text Field1");
TextField tf2 = new TextField("Text Field2");
b1.addFocusListener(this);
b2.addFocusListener(this);
tf1.addFocusListener(this);
tf2.addFocusListener(this);
addWindowListener(new WindowEventHandler());
add(b1); add(b2); add(tf1); add(tf2);
}
class WindowEventHandler extends WindowAdapter {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
}
public void focusGained(FocusEvent fe) {
System.out.println(fe);
System.out.println(fe.isTemporary());
}
public void focusLost(FocusEvent fe) {
System.out.println(fe);
System.out.println(fe.isTemporary());
}
public static void main(String[] args) {
Frame f = new FocusEventTest();
f.setSize(300, 200); f.setVisible(true);
}
}
import java.awt.*;
import java.awt.event.*;
class FocusEventTest extends Frame implements FocusListener {
public FocusEventTest() {
super("Focus Event Test...");
setLayout(new FlowLayout());
Button b1 = new Button("Button1");
Button b2 = new Button("Button2");
TextField tf1 = new TextField("Text Field1");
TextField tf2 = new TextField("Text Field2");
b1.addFocusListener(this);
b2.addFocusListener(this);
tf1.addFocusListener(this);
tf2.addFocusListener(this);
addWindowListener(new WindowEventHandler());
add(b1); add(b2); add(tf1); add(tf2);
}
class WindowEventHandler extends WindowAdapter {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
}
public void focusGained(FocusEvent fe) {
System.out.println(fe);
System.out.println(fe.isTemporary());
}
public void focusLost(FocusEvent fe) {
System.out.println(fe);
System.out.println(fe.isTemporary());
}
public static void main(String[] args) {
Frame f = new FocusEventTest();
f.setSize(300, 200); f.setVisible(true);
}
}
댓글 없음:
댓글 쓰기