当我的程序进入 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");
}
}
}
}
您可以提供给我的任何信息都会非常有帮助,如果这太不具体,我会很乐意发布您需要的更多信息:)