title: how to create a window with two buttons that will open a new window
body: <p>I need program - main JFrame have 2 buttons</p>
  
  <ol>
  <li>button</li>
  <li>button2</li>
  </ol>
  
  <p>When I click <em>button</em> it has to open new JFrame window with new options, while if I click <em>button2</em> then open another window. </p>
  
  <p>In these 2 new windows I must add buttons like next and previous. </p>
  
  <p>I have a problem, when I open button 1 , then open 2 windows and main JFrame still be visible.</p>
  
  <p>My first program on swing:</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  
  public class example {
  
  public static void main (String[] args){    
    JFrame frame = new JFrame("Test");
    frame.setVisible(true);
    frame.setSize(500,200);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
    JPanel panel = new JPanel();
    frame.add(panel);
    JButton button = new JButton("hello agin1");
    panel.add(button);
    button.addActionListener (new Action1());
  
    JButton button2 = new JButton("hello agin2");
    panel.add(button2);
    button.addActionListener (new Action2()); 
  }
  static class Action1 implements ActionListener {        
    public void actionPerformed (ActionEvent e) {     
      JFrame frame2 = new JFrame("Clicked");
      frame2.setVisible(true);
      frame2.setSize(200,200);
      JLabel label = new JLabel("you clicked me");
      JPanel panel = new JPanel();
      frame2.add(panel);
      panel.add(label);       
    }
  }   
  static class Action2 implements ActionListener {        
    public void actionPerformed (ActionEvent e) {     
      JFrame frame3 = new JFrame("OKNO 3");
      frame3.setVisible(true);
      frame3.setSize(200,200);
  
      JLabel label = new JLabel("kliknales");
      JPanel panel = new JPanel();
      frame3.add(panel);
      panel.add(label);
    }
  }   
  }
  </code></pre>