继续或取消java

时间:2013-09-19 16:46:42

标签: java while-loop

好的,所以我对编程很陌生,而且我正在制作一个非常基本的税务计划。我不能使用jQuery。 我需要创建一个从用户返回stop或continue的方法。 然后我需要:

while (answer equals continue){

   code

   code 

   code

   call a method that returns either stop or continue from the user

}//end of while

我尝试在方法中使用JOptionPane,但我无法弄清楚如何在'while'部分使用该方法。

1 个答案:

答案 0 :(得分:1)

您需要将对话框的结果(JOptionPane)存储在布尔变量中。类似的东西:

boolean cnt = true;
while (cnt) {
    //... Do the stuff you want to do ...
    //update cnt variable using a JOptionPane
    cnt = JOptionPane.YES_OPTION == jOptionPane1.showConfirmDialog(this, "Do you want to continue?");
}
相关问题