title: Java jGRASP creating more lines of code in a text file every time you submit
body: <p>Beginner to coding here. With the GUI in java jgrasp, how can you submit one line of code per submission and keep adding to the text file. For example, in the GUI, you can add some random answers. This can include dates, food, or sauce. This is what it will print out when submitted.</p>
  
  <pre><code>2/2/2017 hamburger ketchup
  </code></pre>
  
  <p>Currently, I can only submit one line of code. After another submission, the file rewrites another answer on the code. However, I need for the java jgrasp program to save and allow for more answers. It needs to look like the code shown below, each number represents one time the user pressed submit in the GUI.</p>
  
  <pre><code>1. 2/2/2017 hamburger ketchup
  2. 2/3/2017 fish tartar sauce
  3. 6/3/2018 steak A1
  </code></pre>
  
  <p>These codes will create a GUI in java jgrasp. Then you can input a code, however, you can only write one code. Every other inputted submission will rewrite the original one. How can I fix the problem and make the code add inputs beyond 1 line of submissions?</p>
  
  <p>This is the code in question:</p>
  
  <h1>1:</h1>
  
  <pre><code>&lt;pre&gt;&lt;code&gt;
      // Creates form for gathering data and loads it into a file
      // This list shows the functions used in this program
      //there are many Class files used. I have listed them all FYI
  
      import java.io.PrintWriter;
      import java.io.FileNotFoundException;
      import java.io.FileOutputStream;
      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.JPanel;
      import javax.swing.JButton;
      import javax.swing.JMenuBar;
      import javax.swing.JMenu;
      import javax.swing.JMenuItem;
      import javax.swing.JTextField;
      import java.awt.Color;
      import java.awt.GridLayout;
      import java.awt.event.ActionListener;
      import java.awt.event.ActionEvent;
      import java.awt.Graphics;
  
      //this makes this class file is made a subclass of JFrame and uses the             ActionListener Interface
  
      public class QuestionForm extends JFrame implements ActionListener   
      {
          // these are class level variables for use by the entire class file
  
          public static final int WIDTH = 700;
          public static final int HEIGHT = 500;
  
          //this sets up a constant char field size the text fields
          public static final int FIELDWIDTH = 10;  
  
      // these private instance variables are defined here to be used by the GUI object form
      private JTextField firstNameField;
      private JTextField lastNameField;
      private JTextField phoneNumField;
      private JTextField dressNumField;
      private JTextField dressStreetField;
      private JLabel label6; // used for status messages on panel 6
      private JLabel label5; // used for directions on panel 5
  
      // menu action listener inner classes to establish each menu selection response
  
      private class humanListener implements ActionListener
      {
          public void actionPerformed(ActionEvent e)
          {
              dressStreetField.setText("humanoid");
          }
      } // end human listerner inner class
  
      private class alienListener implements ActionListener
      {
          public void actionPerformed(ActionEvent e)
          {
              dressStreetField.setText("Klingon");
          }
      } // end alien listerner inner class
  
  
      // class constructor
      public QuestionForm()
      {
          super();        // default constructor calls to the super JFrame class intially
          setSize(WIDTH, HEIGHT);  // these can also be sent from main as an option
          setTitle("Questionaire Form");
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
          // sets form grid to divide frame into multiple parts for panels to snap to
          setLayout(new GridLayout(6, 1)); //fixed size for this form object class
  
  
          // create first panel of text fields and labels
          JPanel panel1 = new JPanel();  // panel object
          panel1.setBackground(Color.PINK);  //panel color
          JLabel label1 = new JLabel("First Name");  // panel label
          panel1.add(label1);
          firstNameField = new JTextField(FIELDWIDTH);  // panel text field
          panel1.add(firstNameField);
          add(panel1);
  
          // create second panel of text fields and labels
          JPanel panel2 = new JPanel();
          panel2.setBackground(Color.YELLOW);
          JLabel label2 = new JLabel("Last Name");
          panel2.add(label2);
          lastNameField = new JTextField(FIELDWIDTH);
          panel2.add(lastNameField);
          add(panel2);
  
          // create third panel of text fields and labels
          JPanel panel3 = new JPanel();
          JLabel label3 = new JLabel("phone number (no dashes please)");
          panel3.add(label3);
          phoneNumField = new JTextField(FIELDWIDTH);
          panel3.add(phoneNumField);
          add(panel3);
  
          // create fourth panel of text fields and labels
          JPanel panel4 = new JPanel();
        panel4.setBackground(Color.WHITE);
  
          JLabel label4 = new JLabel("address house number");
          panel4.add(label4);
          dressNumField = new JTextField(FIELDWIDTH);
          panel4.add(dressNumField);
          add(panel4);
  
          // create loaded fifth panel with text field label and drop down menu
          JPanel panel5 = new JPanel();
          JLabel label5 = new JLabel("select from menu");
          panel5.add(label5);
          dressStreetField = new JTextField(FIELDWIDTH);
          panel5.add(dressStreetField);
  
          // create and populate menu for panel 5
          JMenuBar bar = new JMenuBar();
        bar.setBackground(Color.CYAN);
          JMenu select = new JMenu("species");
          JMenuItem humanchoice = new JMenuItem("humanoid");
          humanchoice.addActionListener(new humanListener());  // defines what happens when menu choice selected...see private inner class above
          select.add(humanchoice);
  
          JMenuItem alienchoice = new JMenuItem("Klingon");
          alienchoice.addActionListener(new alienListener());
          //alienchoice.setActionCommand(label5.setText("Klingon"));
          select.add(alienchoice);
  
          bar.add(select);
          panel5.add(bar);
          add(panel5);  //fully loaded panel now snapped to frame
  
          // create submit button panel6 with status indicator label
          JPanel subpanel = new JPanel();
        subpanel.setBackground(Color.CYAN);
  
          JButton submit = new JButton("Submit");
          submit.addActionListener(this);   //programs the button action in method call below
          label6 = new JLabel("Please fill in form, then press Submit");
          subpanel.add(submit);
          subpanel.add(label6);
          add(subpanel);
  
  
      }  // end Frame building method
  
  
      // submit button action defined in this public method
      public void actionPerformed(ActionEvent e) 
      {
          PrintWriter outputStream = null;    // defines Writer object for file loading
          String fileName = lastNameField.getText();  //creates file name from lastName on form
  
          // This is an exception catching method for handling potential file opening errors
          try
          {
              outputStream = new PrintWriter(new FileOutputStream(fileName)); // opens file on drive, waits for data
          }
          catch(FileNotFoundException f)  // terminates program is file fails to open--all data lost
          {
              System.out.println("error opening the data store file");
              System.exit(0);
          }
  
  
          outputStream.println(firstNameField.getText() + " " + lastNameField.getText() + " " + phoneNumField.getText() + " " + dressNumField.getText() + " " + dressStreetField.getText());  //defines text file format -- please note: all inputted data are Strings
  
          outputStream.close();       //data store file written and closed 
  
          label6.setText("file saved...End of program");  //updates status on panel 6
  
  
      } // end action method
  
  
  
  
  
  
      } // end class
  &lt;/code&gt;&lt;/pre&gt;
  </code></pre>
  
  <h1>2:</h1>
  
  <pre><code>&lt;pre&gt;&lt;code&gt;
  
      import java.awt.GridLayout;
      import javax.swing.JFrame;
  
  
      public class QuestionFormTester
      {
      public static void main(String[] args)
      {
  
          QuestionForm form = new QuestionForm();
          form.setVisible(true);
  
      } //endmain
      } // end class
  &lt;/code&gt;&lt;/pre&gt;
  </code></pre>