12 - Java Option Panes

Share:

Java Option Panes

Another useful class for accepting user input, and displaying results, is the JOptionPane class. This is located in the javax.swing library. The JOptionPane class allows you to have input boxes like this one:
A JOptionPane Input box
And message boxes like this:
A JOptionPane message box
The first thing to do is to reference the library we want to use:
import javax.swing.JOptionPane;
This tells java that we want to use the JOptionPane class, located in the javax.swing library.
So we can do a small exercise. now create the new java project.
Now run your programme. You'll see the Enter your First Name input box. Type something into it, then click OK

Then You'll see the Enter your Last Name input box. Type something into it, then click OK.

Then you'll see the final out put. then click Ok the programme will end.
Try to change the variables and find the different answers.

we can display different type of message using JOptionPane library class.
ERROR_MESSAGE
PLAIN_MESSAGE
QUESTION_MESSAGE
WARNING_MESSAGE


No comments