Saturday 31 August 2019

Java Applet Hello World Example | Java Applet Hello World Program

                  In this post, we will see Java Applet Hello World Example | Java Applet Hello World Program. 

Find details of Life Cycle of Applet in this link:

                  Applet program does not have main() method. Hence, it can not be used for creating stand-alone application. It is to be used with other applications like webpages created by JSP, Servlet.
                  We need to extend class Applet given by package java.applet.
                  We can override init(), start(), stop(), destroy() methods given by Applet class. We may also need paint() method to redraw applet. paint() method is given by Component class which is given by java.awt package. paint() method accepts Graphics class object as parameter.

                  Go through the following programs:

Program (

import java.applet.*;
import java.awt.*;

public class HelloWorldApplet extends Applet
  public void paint(Graphics g)
    g.drawString("Hello World", 100, 100);

Program (HelloWorldApplet.html)

<head><title>Hello World Applet</title></head>
<applet code = "HelloWorldApplet.class" width = "300" height = "300">
If your browser is Java enabled, then only you can see Applet in your browser. If it is not Java enabled, then you need to add Java plug-ins in your browser or use appletviewer to view applet.

 How to run from terminal
parag@parag-Inspiron-N4010:~/Desktop/programs/applet$ javac
parag@parag-Inspiron-N4010:~/Desktop/programs/applet$ appletviewer HelloWorldApplet.html


Find Life Cycle of Applet in following link: .

No comments:

Post a Comment