java

ActionEventTestEx1

5DMK2]발자국 2014. 7. 3. 10:50

import java.awt.*;

import java.awt.event.*;

public class ActionEventTestEx1 {


public static void main(String[] args) {

Frame f = new Frame();

Button b1 = new Button("버튼111"); //이벤트 소스

Button b2= new Button("버튼222"); //이벤트 소스

Button b3= new Button("버튼333"); //이벤트 소스

f.setLayout(new FlowLayout());

f.setBounds(200, 200, 300, 300);

b1.addActionListener (new EventButton1());//리스터 등록

b2.addActionListener (new EventButton2());//리스터 등록

b3.addActionListener (new ActionListener(){

public void actionPerformed(ActionEvent e){//헨들러

System.out.println("익명클래스로 이벤트 처리");

}

});//리스터 등록

f.add(b1);

f.add(b2);

f.add(b3);

f.show();

}

}

class EventButton1 implements ActionListener{

public void actionPerformed(ActionEvent e){//헨들러

System.out.println("이벤트 발생");

}

}

class EventButton2 implements ActionListener{

public void actionPerformed(ActionEvent e){//헨들러

System.out.println("이벤트 발생1234");

}

}