Menu

[solved]-Guess Number Helpthe Static Showmessagedialog Accessed Static Way Import Javaxswingjoption Q39063964

Guess my number helpThe static showmessagedialog should be accessed in a static way ??import javax.swing.JOptionPane;import javax.swing.UIManager;import java.awt.Color;import java.util.Random;public class randomNumber { public static void main (String [] args) { UIManager.put(“OptionPane.background”, Color.white); UIManager.put(“Panel.background”, Color.white); UIManager.put(“Button.background”, Color.white); Random nextRandom = new Random(); int randomNum = nextRandom.nextInt(1000); boolean playerCorrect = false; String keyboardInput; int playerGuess; int numPlayerGuesses = 0; while( !playerCorrect) { numPlayerGuesses = numPlayerGuesses + 1; JOptionPane JOptionPane1 = new JOptionPane(); long startTime = System.nanoTime(); keyboardInput = JOptionPane1.showInputDialog(“Guess my number between 0 and 1000!”); UIManager.put(“OptionPane.background”, Color.white); UIManager.put(“Panel.background”, Color.white); playerGuess = Integer.parseInt( keyboardInput); if( playerGuess > randomNum) { JOptionPane JOptionPane2 = new JOptionPane(); UIManager.put(“OptionPane.background”, Color.red); UIManager.put(“Panel.background”, Color.red); JOptionPane2.showMessageDialog(null, “You guessed too high, try again!”); } else if ( playerGuess < randomNum) { JOptionPane JOptionPane3 = new JOptionPane(); UIManager.put(“OptionPane.background”, Color.blue); UIManager.put(“Panel.background”, Color.blue); JOptionPane3.showMessageDialog(null, “You guessed too low, try again!”); } else { JOptionPane JOptionPane4 = new JOptionPane(); long estimatedTime = System.nanoTime() – startTime; UIManager.put(“OptionPane.background”, Color.green); UIManager.put(“Panel.background”, Color.green); JOptionPane4.showMessageDialog(null, “Congrats! you guessed THE NUMBER!!! it only took you ” + numPlayerGuesses + ” tries in ” + estimatedTime + ” seconds!”); playerCorrect = true; } } System.exit(0); }

Expert Answer


Answer to Guess my number help The static showmessagedialog should be accessed in a static way ?? import javax.swing.JOptionPane;… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *