title: How do you print multiple text areas in an orderly manner in Java?
body: <p>Alright, so I have a dilemma. I was wondering if there is a way for me to do the following with two text areas:</p>
  
  <p>I. Print the first text area, and only the first text area.
  II. Upon closing the first text area, have it so the second text area appears. 
  III. Do this so that both text areas do not appear at the same time.</p>
  
  <p>Here is my code, sorry for all the comments, I have to teach this to fellow classmates for a project:</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*; //Used for events and the Action Listener
  
  public class ActionProgram extends JFrame /*"extends JFrame" will extend the frame into the variable used to call the class*/
  {
  //Declare fields (Do not require public/private identification)
  JTextArea area;
  JLabel instructions;
  JLabel question;
  JLabel ask;
  JButton submitt;
  JScrollPane sp;
  
  //Create a constructor to start applying these variables in the creation of the Text Area
  public ActionProgram()
  {
      //Create the flow layout
          setLayout(new FlowLayout());
  
      //Create the text area and set how long and wide it should be. Add it to the frame
      area = new JTextArea(10,30);
      add(area);
  
      //Create scroll pane and add it to the frame
      sp = new JScrollPane(area);
      add(sp);
  
      //Set the line wrap and word wrap to true for the frame
      area.setLineWrap(true);
      area.setWrapStyleWord(true);
  
      //Create submitt button, and add it to the frame
      submitt = new JButton ("Submitt");
      add(submitt);
  
      //Create label asking user to answer the question and add it to the frame
      instructions = new JLabel("Please Answer the Following Question:");
      add(instructions);
  
      //Create label for the question and add it to the frame
      question = new JLabel("-----Briefly Describe how to print something in java-----");
      add(question);
  
      //Create label telling user what to do when finished, and add it to the frame
      ask = new JLabel("Please enter Submitt when you have finished");
      add(ask);
  
  
      //As you can tell, we do not need to put all these parts into the frame, for the class puts it all into the variable calling it
  
      /*In order for the program to take what the user has writen into text area and make it an input, we have to create an
      Action Listener. An Action Listener is a piece of code that will do a specific event when an action is done. In this case
      we need the action listener to respond when the user presses "Submitt". To do this, we need to create an event class*/
  
      //This will call the action listener class
      event action = new event();
  
      //This will add the action listener to the submitt button
      submitt.addActionListener(action);
  
  }
  /*The class called event will create the aciton listener. There are two different methods for the action event, the action listener
  and the action performer. The action performer is the method used to create code when the action listener is activated. The listener
  waits for the submitt button to be pressed, and the performer does user-inputed code when the button is pressed*/
  public class event implements ActionListener
  {
      public void actionPerformed(ActionEvent e) //We use a nested method to create the action performer
      {
          /*The following code is what the performer will do when the listner is activated. It will get the text typed in the
          text area when the user hits the submitt button. The performer will then print the text obtained and close the text area*/
          String text = area.getText();
          System.out.println(text);
  
          //Use System.exit(0) to close the text area
          System.exit(0);
      }
  }
  public static void main(String[] args)
  {
              //Call the class like you usually do, and set a variable to it
              ActionProgram display = new ActionProgram();
  
              //display also acts as the frame of the text area since the class set it equal to the JFrame
              display.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
              //Set the length and width of the text area in pixels
              display.setSize(500,300);
  
              //Set it so the text area can be seen
              display.setVisible(true);
  
  }
  
  }
  </code></pre>