WORK/Sotfware
JAVA 버튼
KANG Stroy
2012. 1. 27. 18:01
728x90
728x90
아래의 예제는 NEW JAVA 언어입문에 나온 예제 입니다. 영진닷컴
1 import java.applet.Applet;
2 import java.awt.*;
3 import java.awt.event.*;
4
5 /*
6 <applet code="Btn1.class" width=300 height=50>
7 </applet>
8 */
9 // actionPerformed() 기술을 위해 implements ActionListener가 필요
10 public class Btn1 extends Applet implements ActionListener{
11 Label lb1;
12 Button btn1, btn2;
13
14 public void init(){
15 btn1 = new Button("BTN1"); // 버튼 오브젝트
16 btn1.addActionListener(this); // 이벤트 리스너 설정
17 add(btn1); // 애플릿 등록
18
19 btn2 = new Button("BTN2");
20 btn2.addActionListener(this);
21 add(btn2);
22
23 lb1 = new Label("클릭한 버튼이 표시됩니다."); // 라벨설정
24 add(lb1);
25 }
26
27 // 버튼이 클릭되면 이 메소드가 호출된다.
28 public void actionPerformed(ActionEvent e){
29 if(e.getSource() == btn1)
30 lb1.setText("BTN---1");
31 else
32 lb1.setText("BTN---2");
33 }
34 }
728x90