ActionListener Demo

By Blanca :-)





The Code


ActionListener Included in Applet
// @author Blanca J. Polo

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class ListenerDemoApplet2 extends Applet implements ActionListener {

  private TextField tf = new TextField(" ");
  Button b = new Button (" Click Me ");
  int clicks = 0;


  public void init(){
     tf.setEditable(false);
     tf.setText(""+clicks);  


     b.addActionListener(this);
     this.add(b);
     this.add(tf);
  }   //init method finishes



  public void actionPerformed(ActionEvent e){

      String whichButton = e.getActionCommand();

      if(whichButton.equals(" Click Me ")){
             clicks++;
             tf.setText(""+clicks);

         }  //end of if-statement

     }  // end of actionPerformed method


} //end of class ListenerDemoApplet2