Java中ShowOptionDialog的替代方案

时间:2013-12-04 10:59:05

标签: java

所以目前我有

    public boolean start(){        
        boolean validInput = false;   
        String input = null;
        int nextMove;
        Object[] options = { "Move Hek", "Move Back", "Exit Game" };
        int newEnemyAtMoveNo = 0;
        do{
            displayCharPositions();
            if(!checkOgreAlive()){                
                System.out.println("Ogre Dead!!");
                JOptionPane.showMessageDialog(null, "Hek Died! \nGame Over!");
                return false;
          }
            input = Array.get(moves, new Random().nextInt(8)).toString(); 

                    nextMove = JOptionPane.showOptionDialog(null, "What will you do next? " + Ogre , "Your move",
                    JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
                    null, options, options[0]);
            if(nextMove == JOptionPane.YES_OPTION)
            {           
                validInput = moveCharacter(Ogre,input);
                if(!validInput){
                    if(!input.equals("E"))
                        System.out.println("Invalid move! Try Again");
                }
                else {                
                    moveNo ++;
                    System.out.println("Move No.: " + (moveNo+1));
                    moveEachEnemy();
                    if(moveNo % 3 == 0)                    
                        newEnemyAtMoveNo = new Random().nextInt(3);                
                    if(moveNo % 3 == newEnemyAtMoveNo)
                        enterNewEnemy();                
                }}
        }while(nextMove != JOptionPane.CLOSED_OPTION && nextMove != JOptionPane.CANCEL_OPTION);
        int saveResult = JOptionPane.showConfirmDialog(null, "Would you like to save the game?", null, JOptionPane.YES_NO_OPTION);
        if(saveResult == JOptionPane.YES_OPTION)
            return true;
        else
            return false;

    }

是否有弹出框的替代品,例如我可以在Gui上放置按钮来替换输入框吗?

但是,如果我没有停止循环的东西(例如showMessageDialog),程序就会运行完毕。

所以基本上,我可以使用与showMessageDialog相同的功能,但是使用Gui上的按钮而不是弹出一个框?

0 个答案:

没有答案