![]() |
![]() |
Java Multithreading | |
Creating a Thread | |
Thread Life Cycle | |
Thread Exceptions | |
Thread Synchronization |
Intro. to Graphics class | |
Drawing - Lines , Rectangles | |
Drawing - Circles and Ellipse | |
Drawing - Arcs | |
Drawing - Polygons | |
Drawing - Bar Charts |
Java Programs | |
Java Keywords Dictionary | |
Java Interview Questions |
In java, Applet can be executed on local computer or Web page of browser.
In this topic we will see how to compile and run the applet on local computer.
Let's see the applet syntax to understand how to create an Applet.
import java.awt.*; import java.applet.*; public class AppletClassName extends Applet { //declarations public void paint(Graphics g) { // Actual applet operation code .... .... } } /* <applet code="AppletClassName.class" width="300" height="300"> </applet> */
Displaying Hello World on Applet window
To print the message on the applet window, java has drawString() method stored in the Graphics class.
drawString(String,int,int) has 3 parameters - where String is the message to display, second is integer for x-axis and third integer for y-axis to place the message on window.
import java.awt.*; import java.applet.*; public class AppletProgram extends Applet { public void paint(Graphics g) { g.drawString("Hello Applet", 15, 120); } } /*<applet code="AppletProgram.class" width=500 height=500> </applet> */
Compile and run as
javac AppletProgram.java
appletviewer AppletProgram.class