title: Java Arrays being overwritten
body: <p>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 <em>String[]</em> arrays to populate my form and display it on screen and then have the <strong>getForm()</strong> function return a <strong>String[]</strong> with the title of the form and the info in <strong>text[i]</strong>. This all works fine until I use use the button I added to call the <strong>getForm()</strong> function and I change to a different form (<strong>createForm()</strong> attached to ListListener) and all the labels appear as whatever was returned in the <strong>getForm()</strong> 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 <strong>createForm()</strong> function again resetting the arrays, so I'm not sure whats going on. </p>
  
  <p>Thanks</p>
  
  <p>I've included a screenshot of what I'm referring too bellow as well.</p>
  
  <p><a href="http://www.majhost.com/gallery/adc90/afsd/error.png" rel="nofollow">http://www.majhost.com/gallery/adc90/afsd/error.png</a></p>
  
  <pre><code>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 &lt; 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 &lt; formReturn.length; i++)
              formReturn[i] = text[i].getText();
          return formReturn;
      }
      //Clear form
      public void clearForm()
      {
          for(int i = 1; i &lt; formArray.length; i++)
              text[i].setText("");
      }
  }
  </code></pre>
  
  <p></p>