I do some practice expanding the homework project that I recently wrote. This is not for evaluation, but I want to add some errors to my code.
The program requires you to enter a name, select from the drop-down list, select from the list and select the switch. My goal is to fill out an error message if any of the required elements is empty.
The code that I have so far checked for an error is given below, but I'm not sure how to take a separate element without it and fill it in the message field, since the entire error check is in the same "if" expression.
Error checking code:
class ButtonListener implements ActionListener
{
ButtonListener() {}
public void actionPerformed(ActionEvent e)
{
JFrame frame1 = new JFrame("Show Message Dialog");
if (error == 0 || name == "" || flag == 0)
{
JOptionPane.showMessageDialog(frame1,
"You must complete the form: " + missing, "ERROR",
JOptionPane.ERROR_MESSAGE);
}
else
{
setText();
System.out.println("Passenger Name: " + name + "\n");
System.out.println("Age Group: " + ageValue + "\n");
for (int i = 0; i < value.length; i++)
{
System.out.println("Destination: " + value[i] + "\n");
}
System.out.println("Departure Day: " + day + "\n");
}
}
}
Thank!
source
share