• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error dialog boxes?  RSS feed

 
David Mathie
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am creating a hotel booking system just to prove that I can after learning Java. However the current problem I am having is say a user has left a field empty usch as name, or email address etc. An error message dialog box shows up to tell the user that that field must have input in. However when running the program the error message is behind the actual program. E.g. I have to do the alt tab to get it to focus but it still doesn't show up on the screen? I have set the window to be on top of all others. Does that make a difference? Thanks
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Mathie wrote:I have set the window to be on top of all others. Does that make a difference?


You should be able to answer that quite easily by not setting the window to be on top of all others and seeing what happens.
 
David Mathie
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
David Mathie wrote:I have set the window to be on top of all others. Does that make a difference?


You should be able to answer that quite easily by not setting the window to be on top of all others and seeing what happens.


yer I've just tried that and still the same effect. Don't really know how to resolve this!
 
Rob Camick
Ranch Hand
Posts: 2756
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure you specify the frame as the parent of the optiong pane. Read the JOptionPane API and follow the link to the Swing tutorial on How to Make Dialogs for more information.
 
David Mathie
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my code for the next button.
commented out the new page atm because it keeps popping up and me having to do the alt tab. Thanks

Hotel hotel = new Hotel();
hotel.setVisible(true);


if (TxtName.getText().equals("")){
JOptionPane.showMessageDialog(this, "Name is required", "Input Error!", JOptionPane.ERROR_MESSAGE);
TxtName.requestFocus();
}
else
//hotel.setVisible(true);

if (TxtSurname.getText().equals("")){
JOptionPane.showMessageDialog(rootPane, "Surname is required", "Input Error!", JOptionPane.ERROR_MESSAGE);
}
else
//hotel.setVisible(true);

if (TxtAddress.getText().equals("")){
JOptionPane.showMessageDialog(rootPane, "Address is required", "Input Error!", JOptionPane.ERROR_MESSAGE);
TxtAddress.requestFocus();
}
else
//hotel.setVisible(true);

if (TxtCity.getText().equals("")){
JOptionPane.showMessageDialog(null, "City is required", "Input Error!", JOptionPane.ERROR_MESSAGE);
}
else
//hotel.setVisible(true);

if (ComboCounty.equals("")){
JOptionPane.showMessageDialog(null, "County is required", "Input Error!", JOptionPane.ERROR_MESSAGE);
}
else
//hotel.setVisible(true);

if (TxtPostCode.getText().equals("")){
JOptionPane.showMessageDialog(null, "Postcode is required", "Input Error!", JOptionPane.ERROR_MESSAGE);
}
else
//hotel.setVisible(true);

if (TxtPhoneNumber.getText().equals("")){
JOptionPane.showMessageDialog(null, "Phone Number is required", "Input Error!", JOptionPane.ERROR_MESSAGE);
}
else
//hotel.setVisible(true);

if (TxtMobile.getText().equals("")){
JOptionPane.showMessageDialog(null, "Mobile is required", "Input Error!", JOptionPane.ERROR_MESSAGE);
}
else
//hotel.setVisible(true);

if (TxtEmailAddress.getText().equals("")){
JOptionPane.showMessageDialog(null, "Email Address is required", "Input Error!", JOptionPane.ERROR_MESSAGE);
}
else
hotel.setVisible(true);
}
 
Rob Camick
Ranch Hand
Posts: 2756
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you download the code from the tutorial and try it?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!