最近我在学校的AP计算机科学课上一直在研究一个日食项目。我的目标是使用JOptionPane窗口创建像Simon所说的游戏。我很清楚我需要做什么,除了我的一个问题是当我想非常快地关闭“Simon Says”窗口时,用户无法完全阅读该消息。我相信我将不得不使用我一直在寻找的摆动计时器。使用固定代码的响应会很棒,我目前只是初学者。因此,如果您添加计时器,请将其添加到简单级别。非常感谢!
import javax.swing.JOptionPane;
public class Random {
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "Welcome." );
JOptionPane.showInputDialog("Enter a nickname to play");
String[] choices = { "EASY", "HARD" };
String input = (String) JOptionPane.showInputDialog(null, "Choose now...",
"Difficulty", JOptionPane.QUESTION_MESSAGE, null,
choices, // Array of choices
choices[1]); // Initial choice
JOptionPane.showMessageDialog(null, "Your difficulty is " + input);
//For easy
if (input.equals("EASY"))
{
JOptionPane.showMessageDialog(null, "To play, click OK. A message bubble will come up, and have a command with either the words JAVA SAYS at the begginning, or with out the words. \nThe message bubble will be up for one half of a second and you will have to see if the beginning words are there. \nIf the words are there before the action, the correct thing to do is click the action and proceed. \nIf the words are not there, click the option to do nothing and proceed. If you fail to choose the correct choice, you will lose the game and have to restart.", "Instructions", JOptionPane.QUESTION_MESSAGE); //instructions here
{
JOptionPane.showOptionDialog(null, "Java says","Java Says", JOptionPane.DEFAULT_OPTION,JOptionPane.INFORMATION_MESSAGE, null, new Object[]{}, null);
}
}
// For Hard level
if (input.equals("HARD"))
{
JOptionPane.showMessageDialog(null, "To play, click OK. A message bubble will come up, and have a command with either the words JAVA SAYS at the begginning, or with out the words. \nThe message bubble will be up for one fourth of a second and you will have to see if the beginning words are there. \nIf the words are there before the action, the correct thing to do is click the action and proceed. \nIf the words are not there, click the option to do nothing and proceed. If you fail to choose the correct choice, you will lose the game and have to restart.", "Instructions", JOptionPane.QUESTION_MESSAGE); //instructions here
}
}
}