Ved
Ved

Reputation: 369

Showing an Alert Dialog in Java Swing

I want to giving an alert when there is an exception, like in code:

try
{
    //the code here
}
catch(Exception e)
{
    //show an alert dialog here
}

An example or a code snippet is what I need.

Upvotes: 7

Views: 39869

Answers (2)

KethanKumar
KethanKumar

Reputation: 726

try this:

JOptionPane.showMessageDialog(null, "My Goodness, this is so concise");

If you statically import JOptionPane.showMessageDialog this further reduces to

showMessageDialog(null, "This language just gets better and better!");

Upvotes: 12

user2336315
user2336315

Reputation: 16067

You can use JOptionPane.showMessageDialog with WARNING_MESSAGE :

JOptionPane.showMessageDialog(yourFrame,
    "WARNING.",
    "Warning",
    JOptionPane.WARNING_MESSAGE);

More infos about how to make dialogs here.

Upvotes: 31

Related Questions