March 31, 2015

netbeans(EVENTSAMPLE)

import java.awt. *;
import java.awt.event. *;
import java.applet.Applet;
   
public class EventSample extends Applet implements ActionListener{
    Button b1;
    TextField txt1;
    int counter=0;
public EventSample(){
    b1 = new Button("Count");
    txt1=new TextField(" ", 20);
    add(b1);
    b1.addActionListener(this);
    add(txt1);
}  
public void init(String[]args){
    EventSample go=new EventSample();
}
public void actionPerformed(ActionEvent e){
    ++counter;
    txt1.setText(counter+" ");
}
}

No comments: