再次运行程序

时间:2013-11-25 21:46:54

标签: java panel option

我目前正在开发一个java版的扫雷。当用户点击我的游戏或赢得游戏时,我想实现一个是,没有选项面板,可以作为“你想再玩一次”的功能。实现no很简单,但我在实现yes选项时遇到问题,程序再次运行但在我的情况下它只是运行程序的新实例而不关闭旧实例。建议?感谢。

以下是用户找到所有地雷并获胜的代码:

 if (check == nomines)
           {
               endtime = System.nanoTime();
               Component temporaryLostComponent = null;
               JOptionPane.showMessageDialog(temporaryLostComponent, "Congratulations, you won! It took you " + (int)((endtime-starttime)/1000000000) + " seconds!");

               int p = JOptionPane.showConfirmDialog(this, "Play again?","Minefield",JOptionPane.YES_NO_OPTION);
               if (p == 1)
               {
                   System.exit(0); 
               }
               else 
               {
                   new Minefield(); 
               }

           }
       }

1 个答案:

答案 0 :(得分:2)

使用执行循环,可以轻松完成工作..

do{

  // your all operations...

 // at last prompt  yes or no ?
} while(choice.equalsIgnoreCase("yes"));