Reputation: 1299
I want to create a pop up box that is activated when I click a "Check" button. What it does is ask the user if they are sure about what they requested. If yes, it does the request. If no, it goes back to it's normal state.
I know what I said is a bit ambiguous but I want to create various types of pop up boxes.
So I was wondering is there a website that has generic pop up boxes with the code given?
I just need a simple code which I can expand on.
Upvotes: 1
Views: 17712
Reputation: 16262
I think JOptionPane is what you want.
showConfirmDialog
: Asks a confirming
question, like yes/no/cancel.showInputDialog
: Prompt for some
input.showMessageDialog
: Tell the
user about something that has
happened.showOptionDialog
: The Grand
Unification of the above three.A small example to get a Yes-No popup like you asked for would be:
if (JOptionPane.showConfirmDialog(null, "Are you sure about your request?", "Request",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE)
== JOptionPane.YES_OPTION)
{
//Do the request
}
else
{
//Go back to normal
}
This solution, however, only works if you are using Swing.
Upvotes: 4
Reputation: 3486
You shoudl check JDialog to create your custom message dialogs or you can use standard message dialogs in JOptionPane.
Upvotes: 3