Show Message Dialogs
Learn how to display a message dialog.
We'll cover the following
A message dialog is a small window that displays a message.
Displaying a message dialog
What should Guess My Color do if the sample color matches the target color? Open a small window to congratulate the user.
- In
updateColorSample()
, check whether each color matches its target color. (Hint: addSystem.out.println
statements if you want to see the color values and target color values as you testGuessMyColor
. Be sure to remove allSystem.out.println
statements later.) - If all three colors match:
- Create a string called
message
to congratulate the user and tell him the color values. - Display
message
in a message dialog. Use JOptionPane’sshowMessageDialog()
method with this andmessage
as parameter values.
- Create a string called
...
private void updateColorSample() {
Color color = new Color(red, green, blue);
samplePanel.setBackground(color);
if(_____________ && _____________&& _____________) {
___________ message = ____________________;
JOptionPane.showMessageDialog(___________);
}
}
...
Get hands-on with 1200+ tech skills courses.