You are here: Home / Topics / Program to use Applet with Button and it's event in Java

Program to use Applet with Button and it's event in Java

Filed under: Java on 2023-09-20 06:39:13

// Program to use Applet with Button and it's event.

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.applet.Applet;
import java.awt.Button;

/*
<applet code="AppletTest2.class" width="300" height="100">
</applet>
*/

public class AppletTest2 extends Applet 
{
Button b1 = new Button("Click Here");

public void init() 
{
 b1.addActionListener(new ActionListener() 
 {
  public void actionPerformed(ActionEvent e) 
  {
   System.out.println("Button was clicked..!");
  }
 });

 add(b1);
}
}


Output:

D:\Java>appletviewer AppletTest2.java

Button was clicked..!


About Author:
M
Mr. Dubey     View Profile
Founder of MCQ Buddy. I just like to help others. This portal helps students in getting study material free. Share your stuff here so that others can get benefitted.