title: How do I get the text of a button in Java?
body: <pre><code>class Test extends JPanel implements MouseListener
  {
      private JButton b1, b2, b3, b4;
  
      public Test()
      {
          setLayout (new GridLayout (2, 3));
  
          b1 = new JButton ("Button 1");
          b2 = new JButton ("Button 2");
  
          add (b1);
          add (b2);
      }
  
      public void mousePressed (MouseEvent event)
      {
          if (event.getText() == b1.getText())
          {
          }
      }
  }
  </code></pre>
  
  <p>I was wondering if there was a method within the <code>MouseListener</code> or <code>JPanel</code> class that allows me to get the text of a button that is clicked. Thanks</p>