title: How to define multiple JButton actions from a different class
body: <p>I am writing a program where I need to do different actions for a separate class depending on which button is clicked.</p>
  
  <pre><code>public class NewJFrame{
      public static JButton b1;
      public static JButton b2;
      public static JButton b3;
  }
  
  public class Slot{
  
      int value;
      JButton button;
  
      Slot(int value, JButton button)
      {
          this.value=value;
          this.button=button;
      }
  }
  
  public class Game{
      Slot[] slots=new Slot[3];
      Game(){
          slots[0]=new Slot(1,NewJFrame.b1);
          slots[1]=new Slot(2,NewJFrame.b2);
          slots[2]=new Slot(3,NewJFrame.b3);
      }
      public void actionPerformed(ActionEvent e) {
          for(int i=0;i&lt;3;i++){
              if(e.getSource()==slots[i].button)
                  slots[i].button.setText(String.valueOf(value));
          }
      }
  }
  </code></pre>
  
  <p>Something like this. Note that, I'm completely novice at GUI designing.</p>