gpt4 book ai didi

java - 如何编写代码,以便在发生某事后不会再发生其他事情?

转载 作者:行者123 更新时间:2023-12-01 07:06:51 26 4
gpt4 key购买 nike

假设如果游戏的最后一个关卡被击败,那么您不会显示一个对话框询问玩家是否想要进入下一个关卡,而是显示主菜单。所以基本上,如果发生了某件事,那么之后应该发生的事情就不会发生。

private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             

final ImageIcon pokeballIcon = new ImageIcon("C:\\Users\\bacojul15\\Pictures\\pokeball5.gif");
final ImageIcon pokemoneggIcon = new ImageIcon("C:\\Users\\bacojul15\\Pictures\\nidoking.gif");
final ImageIcon pokemonredIcon = new ImageIcon("C:\\Users\\bacojul15\\Pictures\\red.gif");

String userAnswer = answertextArea.getText().trim();

if (userAnswer.equalsIgnoreCase(answers.get(questionNumber))) {

answerLabel.setText("Correct");
levelScore ++;
triviagui.totalScore ++;


} else {
answerLabel.setText("Incorrect");
}
answertextArea.setText("");
questionNumber++;
if(questionNumber == questions.size()){
JOptionPane.showMessageDialog(null, "Your score for this level was : " + levelScore + " out of 10. \n Your total score is " + triviagui.totalScore, "Scores",JOptionPane.INFORMATION_MESSAGE, pokeballIcon );
if(difficulty == 3){
JOptionPane.showMessageDialog(null, "Good job you beat the game! \n Your total score was " + triviagui.totalScore + " out of 30.", "Thanks for playing!", JOptionPane.INFORMATION_MESSAGE, pokemonredIcon);
triviagui.questionFrame.setVisible(false);
triviagui.mainFrame.setVisible(true);
}
int leveloptionPane = JOptionPane.showConfirmDialog(null,"Would you like to go on to the next level?" , "Next Level?", JOptionPane.YES_NO_OPTION, levelScore, pokemoneggIcon);
if(leveloptionPane == JOptionPane.YES_OPTION){
difficulty++;
triviagui.questionFrame.setVisible(false);
triviagui.questionFrame=new QuestionFrame(difficulty);
triviagui.questionFrame.setVisible(true);

}
if(leveloptionPane == JOptionPane.NO_OPTION){
triviagui.questionFrame.setVisible(false);
triviagui.mainFrame.setVisible(true);
}
return;
}
updateQuestionScore();

}

最佳答案

你只是想做:

if(something happens) {
return;
}

关于java - 如何编写代码,以便在发生某事后不会再发生其他事情?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22073386/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com