title: How do I use button action events to call other classes?
body: <p>I am trying to create a GUI program using JFrame that allows me to call to call other classes when a button is clicked in the main class of another class.  I used JPanel to create the GUI panel so I could organize the buttons and such, so not all parts of the panel are in the same class.  I am having a hard time figuring out a way to use a button click in one class to have the main method call other classes to perform their actions.  I tried sending an int value to a mutator and accessor  and then get the int from that, but it doesn't set the global variable.  Is it a problem of sequence?  Please help.</p>
  
  <p>Here is a small piece of the code in case I was not being very clear(I am sure I wasn't):
  This is the class with the main method in it:</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  import javax.swing.JOptionPane;
  
  public class GUI extends JFrame{
  
  private hPanel hp;
  private mPanel mp;
  
  public GUI(){
  setLayout(new BorderLayout());
  setTitle("GUI");
  
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  hp = new hPanel();
  mp = new mPanel();
  add(hp, BorderLayout.NORTH);
  add(mp, BorderLayout.CENTER);
  pack();
  setVisible(true);
  }
  public static void main(String[]args){
  mPanel MP = new mPanel();
  pPanel PP = new pPanel();
  int buttIn = MP.getbuttonIndicator();
  
  
  if (MP.getbuttonIndicator()==1){
  PP.tester1();
  }
  else if (MP.getbuttonIndicator()==2){
  PP.tester2();
  }
  else if (MP.getbuttonIndicator()==3){
  PP.tester3();
  }
  else if (MP.getbuttonIndicator()==4){
  PP.tester4();
  }
  else if (MP.getbuttonIndicator()==5){
  PP.tester5();
  }
  else if (MP.getbuttonIndicator()==6){
  PP.tester6();
  }
  new Grade();
  
  }
  }
  </code></pre>
  
  <p>I want to use the buttons in this actionListener to initiate the calls from the main to other classes.  This actionListener is in another class from the main method:</p>
  
  <pre><code>private class JButtonListener implements ActionListener{
  public void actionPerformed(ActionEvent e){
  if (e.getSource()==button1){
  buttonIndicator = 1;
  setbuttonIndicator(buttonIndicator);
  }
  if (e.getSource()==button2){
  buttonIndicator = 2;
  setbuttonIndicator(buttonIndicator);
  }
  if (e.getSource()==button3){
  buttonIndicator = 3;
  setbuttonIndicator(buttonIndicator);
  }
  if (e.getSource()==button4){
  buttonIndicator = 4;
  setbuttonIndicator(buttonIndicator);
  }
  if (e.getSource()==button5){
  buttonIndicator = 5;
  setbuttonIndicator(buttonIndicator);
  }
  if (e.getSource()==button6){
  buttonIndicator = 6;
  setbuttonIndicator(buttonIndicator);
  }
  
  }
  }
  </code></pre>