ActionEvent·Î ¹è°æ»öÀ» ¹Ù²Ù°í ±ÛÀÚ¸¦ »ðÀÔÇÏ´Â ¿¹Á¦
ActionEventTest.java
import java.awt.*;
import java.awt.event.*;
class ActionEventTest extends Frame {
Button b1, b2;
TextField tf1;
public ActionEventTest(){
setLayout(new FlowLayout());
ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent ae) {
if(ae.getSource() == b1) {
b1.setEnabled(false);
b2.setEnabled(true);
tf1.setBackground(Color.yellow);
tf1.setText(ae.getActionCommand());
}else {
b1.setEnabled(true);
b2.setEnabled(false);
tf1.setBackground(Color.white);
tf1.setText(ae.getActionCommand());
}
}
};
this.b1 = new Button("Enable");
this.b2 = new Button("Disable");
this.b2.setEnabled(false);
this.tf1 = new TextField(4);
this.b1.addActionListener(al);
this.b2.addActionListener(al);
this.add(b1);
this.add(b2);
this.add(tf1);
}
public static void main(String[] args) {
ActionEventTest f = new ActionEventTest();
f.pack();
f.setVisible(true);
}
}
C:\JavaExample\13>javac ActionEventTest.java
C:\JavaExample\13>java ActionEventTest
ActionListener¸¦ ¹öư¿¡ ´Þ¾ÆÁÖ¾î ActionEvent¹ß»ý½Ã ¹è°æ»öÀ» ¹Ù²Ù°í ±ÛÀÚ¸¦ ä¿ò
ActionEvent°¡ ¹ß»ýÇÏ´Â ÄÄÆ÷³ÍÆ®
n Button : Ŭ¸¯ÇßÀ» ¶§
n List : Ŭ¸¯ÇßÀ» ¶§
n TextField : ¿£ÅÍ۸¦ ÃÆÀ» ¶§
n MenuItem : Ŭ¸¯ÇßÀ» ¶§
n À§ ÄÄÆ÷³ÍÆ®¸¦ »ó¼ÓÇÏ´Â ¸ðµç ÄÄÆ÷³ÍÆ®µé(CheckboxMenuItem, Menu, PopupMenu)
jabookÀúÀÚ¸íÇÔ |
Á¦¸ñ:¼Ò¼³°°Àº¹Ì´ÏÄÚµå ÀÛ¼ºÀÚ:Àںϸâ¹ö ±è´ë¼º |