We help IT Professionals succeed at work.

Swing Dialog Error

sabi97
sabi97 asked
on
I'm adding the below event to a menu item, to trigger a dialog box.

------------
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
   JOptionPane.showMessageDialog(null, "test dialog");

}
-------------

However, I'm getting the below errors!
------------------
forte4j/Development/db2.java [244:1] Undefined variable, class, or package name: JOptionPane
   JOptionPane.showMessageDialog(null, "test dialog");
   ^
forte4j/Development/db2.java [244:1] Invalid expression statement.
   JOptionPane.showMessageDialog(null, "test dialog");
   ^

---------------------

I'm adding other components to the JFrame like so :
getContentPane().add(searchHeader);


How do I get the dialog to work?


Comment
Watch Question

Commented:
Did you import javax.swing.* ?
Commented:
<@ import javax.swing.*>
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
Who said anything about jsp??
This question is LOCKED with a Proposed Answer.  If it helps you, great, accept it and grade it to close.  If not, reject it and comment as to why or what else is needed.

Few additional experts will join this collaboration effort, once a question has been locked.  Just want to confirm this to you.  If more than one expert helps you, you can always split points or award additional help in a new question, within the same topic area.  If you need help from us, post a zero point question here, and include the link:

EXPERT INPUT ON OUTCOME ALWAYS WELCOME.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

Moondancer
Community Support Moderator @ Experts Exchange

Commented:
hi...
i have encountered the same problem too...
u need to add
import javax.swing.JOptionPane;
on the beginning of the file

hopes this solve the problem

jen

Commented:
Please reject the proposed answer since it is a duplicate.
Thank you, yongsing:  Please claim your points here, this topic area:
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20265815

Moondancer
Community Support Moderator @ Experts Exchange

Explore More ContentExplore courses, solutions, and other research materials related to this topic.