Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7812937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:40:52+00:00 2026-06-02T04:40:52+00:00

I am doing some practice work by expanding on a homework project I recently

  • 0

I am doing some practice work by expanding on a homework project I recently wrote. This is not for a grade, but I want to add some error checking to my code.

The program requires you to enter a name, select from a dropdown, select from a listbox and to select a radio button. My goal is to populate an error messagebox if any of the required items is blank.

The code I have so far for the error checking is below, but Im not sure how to take the individual lacking item and populate that to the message box since all of the error checking is in a single “if” statement.

Error checking code:

// Listener to handle the print button.
class ButtonListener implements ActionListener
{
    ButtonListener() {}

    public void actionPerformed(ActionEvent e)
    {
        JFrame frame1 = new JFrame("Show Message Dialog");

        // Checks for required entries
        if (error == 0 || name == "" || flag == 0)
        {
            JOptionPane.showMessageDialog(frame1,
                    "You must complete the form: " +     missing, "ERROR",
                JOptionPane.ERROR_MESSAGE);
        }
        else
        {
            // Get values from fields
            setText();
            System.out.println("Passenger's 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");
        }
    }
}

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:40:54+00:00Added an answer on June 2, 2026 at 4:40 am

    It looks like they can actually have multiple things wrong, so why only show one? I’m normally a C# dev so I’m not going to try to get the syntax right on typing this myself, but here’s the concept:

    • Create a collection of some sort, like a list of strings.
    • Make 3 if statements, one for each of those errors, and put the field
      names in for each one that fails. if (name.isEmpty()) {
      errorList.Add("name"); }
    • Check to see if the count of items in the list is greater than 0. If
      it is throw your error and put the name of the bad fields from the
      collection into the string that you generate.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been doing some web development work in PHP recently which has led me
I'm currently doing some optimization work on a large web project. I'm already doing
im doing some practice sql problems one of the questions is: Prepare a shipping
Doing some homework here (second assignment, still extremely green...). The object is to read
While doing some small regex task I came upon this problem. I have a
I've been doing some research on whether what best practice is regarding the use
I am trying to prevent text highlighting in Firefox for some, but not all
I'm not sure if this is an odd setup to begin with, but here's
I'm working currently on a test project in order to practice some of the
So I'm doing Project Euler because dear gods do I need to practice writing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.