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 7867677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:46:03+00:00 2026-06-03T00:46:03+00:00

Hey I’m a little new here so my apologies if I messed something up

  • 0

Hey I’m a little new here so my apologies if I messed something up in my post. Anyways the problem I’m having has to deal with arrays, what I’m trying to do basically is use the String[] arrays to populate my form and display it on screen and then have the getForm() function return a String[] with the title of the form and the info in text[i]. This all works fine until I use use the button I added to call the getForm() function and I change to a different form (createForm() attached to ListListener) and all the labels appear as whatever was returned in the getForm() function. I’m pretty sure it has something to do with the way I’m using my arrays but I thought they would be set back to normal after I chose another list item which goes through the createForm() function again resetting the arrays, so I’m not sure whats going on.

Thanks

I’ve included a screenshot of what I’m referring too bellow as well.

http://www.majhost.com/gallery/adc90/afsd/error.png

class Form extends JPanel
{
    //Arrays for the forms
    private String[] com = {"Communication","ICAO","Type","Frequency"};
    private String[] fuel = {"Fuel","ICAO","Type"};
    private String[] runway = {"Runway","ICAO","Number","Type","Length"};
    private String[] airplane = {"Airplane","Make","Model","Type","Fuel Capacity", "Fuel Burn Rate", "Air Speed"};
    private String[] airport = {"Airplane","ICAO","Name","Longitude","Latitude","crFreq","crType", "Fuel Type"};

    //Declare variables
    private JTextField[] text;
    private String[] formReturn;
    private String[] formArray;
    private JButton submit,clear;

    public Form()
    {
        createForm("Airplane");
    }

    public void createForm(String choice)
    {
        removeAll();
        if(choice.equals("Communication"))
        {
            formArray = com;
        }
        else if(choice.equals("Fuel"))
        {
            formArray = fuel;
        }
        else if(choice.equals("Airplane"))
        {
            formArray = airplane;
        }
        else if(choice.equals("Airport"))
        {
            formArray = airport;
        }
        else if(choice.equals("Runway"))
        {
            formArray = runway;
        }


        int l = formArray.length + 1;
        text = new JTextField[l];

        //Layout info
        GridLayout grid = new GridLayout(l,2);
        grid.setHgap(0);
        setLayout(grid);
        //Set label
        add(new JLabel(formArray[0]));
        add(new JLabel(""));
        for(int i = 1; i < formArray.length; ++i)
        {
            add(new JLabel(formArray[i]));
            add(text[i] = new JTextField(20));
        }

        //Add in the buttons and the actionlisteners
        submit = new JButton("Create");
        clear = new JButton("Delete");
        add(clear);
            clear.addActionListener(new Button());
        add(submit);
            submit.addActionListener(new Button());
        updateUI();
    }
    //Get form info
    //This works so far
    public String[] getForm()
    {
        formReturn = formArray;
        formReturn[0] = formArray[0];
        for(int i = 1; i < formReturn.length; i++)
            formReturn[i] = text[i].getText();
        return formReturn;
    }
    //Clear form
    public void clearForm()
    {
        for(int i = 1; i < formArray.length; i++)
            text[i].setText("");
    }
}

  • 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-03T00:46:05+00:00Added an answer on June 3, 2026 at 12:46 am
    public String[] getForm()
    {
        formReturn = formArray; /* (0) */
        formReturn[0] = formArray[0];
        for(int i = 1; i < formReturn.length; i++)
            formReturn[i] = text[i].getText(); /* (1) */
        return formReturn;
    }
    

    Look at line (1): you modify formReturn array which points to labels text. formReturn -> formArray -> com.

    To fix it just create new String array at (0):

    formReturn = new String[formArray.length];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey guys having this really simple problem but cant seem to figure out have
Hey I'm having a problem trying to figure this out: Lets start out with
Hey its really hard to define an exact title for my problem. I am
Hey all i am trying to figure out what i am doing incorrectly here.
Hey guys I'm following the rails tutorial found here http://net.tutsplus.com/tutorials/ruby/the-intro-to-rails-screencast-i-wish-i-had/ and I've gotten to
Hey I need a little help with unsigned char bit access. I need to
Hey everyone I have a basic search function here that allows me to search
Hey i am new to iOS development, in my app i want to fetch
Hey guys, sorry I'm kind of new to programming, but I had a small
Hey guys here is my php: $x = array(one, two, three); foreach ($x as

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.