title: The mouse listener in Java
body: <p>The <code>MouseListener</code> on a <code>JButton</code> is registered during the application startup then after startup any mouse clicks on the button the corresponding mouseClicked(MouseEvent e) method will be called.</p>
  
  <p>The question is what/who is responsible to create the <code>MouseEvent</code> object with all the metadata and invoke the <code>mouseClicked</code> method.</p>
  
  <p>Posting a SSCCE:</p>
  
  <pre><code>public class TestMouseListener {
      public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
              createAndShowGui();  
          }); 
      }
  
      private void createAndShowGui(){
          JFrame frame = new JFrame(); 
          JButton button = new JButton(); 
          frame.add(button); 
          button.addMouseListener(new MouseAdapter() {
              public void mouseClicked(MouseEvent e) { 
                  System.out.println("The button was clicked");   
                  System.out.println("The clicked time is":e.getWhen());  
              } 
          }); 
      } 
  }
  </code></pre>