【发布时间】:2010-03-09 02:56:00
【问题描述】:
我有这个代码:
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 中遇到了这个错误。我只是在书中找到了一个(简化的)示例,不知道有什么问题。需要知识的眼睛! :)
【问题讨论】:
-
顺便说一句,在一个超类之后命名一个类可能会造成混淆。 java.sun.com/javase/6/docs/api/javax/swing/JFrame.html