0

当我的程序进入 while 循环时,我正在努力从 Textfield 获取用户输入。以前我的程序使用了 JOptionPane 但现在我依靠单击按钮将信息发送到我的引擎类我得到了很多错误

这是我的引擎

public class engine  {
public final Object buttonClickedLock = new Object(); // possible clean up
guess gs = new guess();
public  boolean close = true;
char [] charda = new char[20];
char [] charwo = new char[20];
Highscore words = new Highscore();
main mn = new main();
int guesses =7;
char guess;


public engine() {

}

public void enginer(char guess) { //throws for wait method


    int count = 0;


    String word = words.getWord();


    for(int i = 0; i<word.length(); i++)
    {
        //instantiates two arrays one of dahses and one with the word
        charwo[count] = word.charAt(i);
        charda[count]= '_';
        count++;
    }

    for(int l=0; l<count; l++)
        {
            System.out.print(" "+charda[l]);

        }

    while(guesses !=0 && !Arrays.equals(charwo, charda))
    {
        guess = guess; //This is previously where my JoptionPane went 



        if(word.toUpperCase().contains(String.valueOf(guess).toUpperCase()))
        {


            for(int k = 0; k<word.length(); k++)
            {
                if(String.valueOf(guess).toUpperCase().equals(String.valueOf(charwo[k]).toUpperCase()))
                {
                            charda[k]=charwo[k];

                                    for(int l=0; l<count; l++)
                            {   //prints dashes here to avoid a letter being chopped off by the program stopping in the middle
                                System.out.print(" "+charda[l]);

                            }
                }

              }

        }

        else
        {

                guesses = guesses-1;

                System.out.println("guesses left "+guesses);
                //Re-displays dashes 
                for(int l=0; l<count; l++)
                {
                System.out.print(" "+charda[l]);

                }

        }

           if(Arrays.equals(charwo, charda))
           {
               System.out.println("");
           System.out.println("You are Winner");

                    }
     }

}



}

您可以提供给我的任何信息都会非常有帮助,如果这太不具体,我会很乐意发布您需要的更多信息:)

4

1 回答 1

0

这段代码中 JOptionpane 的目的是什么?给定代码中的 JOptionPane 和 JTextField 之间没有关系。无论您是否放置 JoptionPane,您都可以始终从文本字段中获取输入。例如- String strTemp = textfield.getText();// 这将为您提供文本字段值。

我认为您正在将此 getText() 值直接传递给接受字符的方法 engine() 。您是否收到无效参数错误?

于 2013-08-29T11:54:43.120 回答