Site icon WebArtDeveloper

Applet Life cycle and How to Handle Event in Applet in Core Java

In this tutorial Applet Life cycle is explained and how to handle event in Applet in Core Java is shown.

Code:

MyApplet.java

/*<applet code=”MyApplet” height=”400″ width=”400″> </applet>*/

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

public class MyApplet extends Applet
{
Button b;
Label l;
TextField t;

public void init()
{
b = new Button(“OK”);
l = new Label(“Enter your name:”);
t = new TextField(30);

add(l);
add(t);
add(b);

b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JOptionPane.showMessageDialog(null,”Hello “+t.getText(),”MESSAGE”,JOptionPane.INFORMATION_MESSAGE);
}

});

System.out.println(“Inside init”);
}

public void start()
{
System.out.println(“Inside start”);
}

public void stop()
{
System.out.println(“Inside stop”);
}

public void destroy()
{
System.out.println(“Inside destroy”);
}

public void paint(Graphics g)
{}

}

https://youtu.be/PY4iO9_b5AI

Exit mobile version