Anonymous Class
클래스 정의와 객체 생성을 한 번에 한다.
import java.awt.*;
class Ex7_18 {
public static void main(String[] args) {
Button b = new Button("start");
b.addActionListener(new EventHandler());
}
}
class EventHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.out.println("ActionEvent occured!!!");
}
}
Anonymous Class :
import java.awt.*;
class Ex7_18 {
public static void main(String[] args) {
Button b = new Button("start");
b.addActionListener(new EventHandler(){
public void actionPerformed(ActionEvent e) {
System.out.println("ActionEvent occured!!!");
}
});
}
}
Last updated