0% found this document useful (0 votes)
51 views1 page

010 OptionPane

This document demonstrates the use of JOptionPane in Java to display different types of pop-up dialog boxes including message, question, warning, and error dialogs. It also shows how to display an input dialog to prompt for user input, a confirm dialog to get a yes/no response, and an option dialog to select from multiple options with a custom icon. The code provides examples of each type of dialog and stores the user's response in a variable.

Uploaded by

Momed Groove
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views1 page

010 OptionPane

This document demonstrates the use of JOptionPane in Java to display different types of pop-up dialog boxes including message, question, warning, and error dialogs. It also shows how to display an input dialog to prompt for user input, a confirm dialog to get a yes/no response, and an option dialog to select from multiple options with a custom icon. The code provides examples of each type of dialog and stores the user's response in a variable.

Uploaded by

Momed Groove
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

10 – JOptionPane

import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

public class Main


{

public static void main(String[] args)


{

// JOptionPane = pop up a standard dialog box that prompts users for a value
// or informs them of something.

//JOptionPane.showMessageDialog(null, "This is a message dialog box", "title",


JOptionPane.PLAIN_MESSAGE);
//JOptionPane.showMessageDialog(null, "Here is some useless info", "title",
JOptionPane.INFORMATION_MESSAGE);
//JOptionPane.showMessageDialog(null, "really?", "title",
JOptionPane.QUESTION_MESSAGE);
//JOptionPane.showMessageDialog(null, "Your computer has a VIRUS!", "title",
JOptionPane.WARNING_MESSAGE);
//JOptionPane.showMessageDialog(null, "CALL TECH SUPPORT OR ELSE!", "title",
JOptionPane.ERROR_MESSAGE);

//int answer = JOptionPane.showConfirmDialog(null, "bro, do you even code?");


//String name = JOptionPane.showInputDialog("What is your name?: ");

ImageIcon icon = new ImageIcon("smile.png");


String[] responses = {"No, you are!","thank you!","*blush*"};
int answer = JOptionPane.showOptionDialog(
null,
"You are the best! :D",
"Secret message",
JOptionPane.DEFAULT_OPTION,
0,
icon,
responses,
responses[0]);
System.out.println(answer);

}
}

You might also like