title: event handling in java and the execution of actionPerformed method in java
body: <p>I have written a small code in java for simpleGUI.</p>
  
  <pre><code>package guidemo1;
  
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  
  public class GuiDemo1 implements ActionListener{
   JButton button;
      /**
       * @param args the command line arguments
       */
      public static void main(String[] args) {
          GuiDemo1 gui=new GuiDemo1();
          gui.go();
      }
  
      public void go()
      {
          JFrame frame=new JFrame();
          button=new JButton();
          frame.getContentPane().add(button);
          button.addActionListener(this);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(300, 200);
          frame.setVisible(true);
  
      }
      @Override
      public void actionPerformed(ActionEvent e) {
          //throw new UnsupportedOperationException("Not supported yet.");
          button.setText("I've been clicked");
      }
  }
  </code></pre>
  
  <p>I am newbie to JAVA.I have few questions related to this program.</p>
  
  <p>Can some one explain how actionPerformed method gets executed with out any call?</p>
  
  <p>Here I have defined frame object locally to the go() method and we are using button in actionPerformed which is another method.How is that possible?Isn't the button gets embedded on the frame?</p>
  
  <p>Thanks..</p>