【发布时间】:2014-02-25 17:06:42
【问题描述】:
我有一个游戏程序,要求用户猜测给定的打乱单词。
例如: 乱码:loglab 你的猜测:
这个词是全局的,每次我输入“GLOBAL”时,它都会说这个词不正确。我尝试使用 toUpperCase 但它没有用。我的程序如何能够接受输入的字符串,即使它是大写的?下面是我的一些代码。因为太长,我不会全部发布,但是如果您需要更多内容,请告诉我。请帮我解决这个问题谢谢。
StaticWordLibrary.java:
public boolean isCorrect(int idx, String userGuess) {
return userGuess.equals(getWord(idx));
}
WordLibrary.java:
public abstract boolean isCorrect(int idx, String userGuess);
Anagrams.java:
private void guessedWordActionPerformed(java.awt.event.ActionEvent evt) {
if (wordLibrary.isCorrect(wordIdx, guessedWord.getText())){
JOptionPane.showMessageDialog(null, "Your answer is correct! Guess another word.","", JOptionPane.INFORMATION_MESSAGE);
getRootPane().setDefaultButton(nextTrial);
} else {
JOptionPane.showMessageDialog(null, "Your answer is incorrect! Please try again.","", JOptionPane.ERROR_MESSAGE);
guessedWord.setText("");
}
guessedWord.requestFocusInWindow();
}
【问题讨论】: