I tried, no problem.
Import javax.swing.icon;
Import javax.swing.jooptionpane;
public class Cai shuzi 4 joptionpane {
/**
* @param args
*/
Public static void main(String[] args) {
Icon icon = null
Boolean bl = false
int put = 0;
int c =(int)(((math . random())* 100)+ 1); //Get a random number 1- 100.
System.out.println ("The random number you got is"+c "); //Print your random number.
String string 1 =(string) options pane. ShowInputDialog (null, "Please enter your guess number (1- 100): \ n", "Guess Numbers Game", Joption pane. Plain _ Message, icon, null, "enter here. //Enter your guess for the first time.
if(str 1==null){
Joptionpane。 Displays a message dialog box (empty, "You have cancelled this game"); //If you click Cancel, the game is over.
} Otherwise {
bl = num(str 1); //Determine whether the input is a number or an integer.
If(true==bl){ // If it is a number, enter the procedure of comparing with a random number.
System.out.println ("The number you entered is:"+str1); //Print the number you entered.
put = integer . value of(str 1);
for(int I = 4; I>0; I-) {//I is the number of times you can guess.
if(put==c){
The Joption pane. Displays a message dialog box (empty, "Congratulations on your guess. The correct answer is +c++. ); //If you guess correctly, end the loop.
Break;
} else if(put & gt; C){ // If you lose too much, you can lose again.
Str 1 = (string) options pane. ShowInputDialog (null, "Your input is too large. You still have the chance of "+i+", please re-enter: \n, "Guess Numbers Game", jooptionpane. Plain _ message, icon, null, "enter here");
if(str 1==null){
Joptionpane。 Displays a message dialog box (empty, "You have cancelled this input");
Break;
} Otherwise {
bl = num(str 1);
if(true==bl){
put = integer . value of(str 1);
} Otherwise {
Joptionpane。 Displays the message dialog box (empty, "Your input is incorrect, please re-enter");
}
}
} else if(put & lt; C){ // If you lose less, you will be re-entered.
Str 1 = (string) options pane. ShowInputDialog (null, "Your input is too small. You still have the chance of "+i+", please re-enter: \n, "Guess Numbers Game", jooptionpane. Plain _ message, icon, null, "enter here");
if(str 1==null){
Joptionpane。 Displays a message dialog box (empty, "You have cancelled this input");
Break;
} Otherwise {
bl = num(str 1);
if(true==bl){
put = integer . value of(str 1);
} Otherwise {
Joptionpane。 Displays the message dialog box (empty, "Your input is incorrect, please re-enter");
}
}
}
}
}else if(bl==false){ // This is the first time you will end the game without filling in numbers.
Joptionpane。 The message dialog box is displayed (empty, please fill it in as required next time. Game over ");
}
if(true = = bl & amp; & ampc! =put){ // If you don't say it right the first time, I'll tell you what it is.
Joptionpane。 Displays a message dialog box (empty, "I'm sorry you didn't guess correctly, the number is" +c+ "." );
}
}
}
Public static Boolean num (String value) {//Static method to determine whether a number is entered.
Try {
integer . parse int(value);
Return true
Catch (exception e) {
Returns false
}
}
}