title: A Back/Home Button [Java]
body: <p>Ive attempted this before on my own and failed.
  How can I add a JButton to a JFrame that will bring it back to the previous opened JFrame or the "Home" Frame.</p>
  
  <p>In my application I have 4 JFrames, The Main One and 3 Accessible by Buttons.</p>
  
  <p>My Full Code(Quiet Long, sorry)</p>
  
  <pre><code>package me.jamplifier;
  
  import java.awt.BorderLayout;
  import java.awt.Color;
  import java.awt.EventQueue;
  import java.awt.FlowLayout;
  import java.awt.Font;
  import java.awt.Image;
  import java.awt.Toolkit;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.awt.image.BufferedImage;
  import java.io.IOException;
  import java.io.InputStream;
  import java.util.ArrayList;
  import java.util.List;
  
  import javax.imageio.ImageIO;
  import javax.swing.BoxLayout;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;
  import javax.swing.JTextArea;
  import javax.swing.JTextField;
  import javax.swing.ScrollPaneConstants;
  import javax.swing.UIManager;
  import javax.swing.UnsupportedLookAndFeelException;
  import javax.swing.text.DefaultCaret;
  
  public class Launcher extends JFrame {
  
  
  
  // Main Class Area (Default/Main Windows)
  public Launcher(){
  
      // Main Window
      JFrame frame = new JFrame("HC Navigator");
      frame.setSize(250, 200);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);
      // Text Labels
      JLabel label = new JLabel("Beta 1.5      ");
      JLabel label1 = new JLabel("Welcome to HurricaneCraft");
      JPanel panel = new JPanel();
      frame.add(panel);
      panel.add(label);
      panel.add(label1);
      panel.setBackground(Color.CYAN);
  
      Font font = new Font("Verdana", Font.BOLD, 12);
      label1.setFont(font);
      label1.setForeground(Color.RED);
      label.setFont(font);
      label.setForeground(Color.GRAY);
  
      // Buttons
      JButton site = new JButton("Site");
      site.addActionListener( new ActionListener()
      {
          public void actionPerformed(ActionEvent e)
          {
              openWebPage("http://www.hurricanecraft.com");
          }
      });
  
      JButton forums = new JButton("Forums");
      forums.addActionListener( new ActionListener()
      {
          public void actionPerformed(ActionEvent e)
          {
              openWebPage("http://www.hurricanecraft.com/forums/");
          }
      });
      JButton apps = new JButton("Member Apps");
      apps.addActionListener( new ActionListener()
      {
          public void actionPerformed(ActionEvent e)
          {
              openWebPage("http://hurricanecraft.freeforums.org/member-registration-f29.html");
          }
      });
      JButton community = new JButton("Community");
      community.addActionListener( new ActionListener()
      {
          public void actionPerformed(ActionEvent e)
          {
              createFrame2();
          }
      });
      JButton admin = new JButton("Admin Area");
      admin.addActionListener( new ActionListener()
      {
          public void actionPerformed(ActionEvent e)
          {
              createFrame();
          }
      });
      JButton update = new JButton("Update Log");
      update.addActionListener( new ActionListener()
      {
          public void actionPerformed(ActionEvent e)
          {
              createFrame1();
          }
      });
      panel.add(site);
      panel.add(forums);
      panel.add(community);
      panel.add(apps);
      panel.add(admin);
      panel.add(update);
  
  
  
  
  }
  
  // Web Browser/Link Opening Code
  public static void openWebPage(String url){
         try {         
           java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
         }
         catch (java.io.IOException e) {
             System.out.println(e.getMessage());
         }
      }
  // Admin Area Panel
  public static void createFrame()
  {
      JFrame frame = new JFrame("Admin Area");
      frame.setVisible(true);
      frame.setSize(250, 200);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
      JLabel label = new JLabel("Beta 1.5      ");
      JLabel label1 = new JLabel("Welcome to the Admin Panel");
      JPanel panel = new JPanel();
      frame.add(panel);
      panel.add(label);
      panel.add(label1);
  
      JButton host = new JButton("MCServer Host");
      host.addActionListener( new ActionListener()
      {
          public void actionPerformed(ActionEvent e)
          {
              openWebPage("http://panel.fadehost.com/index");
          }
      });
  
      JButton console = new JButton("MCServer Console");
      console.addActionListener( new ActionListener()
      {
          public void actionPerformed(ActionEvent e)
      {
          openWebPage("http://panel.fadehost.com/index.php?r=server/log&amp;id=1983");
      }
  });
      JButton tfhost = new JButton("TF2Server Host");
      host.addActionListener( new ActionListener()
      {
          public void actionPerformed(ActionEvent e)
          {
              openWebPage("http://tcadmin.darkstarllc.com");
          }
      });
  
      JButton staffforum = new JButton("Staff Forums");
      staffforum.addActionListener( new ActionListener()
      {
          public void actionPerformed(ActionEvent e)
      {
          openWebPage("http://hurricanecraft.freeforums.org/staff-area-f39.html");
      }
  });
  
      panel.add(host);
      panel.add(console);
      panel.add(tfhost);
      panel.add(staffforum);
  
  
  }
      // Update Logs Panel
      public static void createFrame1()
      {
          JFrame frame = new JFrame("Update Logs");
          frame.setVisible(true);
          frame.setSize(400, 400);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
      JLabel label = new JLabel("                         Change Log:                                      ");
      JLabel label1 = new JLabel("- Beta 1.1: First Release");
      JLabel label2 = new JLabel("- Beta 1.2: Added ADMIN Panel &amp; Change log ");
      JLabel label3 = new JLabel("- Beta 1.3: Added Staff Forum  &amp; Seperated Console/Host");
      JLabel label4 = new JLabel("- Beta 1.4: Added Colours &amp; Community Tab + Online Status's");
      JLabel label5 = new JLabel("- Beta 1.4: Added Colours &amp; Community Tab + Online Status's");
      JLabel label6 = new JLabel("- Beta 1.5: Added New Site Redirects &amp; TF2 Server IP/PANEL");
      JPanel panel = new JPanel();
      frame.add(panel);
      panel.add(label);
      panel.add(label1);
      panel.add(label2);
      panel.add(label3);
      panel.add(label4);
      panel.add(label5);
      panel.add(label6);
  }
  // Community Page
      public static void createFrame2()
      {
          JFrame frame = new JFrame("Community Area");
          frame.setVisible(true);
          frame.setSize(400, 300);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
          // Labels Frames Panels ECT
          JLabel label = new JLabel("Hurricane Craft Servers:            ");
          JLabel minecraft = new JLabel("- Minecraft: IP Mc.hurricanecraft.com");
          JLabel online = new JLabel("[ONLINE]");
          JLabel tf2 = new JLabel("- Teamspeak: IP tf.hurricanecraft.com:27015");
          JLabel online1 = new JLabel("[ONLINE]");
          JLabel teamspeak = new JLabel("- Teamfortress: IP ts.hurricanecraft.com:5326");
          JLabel online2 = new JLabel("[ONLINE]");
          JLabel site = new JLabel("- Site: http://www.hurricanegaming.webs.com");
          JLabel online3 = new JLabel("[ONLINE]");
          JPanel panel = new JPanel();
          // Buttons
          JButton votepmc = new JButton("Vote On PMC");
          votepmc.addActionListener( new ActionListener()
          {
              public void actionPerformed(ActionEvent e)
          {
              openWebPage("http://www.planetminecraft.com/server/hurricane-craft-247-survival-
                creative-pvp-games/vote/");
          }
      });
          JButton votemc = new JButton("Vote On MCServers");
          votemc.addActionListener( new ActionListener()
          {
              public void actionPerformed(ActionEvent e)
          {
              openWebPage("http://minecraftservers.org/vote/97507");
          }
      });
          JButton votetopg = new JButton("Vote On Topg");
          votetopg.addActionListener( new ActionListener()
          {
              public void actionPerformed(ActionEvent e)
          {
              openWebPage("http://topg.org/Minecraft/in-371684");
          }
      });
  
  
          // Adding buttons/labels
          frame.add(panel);
          panel.add(label);
          panel.add(minecraft);
          panel.add(online);
          panel.add(tf2);
          panel.add(online1);
          panel.add(teamspeak);
          panel.add(online2);
          panel.add(site);;
          panel.add(online3);
          panel.add(votepmc);
          panel.add(votemc);
          panel.add(votetopg);
          // Font &amp; Colours
          Font font = new Font("Verdana", Font.BOLD, 12);
          label.setFont(font);
          label.setForeground(Color.BLUE); 
          Font green = new Font("Verdana", Font.BOLD, 12);
          online.setFont(green);
          online.setForeground(Color.GREEN); 
          online1.setFont(green);
          online1.setForeground(Color.GREEN);
          online2.setFont(green);
          online2.setForeground(Color.GREEN);
          online3.setFont(green);
          online3.setForeground(Color.GREEN);
      }
  // Main String Args Declaration
  public static void main(String[] args){
       new Launcher();
      }
  
  
      }
  </code></pre>