title: a simple GUI multiplication table
body: <p>I'm supposed to create a simple multiplication table using GUI and for the most part, it's doing what it is supposed to do. But I just can't figure out the bottom portion of it where if you click on a specific button, a text will say what the two numbers are being multiplied and the answer.</p>
  
  <p>No matter what button I click, it'll only tell me the numbers I input and multiply them together. Here is my code:</p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.GridLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.JOptionPane;
  
  public class MultiplicationTable {
      int clickedCount;
      int rowCount;
      int colCount;
  
      JFrame frame;
      JPanel buttonPanel, countPanel;
      JLabel countLabel;
  
  
      private void createAndShowGui(){
  
          rowCount = Integer.parseInt(JOptionPane
                  .showInputDialog("How many rows do you want your multiplication table to be? "));
  
          colCount = Integer
                  .parseInt(JOptionPane
                          .showInputDialog("How many columns do you want your multiplication table to be? "));
  
  
  
          frame = new JFrame ("Simple Multiplication Table");
          frame.setLayout(new BorderLayout());
  
          buttonPanel = new JPanel();
  
          buttonPanel.setLayout(new GridLayout(rowCount, colCount));
  
  
          countPanel = new JPanel();      
          countLabel = new JLabel("? x ? = ?");
  
          for(int rowCounter = 1; rowCounter &lt;= rowCount; rowCounter++)
              for(int colCounter = 1; colCounter &lt;= colCount; colCounter++){
  
                  final JButton j = new JButton(Integer.toString(rowCounter * colCounter));
  
                  j.addActionListener(new ActionListener(){
  
  
                      @Override
                      public void actionPerformed(ActionEvent event) {
                          for(int rc = 1; rc &lt;= rowCount; rc++)
                              for(int cc = 1; cc &lt;= colCount; cc++){
                                  countLabel.setText(rc + " x " + cc + " = " + String.valueOf(rc * cc));  
                              }   
                      }
                  });
  
                  buttonPanel.add(j); 
              }
  
          frame.add(buttonPanel, BorderLayout.NORTH);
          countPanel.add(countLabel);
          frame.add(countPanel, BorderLayout.SOUTH);
  
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setVisible(true);
      }
  
      public static void main(String[] args){
          MultiplicationTable c = new MultiplicationTable();
          c.createAndShowGui();
      }
  }
  </code></pre>