Introduction
This is a program, which can create a graphical user interface to make visible dynamic content in the web browser. It creates a window for the web content visible inside the web browser. The compiled java program can be loaded into the web browser with the help of HTML document. To execute the applet in the web browser it must contain java virtual machine. The applet can deal with presentation logic and business logic. An applet does not have main method as the starting point of the execution.
Creation process of an applet
- Create a class by inheriting java applet. Applet class.
- Override the life cycle method of applet such as init (), start (), stop (), destroy () and provide a presentation with business logic into these methods.
- Create an HTML file, which must contain the <Applet> tag to load the applet into the web browser.
- Compile the file and load the HTML file into the browser.
- Using the applet viewer tool available in JDK can test an applet corresponding HTML file.
- Init()
- Start()
- Paint()
- Stop()
- Destroy()
- import java.applet.*;
- import java.awt.*;
- public class life extends Applet {
- public void init() {
- setBackground(Color.yellow);
- setFont(new Font("", Font.BOLD, 30));
- Label lab1 = new Label("lifecycle Applet");
- add(lab1);
- System.out.println("Init called");
- }
- public void start() {
- System.out.println("start called");
- }
- public void paint(Graphics g) {
- System.out.println("paint called");
- }
- public void stop() {
- System.out.println("stop called");
- }
- public void destroy() {
- System.out.println("destroy called");
- }
- }
javac life.java
appletviewer life.java

Comments
Join the conversation! Your thoughts help the community grow.