title: Opening a new window on a button click in java
body: <p>I'm just starting with using interfaces in java, I'm okay with having just one window and that doing what i need. But i now want to link two windows together e.g.</p>
  
  <p>Frame 1 opens.
  user chooses button1 (enter data).
  Frame 2 opens so user can enter the data.</p>
  
  <p>Code for Frame 1:</p>
  
  <pre><code>import javax.swing.*;
  
  public class Task_3 extends JFrame {
      private Button btn1, btn2, btn3;
      public Task_3(){
  
        setLayout(new FlowLayout());
  
        btn1 = new Button("Enter data");
        add(btn1);
        btn2 = new Button("Check who is going");
        add(btn2);
        btn3 = new Button("View costs");
        add(btn3);
  
        setTitle("Event Costs");
        setSize(280, 150);
        setVisible(true);
  
        // close the window
        addWindowListener(new WindowAdapter()
        {
        public void windowClosing(WindowEvent e)
        {
           dispose();
           System.exit(0); //calling the method is a must
        }
        });
  
      }
      public static void main(String[] args){
          new Task_3();
      }
  }    
  </code></pre>
  
  <p>Code for Frame 2:</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  
  public class Task1GUI extends Frame implements ActionListener {
      private Label lblInput;
      private Label lblOutput;
      private TextField tfInput;
      private TextField tfOutput;
      private int sum = 0;
  
      public Task1GUI(){
          setLayout( new FlowLayout());
  
          lblInput = new Label("Enter number of students: ");
          add(lblInput);
  
          tfInput = new TextField(5);
          add(tfInput);
  
          tfInput.addActionListener(this);
  
          lblOutput = new Label("The cost per student is: ");
          add(lblOutput);
  
          tfOutput = new TextField(20);
          tfOutput.setEditable(false);
          add(tfOutput);
  
          setTitle("Task1GUI");
          setSize(350, 120);
          setVisible(true);
  
          addWindowListener(new WindowAdapter()
        {
        public void windowClosing(WindowEvent e)
        {
           dispose();
           System.exit(0); //calling the method is a must
        }
        });
      }
      public static void main(String[] args){
  
          new Task1GUI();
      }
  
      @Override
      public void actionPerformed(ActionEvent evt){
          int numOfStudents = Integer.parseInt(tfInput.getText());
          int coachCost = 550;
          int entrycost = 30;
          int totalcost;
          int numFree;
          int Discount;
          int costPerPerson;
          if(numOfStudents&lt;45){
          totalcost = coachCost+(numOfStudents*30);
          numFree = numOfStudents/10;
          Discount = numFree*30;
          costPerPerson = (totalcost-Discount)/numOfStudents;
          tfInput.setText("");
          tfOutput.setText(costPerPerson+"");
      }
      else{
          tfOutput.setText("Too mant students entered");
      }
      }
  }
  </code></pre>
  
  <p>Basically I would like some help with linking these two programs together so that the user can open the first frame choose which action they would like to do.</p>
  
  <p>I have only been working with the console up until very recently so if my code is not perfect I apologise but I would really appreciate any help with this.</p>
  
  <p>I would eventually like to get this program <a href="https://repl.it/repls/FondAptXeme" rel="nofollow noreferrer">https://repl.it/repls/FondAptXeme</a> to have a GUI if this helps at all.</p>
  
  <p>Thanks </p>