Example of AWT ActionListener of java

import java.awt.*;
import java.awt.event.*;
class MyFrame extends Frame implements ActionListener
{
	Label l1;
	Button b1;
	int i;
	MyFrame()
	{
		super("Exapmle of ActionListener");
		l1=new Label("                           ");
		b1=new Button("Click me");
		b1.addActionListener(this);
		i=0;
		
		add(b1);
		add(l1);
		
		addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent we) {
                System.exit(0);
            }
        });
		
		setLayout(new FlowLayout());
		setSize(500,500);
		setVisible(true);
	}
	public void actionPerformed(ActionEvent e)
	{
		i++;
		l1.setText("Button Clicked: "+ Integer.toString(i));
	}
}
public class MyActionListener
{
	public static void main(String args[])
	{
		new MyFrame();
	}
}

0 Comments