次のコードがあります。
public void actionPerformed(ActionEvent e) {
String userInput = commandInput.getText();
if (currentLevel == 0) {
if (userInput.equals(answers.getIntroAnswers().get(0)) || userInput.equals(answers.getIntroAnswers().get(1))) {
messageDisplay.append("\n \n" + userInput + "\n");
commandInput.setText("");
messageDisplay.append("\n" + messages.getNextMessage());
currentLevel++;
getCurrentLevel();
} else {
messageDisplay.append(notValid());
}
} else if (currentLevel == 1) {
// do the same as above but with the next set of answers
}
}
私がやりたいのは、どうにかしてこのアクションを独自のクラスに分離し、そのクラス内でメソッド /constructor を呼び出してこのチェックを行うことです。そうしないと、ネストされた if を使用してスタックし、非常に面倒で理解しにくくなります。currentLevel に基づいて対応する回答に対して userInput をテストするために、currentLevel と userInput のパラメーターを取得する方法を考えるのは正しいでしょうか? 以下は、関連する残りのクラスへのリンクです。