我正在用java编写学校的Hangman程序,我无法获得用户输入

时间:2015-03-17 13:32:04

标签: java while-loop keypress

我已经在这个程序上工作了几天,并且认为我找到了一个用户输入的好方法。当我尝试它时,Java似乎只是跳过循环。跳过的while循环是:

 while(textIN.getText() == "1")
 {
  final String text = textIN.getText();
  key = text.charAt(0);
 }

 while (length < lengthtemp)
 {
  Word = Word + WordD[length];
  length++;
 }

 while (lives > 0)
 {
  JOptionPane.showMessageDialog(null,"EnterLoop");
  while(textIN.getText() == "1")
  {      
   final String text = textIN.getText();
   key = text.charAt(0);
   JOptionPane.showMessageDialog(null,"WORK");
  }

  JOptionPane.showMessageDialog(null,"KeyPressed");
  length = 0;
  String TextTemp = Text.toString();
  while (length < lengthtemp)
  {
   if (key == WordD[length])
   {
    Text.setCharAt(length, WordD[length]);
    JOptionPane.showMessageDialog(null,"Correct Letter");
    Label.setText(Text.toString());
    if (Text.toString() == Word)
    {
     lives=-1;
    }
   }
   length++;
  }

  if (TextTemp == Text.toString())
  {
   lives--;
  }
 }
 if (lives == -1)
 {
  JOptionPane.showMessageDialog(null,"You Win");
 }

感谢您的帮助。

0 个答案:

没有答案