How can we use JOptionPane class in creating different types of dialog boxed explain with suitable syntax.
Using JOptionPane
Using JOption Pane, you can quickly create and customize several different kinds of dialogs. JOption Pane provides support for laying out standard dialogs, providing icons, specifying the dialog title and text, and customizing the button text. A Dialog can be model When a modal Dialog is visible, it blocks user input to all other windows in the programGUI with Swing.
JOptionPane creates /Dialogs that are modal. To create a non-modal Dialog, you must use the /Dialog class directly. JOptionPane's icon support lets you easily specify which icon the dialog displays. We can use a custom icon, no icon at all, or any one of four standard JOptionPane icons (question, information, warning, and error).
By using the JOption Pane class we can create different types of dialog boxes a below:
Confirm Dialog: we can create confirm dialog box by calling JOptionPanes show ConfirmDialog( method. These dialog boxes ask a confirmation question and receive yes/no/cancel response. This method can be used with the following signature JOption Pane.showConfirm Dialog(parent_frame, msg, title, msg_options)
Message options can be any one of the following: DEFAULT OPTION, YES_NO_OPTION, YES_NO_CANCEL OPTION, OK CANCEL OPTION.
Example:
JOption Pane.showMessageDialog(frame, "DoYou Want to Exit?", "Alert",)
Do JOptionPane.YES_NO_CANCEL_OPTION)
Output looks like below:
Message Dialog: we can create a message dialog box by calling JOptionPanes show MessageDialog() method. These dialog boxes tell the user about something that has happened. This method can be used with the following signature
JOption Pane.showMessageDialog(par_frame, msg, title, msg_types, icon)
The message type can be any one of following: INFORMATION MESSAGE, ERROR_MESSAGE, WARNING MESSAGE, QUESTION_MESSAGE, PLAIN_MESSAGE
Example:
JOptionPane.showMessageDialog (frame, "Supplyall required values", "Not Empty", JOptionPane.INFORMATION MESSAGE)
Input Dialog: we can create an input dialog box by calling the JOptionPanes showInput Dialo method. These dialog boxes prompt users for some input.. This method can be used with the following signature
JOption Pane.showInput Dialog(parent_frame, msg, title)
Example:
String num;
num JOptionPane.showMessageDialog (frame,"Enter any Number", "Input")
Output looks like below:
Option Dialog: we can create option dialog box by calling JOptionPanes showOption Dialog() method. This dialog supports the unification of the above three dialog boxes allows us to create a configurable dialog box. This method can be used wi the following signature
JOption Pane.show Option Dialog(parent_frame, msg, title, option_type, msg_ty icon, options, default_option)
Comments
Post a Comment