title: GUI multiple frames switch
body: <p>I am writing a program for a black jack game. It is an assignment we are not to use gui's but I am doing it for extra credit I have created two frames ant they are working. On the second frame I want to be able to switch back to the first when a button is pressed. How do I do this?</p>
  
  <p><strong>first window.............</strong></p>
  
  <pre><code>import javax.swing.* ;
  import java.awt.event.* ;
  import java.awt.* ;
  import java.util.* ;
  
  
  public class BlackJackWindow1 extends JFrame implements ActionListener
  {
    private JButton play = new JButton("Play");
    private JButton exit = new JButton("Exit");
    private JPanel pane=new JPanel();
    private JLabel lbl ;
  
    public BlackJackWindow1()
    {
      super();
      JPanel pane=new JPanel();
      setTitle ("Black Jack!!!!!") ;
      JFrame frame = new JFrame("");
  
      setVisible(true);
      setSize (380, 260) ;
      setLocation (450, 200) ;
      frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE) ;
  
      setLayout(new FlowLayout());
      play = new JButton("Start");
      exit = new JButton("exit");
      lbl = new JLabel ("Welcome to Theodores Black Jack!!!!!");
  
      add (lbl) ;
      add(play, BorderLayout.CENTER);
      play.addActionListener (this);
      add(exit,BorderLayout.CENTER);
      exit.addActionListener (this);
    }
    @Override
    public void actionPerformed(ActionEvent event)
    {
      // TODO Auto-generated method stub
      BlackJackWindow2 bl = new BlackJackWindow2();
      if (event.getSource() == play)
      {
        bl.BlackJackWindow2();
      }
      else if(event.getSource() == exit){
        System.exit(0);
      }
    }
  </code></pre>
  
  <p><strong>second window....</strong></p>
  
  <pre><code>import javax.swing.* ;
  
  import java.awt.event.* ;
  import java.awt.* ;
  import java.util.* ;
  
  public class BlackJackWindow2 extends JFrame implements ActionListener
  {
    private JButton hit ;
    private JButton stay ;
    private JButton back;
    //private JLabel lbl;
  
    public void BlackJackWindow2() 
    {
      // TODO Auto-generated method stub
      JPanel pane=new JPanel();
      setTitle ("Black Jack!!!!!") ;
      JFrame frame = new JFrame("");
  
      setVisible(true);
      setSize (380, 260) ;
      setLocation (450, 200) ;
      frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE) ;
  
      setLayout(new FlowLayout());
      hit = new JButton("Hit");  
      stay = new JButton("stay");
      back = new JButton("return to main menu");
  
      // add (lbl) ;
      add(hit, BorderLayout.CENTER);  
      hit.addActionListener (this) ;
      add(stay,BorderLayout.CENTER);
      stay.addActionListener (this) ;
      add(back,BorderLayout.CENTER);
      back.addActionListener (this) ;
    }
  
    @Override
    public void actionPerformed(ActionEvent event) 
    {
      // TODO Auto-generated method stub
      BlackJackWindow1 bl = new BlackJackWindow1();
      if (event.getSource() == hit)
      {
        //code for the game goes here i will complete later
      }
      else if(event.getSource() == stay){
        //code for game goes here i will comeplete later.
      }
      else 
      {
        //this is where i want the frame to close and go back to the original.
      }
    }
  }
  </code></pre>