重启应用程序hangman

时间:2012-09-04 16:24:47

标签: java

我的hangman应用程序中有一个重启按钮,但我不知道如何重新启动应用程序......任何人都可以给我正确的想法或指向正确的方向吗?

public void actionPerformed(ActionEvent e){
    // Adds word to Words.txt
    if(e.getSource() == btnAddWord){
        try{
            FileWriter fw = new FileWriter("Words.txt", true);
            PrintWriter pw = new PrintWriter(fw, true);

            String word = JOptionPane.showInputDialog("Please enter a word: ");

            pw.println(word);
            pw.close();
        }
        catch(IOException ie){
            System.out.println("Error Thrown" + ie.getMessage());
        }
    }
    // Restarts game
    if(e.getSource() == btnRestart){

    }
    // brings up Help screen
    if(e.getSource() == btnHelp){
        String message = "The word to guess is represented by a row of dashes, giving the number of letters and category of the word."
               + "\nIf the guessing player suggests a letter which occurs in the word, the other player writes it in all its correct positions."
               + "\nIf the suggested letter does not occur in the word, the other player draws one element of the hangman diagram as a tally mark."
               + "\n"
               + "\nThe game is over when:"
               + "\nThe guessing player completes the word, or guesses the whole word correctly"
               + "\nThe other player completes the diagram";
       JOptionPane.showMessageDialog(null,message, "Help",JOptionPane.INFORMATION_MESSAGE);
    }
    //Exits application
    if(e.getSource() == btnExit){
        System.exit(0);
    }
}

1 个答案:

答案 0 :(得分:1)

快速而肮脏的方法是创建一个简单地将所有相关变量重置为其初始值的事件处理程序或方法。