Button and ActionListener in Java AWT


The Java ActionListener is notified whenever you click on the button or menu item. It is notified against ActionEvent.

An ActionListener can be used by the implements keyword to the class definition. It can also be used separately from the class by creating a new class that implements it. It should also be imported to your project.

Source Code

package awtDemo;
import java.awt.*;
class MyApp extends Frame
{
	Button btn;
 
	public MyApp()
	{
		super("Tutor Joes");
		setLayout(null);
 
		btn=new Button("Click Me");
		btn.setBounds(75,75,200,50);
		add(btn);
		setSize(1000,600);
		setVisible(true);
 
	}
 
}
 
 
public class app
{
	public static void main(String args[])
	{
		MyApp frm =new MyApp();
	}
To download raw file Click Here

Output

Java AWT


Basic Programs