나는 자바를 가르치려고 노력 중이며 지금까지 대답 할 수 없다는 의문을 가지고있다. 온라인 독서 중 일부에서는 동일한 일을하는 것처럼 보이는 행동 청취자를 사용하는 두 가지 방법을 발견했습니다. 그러나 나는 다른 것의 장점/단점이 무엇인지 알아 내려고 노력 중이다.자바 액션 리스너 : 익명 클래스 구현
은 다음과 같이 익명 클래스를 사용하는 것이 더 좋은가요 :
public MyClass() {
...
myButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
//doSomething
}
});
...
}
을 정도 같은 클래스의 시작 부분에 구현하는 것이 최선이다 :
이public MyClass() implements ActionListener {
...
myButton.addActionListener(this);
public void actionPerformed(ActionEvent e) {
//doSomething
}
...
}
가능한 중복 : http://stackoverflow.com/questions/5451010/nested-class-vs-implements-actionlistener –