ButtonÀ» ¸¸µå´Â ¿¹Á¦
ButtonTest.java
import java.awt.*;
import java.awt.event.*;
public class ButtonTest extends Frame implements ActionListener {
Button b1, b2;
public ButtonTest() {
setLayout(new FlowLayout());
b1 = new Button("Ok");
b2 = new Button("Cancel");
add(b1);
add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == b1)
setTitle("¾È³ç!! ¼Ò¼³ÀÚ¹Ù");
else if(e.getSource() == b2)
setTitle("");
}
public static void main(String[] args) {
ButtonTest b = new ButtonTest();
b.setSize(200, 80);
b.setVisible(true);
}
}
C:\JavaExample\13>javac ButtonTest.java
C:\JavaExample\13>java ButtonTest
ButtonŬ·¡½º´Â ±âº» ¹öưÀ» »ý¼ºÇϵµ·Ï ÇØ ÁÖ¸ç ÀÌ·¸°Ô »ý¼ºµÈ ¹öưÀº »ç¿ëÀÚ°¡ ¹öưÀ» Ŭ¸¯ÇÒ ¶§¸¶´Ù ActionEvent¸¦ ¹ß»ý½ÃŲ´Ù. ±× À̺¥Æ®¸¦ ¹Þ¾Æ¼ ¿øÇÏ´Â ÀÛ¾÷À» ±¸ÇöÇØ ÁÖ¸é µÈ´Ù.
jabookÀúÀÚ¸íÇÔ |
Á¦¸ñ:¼Ò¼³°°Àº¹Ì´ÏÄÚµå ÀÛ¼ºÀÚ:Àںϸâ¹ö ±è´ë¼º |