title: JFrame and ActionListener
body: <p>I'm a bit of a newbie to java, and I'm having an issue with a game I'm making in Swing. I have a class, guiPulUp, which has buttons and a text field. One of the buttons is "Magic". I'm trying to make it so if you click  the Magic button then a JFrame, another one called guiPullUpMagic, appears with preset "Spell" buttons.
  Is that even possible? Or is there also a way to use .setVisible to make the spell GUI visible when clicked?
  Please help! I can't find any topic related to this on the internet. Thanks! (If there's any other errors, let me know)
  Also, I am getting VERY confused with how to get variables made in one class to work in another, such as getting my JButton "buttonMAGIC" to work in my guiPullUpMagic class.</p>
  
  <p>For reference here's my code (It's pretty big!):</p>
  
  <hr>
  
  <pre><code>import javax.swing.*;
  
  import java.lang.Math.*;
  
  import java.awt.event.*;
  
  /**
   * main GUI class
   */
  
  public class guiPullUp extends JFrame
  {
  
      public static void main(String[] args)
      {
          new guiPullUp();
      }
  
      //declaring buttons for main GUI
  
      private JButton buttonOK;
      private JButton buttonUP;
      private JButton buttonDOWN;
      private JButton buttonRIGHT;
      private JButton buttonLEFT;
      private JButton buttonMAGIC;
      private JButton buttonRUN;
      private JTextField userINPUT;
      private JLabel healthDisplay;
  
      public guiPullUp()
      {
          this.setSize(600,500);
          this.setTitle("Xenix V_1");
          this.setDefaultCloseOperation(
              JFrame.EXIT_ON_CLOSE);
  
           //button names to appear on panel1*
           //*button coordinates needed
  
           JButton buttonOK = new JButton ("OK");
          JButton buttonUP = new JButton ("Up");
          JButton buttonDOWN = new JButton ("Down");
          JButton buttonRIGHT = new JButton ("Right");
          JButton buttonLEFT = new JButton ("Left");
          JButton buttonMAGIC = new JButton ("Magic");
          JButton buttonRUN = new JButton ("RUN");
          JTextField userINPUT = new JTextField(30);
          JLabel healthDisplay = new JLabel("Health:  ");
          JPanel panel1 = new JPanel ();
  
          ButtonListener bl = new ButtonListener();
  
           buttonOK.addActionListener(bl);
           buttonUP.addActionListener(bl); 
           buttonDOWN.addActionListener(bl);
           buttonRIGHT.addActionListener(bl);
           buttonLEFT.addActionListener(bl);
           buttonMAGIC.addActionListener(bl); 
           buttonRUN.addActionListener(bl);
  
  
           panel1.add(buttonOK);
           panel1.add(buttonDOWN);
           panel1.add(buttonRIGHT);
           panel1.add(buttonLEFT);
           panel1.add(buttonMAGIC);
           panel1.add(buttonRUN);
  
           panel1.add(healthDisplay);
  
           panel1.add(userINPUT);
  
           this.add(panel1);
  
           this.setVisible(true);
          }       
  
  
       //declaring variables "counters" for magic count, 
      //health count, etc.
  
      int healthMAX = 100;
      int healthMINIMUM = 0;
      int magicMAX = 100;
      int magicMINIMUM = 0;
      int walletSizeMAX = 9999;
      int walletSizeMINIMUM = 0;
  
      /** 
       * class used to create events
       * based on button sources
       */
  
  
      public class ButtonListener implements
          ActionListener
      {
  
          public void actionPerformed (ActionEvent e)
          {
              //Haven't made these codes yet but some WILL need to bring up a GUI
                  }
  
          }
      }
  }
  </code></pre>
  
  <p>The guiPullUpMagic class:</p>
  
  <hr>
  
  <pre><code>import javax.swing.*;
  
  import java.awt.event.*;
  
  import java.lang.Math.*;
  
  /**
  * class used to pull up the "spells" GUI
  */
  
  public class guiPullUpMagic extends JFrame
  {
      public void magic(String[] args)
      {
          new guiPullUpMagic();
      }
  
      private JButton buttonFIREMAGIC;
      private JButton buttonICEMAGIC;
      private JButton buttonHEALMAGIC;
      private JButton buttonSHOCKMAGIC;
  
      public guiPullUpMagic()
      {
          this.setSize(400,400);
          this.setTitle("Spells");
          this.setDefaultCloseOperation(
              JFrame.EXIT_ON_CLOSE);
  
          //button names to appear on panel2*
          //*button coordinates needed
  
          JButton buttonFIREMAGIC = new JButton ("FireBall");
          JButton buttonICEMAGIC = new JButton ("Ice Flurry");
          JButton buttonSHOCKMAGIC = new JButton ("Spark");
          JButton buttonHEALMAGIC = new JButton ("Heal Minor Wounds");
          JPanel panel2 = new JPanel();
  
          ButtonListener bl = new ButtonListener();
  
          buttonFIREMAGIC.addActionListener(bl);
          buttonICEMAGIC.addActionListener(bl);
          buttonSHOCKMAGIC.addActionListener(bl);
          buttonHEALMAGIC.addActionListener(bl);
  
          panel2.add(buttonFIREMAGIC);
          panel2.add(buttonICEMAGIC);
          panel2.add(buttonSHOCKMAGIC);
          panel2.add(buttonHEALMAGIC);
  
          this.add(panel2);
  
          this.setVisible(false);     
      }
  
      public class ButtonListener implements
          ActionListener
      {
  
          public void actionPerformed (ActionEvent e)
          {
              if (e.getSource() == buttonMAGIC); //THIS is where I'll need
                                                             //the buttonMAGIC variable
                                                             //from guiPullUp
              {
                      //code to bring up the guiPullUpMagic GUI
              }
          }
      }
  }
  </code></pre>