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.

  1. In updateColorSample(), check whether each color matches its target color. (Hint: add System.out.println statements if you want to see the color values and target color values as you test GuessMyColor. Be sure to remove all System.out.println statements later.)
  2. 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’s showMessageDialog() method with this and message as parameter values.
...
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.