首页 > 解决方案 > 在 scopeJava(16777238) 中无法访问 XXXX 类型的封闭实例

问题描述

如果有人能帮助我理解为什么我的代码不起作用,我将不胜感激!我对Java比较陌生,所以请期待一些noobish错误。另外,如果有必要帮助我解决这个问题,我也可以在这里发布我的代码的其他文件。谢谢你。

  1. 包装型号;

    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import java.awt.event.ActionEvent;
    
    import Controller.WordGuess;
    import Controller.Dictionary;
    
    class Observer implements ActionListener 
    {
        public void actionPerformed(ActionEvent paramActionEvent)
        {
            JButton jButton = (JButton)paramActionEvent.getSource();
    
            if(jButton == WordGuess.this.newGameButton)
            {
                for(JButton jButton1 : WordGuess.this.keys)
                {
                    jButton1.setEnabled(true);
                }
    
                String str1 = Dictonary.getWord();
                WordGuess.this.gameKey.setText(str1);
                String str2 = "";
    
                for(int b = 0; b < str1.length(); b++)
                {
                    str2 = str2 + ".";
                }
    
                WordGuess.this.progressStatus.setText(str2);
                WordGuess.this.lifeCount = 5;
                WordGuess.this.status = 0;
                WordGuess.this.gameOver = false;
            } else {
                jButton.setEnabled(false);
                char c = jButton.getText().charAt(0);
                char[] arrayofChar = WordGuess.this.progressStatus.getText().toCharArray();
                String str = WordGuess.this.gameKey.getText();
                boolean bool = false;
    
                for(int b = 0; b < str.length(); b++)
                {
                    if (c == str.charAt(b))
                    {
                        arrayofChar[b] = c;
                        bool = true;
                    }
                }
    
                if (bool) {
                    WordGuess.this.progressStatus.setText(new String(arrayofChar));
    
                    if(!WordGuess.this.progressStatus.getText().contains("."))
                    {
                        WordGuess.this.status = 1;
                        WordGuess.this.gameOver = true;
                    }
                } else {
                    WordGuess.this.lifeCount--;
    
                    if(WordGuess.this.lifeCount == 0)
                    {
                        WordGuess.this.status = 2;
                        WordGuess.this.gameOver = true;
                    }
                }
            }
    
            WordGuess.this.repaint();
    
        }
    }
    

标签: java

解决方案


推荐阅读