我有這樣的代碼:對象不能被解析
public class Window extends JFrame {
public Window(){
...
JButton button = new JButton("OK");
getContentPane().add(button);
ButtonHandler handler = new ButtonHandler();
button.addActionListener(handler);
...
}
private class ButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent event){
if (event.getSource() == button){ // <--- "button can not be resolved"
System.out.println("Hello");
}
}
}
我得到這個錯誤在Eclipse中。我只是做了一本書中的(簡化的)例子,不知道什麼是錯的。需要知識眼睛! :)
順便說一句,這可能會產生混淆它的一個父的名字來命名的一類。 http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html – trashgod 2010-03-09 04:20:00