當我的程序進入while循環時,我努力從文本字段獲取用戶輸入。以前我的程序中使用的JOptionPane的,但現在,我正在依靠點擊一個按鈕,以孫中山信息到我的引擎類,我得到了許多錯誤在While循環中獲取TextField輸入而不是JOptionPane java
這裏是我的引擎
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");
}
}
}
}
的任何信息,你可以爲我提供會真的很有幫助,如果這太沒有針對性,我會很樂意發佈更多的信息,因爲你需要:)
你的textField在哪裏,你在哪裏使用它?你的while循環在哪裏? –