【发布时间】:2011-11-27 20:45:28
【问题描述】:
这里是代码-
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
public final class SetLabelForDemo {
public static void main(String[] args){
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run() {
createAndShowGUI();
}
});
}
private static void createAndShowGUI(){
final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new JLabeledButton("foo:")); // new JLabeledButton("foo:") is the problem
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private final class JLabeledButton extends JButton{
public JLabeledButton(final String s){
super();
JLabel label = new JLabel(s);
label.setLabelFor(this);
}
}
}
这是错误信息 -
SetLabelForDemo 类型的封闭实例不可访问。必须 使用类型的封闭实例限定分配 SetLabelForDemo(例如 x.new A() 其中 x 是 SetLabelForDemo)。
我完全不明白这个错误。对我来说,一切似乎都是完全正确的。我错过了什么吗?
【问题讨论】:
-
这是一个非常糟糕的问题。 ://
-
如果你离开这个论坛去训练大脑,有时会发生这种情况 :-) 对于难以置信的问题 +1