2012-09-04 48 views
1

我有我的劊子手應用的重啓按鈕,但我對如何重新啓動應用程序...誰能給予我正確的想法或指向我朝着正確的方向幫助沒有線索?重新啓動應用劊子手

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); 
    } 
} 
+0

更改應用程序的狀態返回到它是什麼,當用戶啓動?我的意思是這裏唯一的答案。 – thatidiotguy

+0

爲什麼重新啓動?爲什麼不在一個while循環中重新初始化hangman框架/窗口,直到按下應該處理的關閉按鈕並調用System.exit()。 – Vikdor

+0

我將如何重新初始化框架 –

回答

1

快速和骯髒的方式來做它會做一個事件處理程序或方法,只是簡單地將所有相關變量重置爲其初始值。