开发者

Creating a pop up box in Java

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 jus开发者_如何学运维t need a simple code which I can expand on.


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.


You shoudl check JDialog to create your custom message dialogs or you can use standard message dialogs in JOptionPane.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜