我剛剛對uni項目得到了一些不好的反饋,需要一些公正的澄清;Swing組件聽自己vs內部類
任何人都可以解釋什麼時候應該使用(匿名)內部監聽器類與聽自己的組件? (A對B)
一)
public class myButton extends JButton {
public myButton() {
addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// handling code...
}
});
}
}
B)
public class myButton extends JButton implements ActionListener {
public myButton() {
addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
// handle the event
}
}
謝謝你們, 米奇
爲什麼擴展'JButton'? – 2011-05-02 10:36:07
請學習Java命名約定,並堅持他們 – kleopatra 2011-05-02 10:42:33
好老師,假設他/她拒絕了這兩項:-) – kleopatra 2011-05-02 10:47:42