title: Event on disposing a window
body: <p>i have this program in java when you click on View tables and view all
  a windows appears, i need to hide the first one and on closing the second on ,</p>
  
  <p>the first one to become visible again</p>
  
  <p>i have no idea how to refer to an object from these classes since i have created them like 
  new Main(); and new View(); :)</p>
  
  <p>this is one class:</p>
  
  <pre class="lang-java prettyprint-override"><code>package CarManager;
  
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  import javax.swing.ImageIcon;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  
  public class Main extends JFrame {
  
      private static final long serialVersionUID = 1L;
      static int width = 400;
      static int height = width / 16 * 9;
      static String title = "Car Manager";
      JButton viewTables = new JButton("View tables");
      JButton clients = new JButton("Clients");
      JButton search = new JButton("Search");
      JButton viewCars = new JButton("View all");
      JButton viewRent = new JButton("Rent a car");
      JButton viewBuy = new JButton("Buy a car");
      JButton viewAccessory = new JButton("Accessory");
  
      public Main() {
  
          setLayout(null);
          setLocationRelativeTo(null);
          setTitle(title);
          setSize(width, height);
          setResizable(false);
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          setVisible(true);
  
          JLabel background = new JLabel(new ImageIcon("res\\background2.jpg"));
          add(background);
          background.setSize(width, height);
          add(viewTables);
          add(clients);
          add(search);
          viewTables.setBounds(20, 20, 110, 30);
          clients.setBounds(20, 70, 110, 30);
          search.setBounds(20, 120, 110, 30);
  
          viewTables.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                  add(viewCars);
                  viewCars.setBounds(260, 20, 110, 20);
  
                  add(viewRent);
                  viewRent.setBounds(260, 50, 110, 20);
  
                  add(viewBuy);
                  viewBuy.setBounds(260, 80, 110, 20);
  
                  add(viewAccessory);
                  viewAccessory.setBounds(260, 110, 110, 20);
              }
          });
  
          viewCars.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                  new View();
                  setVisible(false);
              }
          });
  
      }
  
      public static void main(String args[]) {
          new Main();
      }
  }
  </code></pre>
  
  <p>and this is the second window that appears :</p>
  
  <pre class="lang-java prettyprint-override"><code>package CarManager;
  
  import javax.swing.ImageIcon;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  
  public class View extends JFrame {
  
      private static final long serialVersionUID = 1L;
      int width = 400;
      int height = width / 16 * 9;
      String title = "View all Cars";
  
      public View() {
          setLayout(null);
          setLocationRelativeTo(null);
          setTitle(title);
          setSize(width, height);
          setResizable(false);
          setDefaultCloseOperation(DISPOSE_ON_CLOSE);
          setVisible(true);
          JLabel background = new JLabel(new ImageIcon("res\\background2.jpg"));
          add(background);
          background.setSize(width, height);
      }
  }
  </code></pre>
  
  <p>all i need is when i close the second window the first one to become visible again</p>