gpt4 book ai didi

java - 重新启动应用程序刽子手

转载 作者:太空宇宙 更新时间:2023-11-04 08:04:37 25 4
gpt4 key购买 nike

我的 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);
}
}

最佳答案

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

关于java - 重新启动应用程序刽子手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12267645/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com