JOptionPane makes it easy to pop up a standard dialog box that prompts users for a value or informs them of something.

1. Message Dialogs
This joptionpanes we can use for display messages to the users.To display a message here the code

import javax.swing.JOptionPane;

public class TestJoptionpane {

* @param args
public static void main(String[] args) {

String fname,lname;// two string type variables

fname = JOptionPane.showInputDialog("Enter your first Name?"); //getting the first name
lname = JOptionPane.showInputDialog("Enter your last Name?");	// getting last name

JOptionPane.showMessageDialog(null, "Your name is "+fname+" "+ lname);// display full name in the message



2. Confirm Dialogs

import javax.swing.JOptionPane; 

* @author Developer
public class message {

public void displayConfirmMessage(){

int opt= JOptionPane.showConfirmDialog(null, "Do you want to exit the program?","contact",JOptionPane.YES_NO_OPTION);


System.exit(1);// if user select yes program will exit



You can create objects of this class and call it when exit button clicked.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.