How to present a simple alert message in java?

Haoest picture Haoest · Feb 2, 2012 · Viewed 472.3k times · Source

Coming from .NET i am so used calling Alert() in desktop apps. However in this java desktop app, I just want to alert a message saying "thank you for using java" I have to go through this much suffering:

(using a JOptionPane)

Is there an easier way?

Answer

Dónal picture Dónal · Feb 2, 2012

I'll be the first to admit Java can be very verbose, but I don't think this is unreasonable:

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

If you statically import javax.swing.JOptionPane.showMessageDialog using:

import static javax.swing.JOptionPane.showMessageDialog;

This further reduces to

showMessageDialog(null, "This is even shorter");