overriding an error messaage
hi.
im building a airplane ticket machine.
basically when i test the GUI the error messages are wrong! EG: i open the GUI and dont enter any values, and then press issue single ticket, the "Number of Passengers must be greater than zero" error message comes up which is correct (at which time i want the cursor to focus on the passenger text box), the departure date error message follows it and when i click OK the focus is on the departure text box and not the passenger textbox.
basically i dont want the 2nd error message to appear if no values are entered, i just want the first error message to appear!....code is below....any help or links to some tutorials will be great!!....thanks guys
//create an exception handler for the passengers textBox
publicvoid numberMessage()
{
try
{
numberOfPassengers = Integer.parseInt(passengerText.getText());
if(numberOfPassengers <= 0)
{
JOptionPane.showMessageDialog(null,"Number of Passengers must be greater than zero","Error Message",JOptionPane.ERROR_MESSAGE);
this.passengerText.setText("");
this.passengerText.requestFocus();
}
}
catch (NumberFormatException ex)
{
JOptionPane.showMessageDialog(null,"Enter the number of Passengers required","Error Message",JOptionPane.ERROR_MESSAGE);
this.passengerText.setText("");
this.passengerText.requestFocus();
}
}
//set the method to create a single ticket
//create an instance of object ticket and call the methods from the class
publicvoid singleTicket()
{
String departure = departureText.getText();
String returns = returnText.getText();
if(departure.length() == 0 || returns.length() != 0)
{
JOptionPane.showMessageDialog(null,"Only Enter the departure date","Error Message", JOptionPane.ERROR_MESSAGE);
departureText.setText("");
returnText.setText("");
departureText.requestFocus();
}
elseif(numberOfPassengers > 0)
{
ticket =new Ticket();
ticket.setFrom((String)from.getSelectedItem());
ticket.setDestination((String)destination.getSelectedItem());
ticket.setClass((String)classes.getSelectedItem());
ticket.setPassengers(numberOfPassengers = Integer.parseInt(passengerText.getText()));
ticket.setDeparture(departureText.getText());
//ticket.setReturn(returnText.getText());
ticket.setTicketPrice();
ticket.printDetails();
//tickets.add(ticket); //add at later date, must add to tickets -- iterate through!!
}
}

