This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Message box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Message box" Watch "Message box" New topic

Message box

Jeff Dube
Ranch Hand

Joined: Jun 14, 2001
Posts: 44
I made a form and i need to have a message box that inform the user if one or more field are empty.
I tried with the following:
<%<br /> if (" field is null.....")<br /> {<br /> this.showMessageDialog(null,"You need to enter a value...");<br /> }<br /> else<br /> { <br /> %>
<%@ include file="Response.jsp" %>
<%<br /> }<br /> %>
But it does'nt work. Do i have to insert the showMessageDialog inside my bean with the parent.showMesageDialog()?
I know that i can do it with javascript but i prefer java.
Is it possible??
Thank you very much

manjerekar annajirao

Joined: Jun 12, 2001
Posts: 4
hi jeff
this is manjerekar.
u haven't specified anything clear. but still i consider ur class extends JFrame. to display a message box , u can go for a JOptionPane class where we have methods to display different dialog boxes.
here's the code for opening a file
when there is a file opening error this dialog box is displayed.
catch(Exception e)
JOptionPane.showMessageDialog(frame,new String[]
"Unable to open file",fileName.toString()
},"File Open Error",JOptionPane.INFORMATION_MESSAGE);
frame------object of JFrame.
fileName-----selected file.
u can manipulate the same for a displaying a dialog box , when the user as not filled in the boxes.
hope this will help u out.
Amit Agarwal
Ranch Hand

Joined: May 09, 2001
Posts: 92
Hi Jeff,
Your code is not visible, but generally you do not have to insert anything.
The showMessageDialog is a statc method of the JOptionPane class, and can be directly called by using the class name or an instance of the JOptionPane class.
JOptionPane.showMessageDialof, parent, "Message", "Title", JOptionPane.ERROR_MESSAGE);
subject: Message box
It's not a secret anymore!