【问题标题】:Object references not being recognized [closed]对象引用未被识别[关闭]
【发布时间】:2015-05-03 07:19:30
【问题描述】:
private GameController gc = new GameController();

private boolean timerstart = false;

private JButton bhit = new JButton("HIT");

private JButton bstand = new JButton("STAND");

private JButton bdd = new JButton("DOUBLE DOWN");

// private JButton bsplit = new JButton("SPLIT")

private JButton 5chips = new JButton("5");
private JButton 10chips = new JButton("10");
private JButton 25chips = new JButton("25");
private JButton 100chips = new JButton("100");

private JTextArea tap = new JTextArea(5,5);

private JTextArea tad = new JTextArea(5,5);

private JTextArea tac = new JTextArea("Welcome to BlackJack Simulator!",1,5);

private Container cp = getContentPane();
// create the panel containing panels
private JPanel mainchippanel = new JPanel(new FlowLayout());
// create the panel to contain the buttons
private JPanel chipandta = new JPanel(new BorderLayout());

private JPanel chipbuttons = new JPanel(new FlowLayout());

private JPanel playeroptions = new JPanel(new FlowLayout());

private JPanel optnsandta = new JPanel(new BorderLayout());

private JPanel mainoptnpanel = new JPanel(new FlowLayout());

private JPanel handdisplays = new JPanel(new BorderLayout());

private JPanel main1 = new JPanel(new BorderLayout());

private JPanel main2 = new JPanel(new BorderLayout());

我正在制作一个小程序,由于某种原因,只有从 gc 到 bdd 的代码被识别,就好像 5chips 及以后的 JButton 中的所有代码都不存在。

我知道这一点是因为类视图没有显示对 bdd 之后的代码的引用,并且对于每个对 bdd 之后的对象的引用,输出不断给出“预期”错误。

我不知道为什么会发生这种情况,因此我们将不胜感激。谢谢。

【问题讨论】:

  • 您遇到了什么异常?..在问题中发布..并发布完整的课程代码..
  • 所以,代码没有编译,是你的问题吗?如果是这样,您从编译器获得的准确且完整的错误消息是什么?它指的是哪一行?
  • 无法识别?不理会类视图,请发布实际异常(不是 Eclipse 消息)和编译器给您的错误。清理你的项目并重建它,看看它是否消失了。
  • 原来问题出在芯片的变量名上。抱歉这个愚蠢的问题。

标签: java swing


【解决方案1】:

Java Tutorials

不能以带数字的变量名开头。 改为:

private JButton chips5 = new JButton("5");
private JButton chips10 = new JButton("10");
private JButton chips25 = new JButton("25");
private JButton chips100 = new JButton("100");

【讨论】:

  • 哦,是的,我忘记了这一切。非常感谢!
猜你喜欢
  • 2021-02-07
  • 1970-01-01
  • 1970-01-01
  • 2013-01-12
  • 2012-05-25
  • 2014-12-31
  • 2017-04-22
  • 1970-01-01
  • 2012-04-19
相关资源
最近更新 更多