sandguy82
Audience Engagement Tactician
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
100 XP
Today in Java, i will teach you how to create an applet in Java.
An applet is a small application that is viewed on the Web using java.
So, now let's start this tutorial!
1. Open JCreator or NetBeans and make a java program with a file name of sampleApplet.java. In the classname, extend a JApplet to have an applet library.
2. Import javax.swing.* and awt.* package because we will going to have the JLabel in swing and also the Container.
3. Create a init() function to initialize an array. Then have this code inside the init() function.
Note: You have to build your program to have the .class file extension for viewing of the applet.
4. Now, create a new file. Click File Type, choose Other Folder and click HTML Applet.
After creating it, it will have the given code. Then in the Applet Code, put and encode your file name of the created java file, the sampleApplet.class. Follow this code below:
Press F5 to run the program.
Output:
Full source code of the sampleApplet.java:
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
If you have some queries, feel free to contact the number or e-mail below.
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware
An applet is a small application that is viewed on the Web using java.
So, now let's start this tutorial!
1. Open JCreator or NetBeans and make a java program with a file name of sampleApplet.java. In the classname, extend a JApplet to have an applet library.
2. Import javax.swing.* and awt.* package because we will going to have the JLabel in swing and also the Container.
- import
javax.swing.*
;
- import
java.awt.*
;
3. Create a init() function to initialize an array. Then have this code inside the init() function.
- public
void
init(
)
{
- //create a container that will have the components to be placed
- Container
con =
getContentPane(
)
;
- // have the flowlayout as the layout manager to directly arrange the component
- con.setLayout
(
new
FlowLayout
(
)
)
;
- // have the label to have the text "Hello World"
- JLabel
lbl =
new
JLabel
(
"Hello World!"
)
;
- // then add the label into the component
- con.add
(
lbl)
;
- }
Note: You have to build your program to have the .class file extension for viewing of the applet.
4. Now, create a new file. Click File Type, choose Other Folder and click HTML Applet.

After creating it, it will have the given code. Then in the Applet Code, put and encode your file name of the created java file, the sampleApplet.class. Follow this code below:
- <!
DOCTYPE HTML
PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
>
- <
html>
- <
head>
- </
head>
- <
body bgcolor=
"000000"
>
- <
center>
- <
applet
- code =
"sampleApplet.class"
- width =
"500"
- height =
"300"
- >
- </
applet>
- </
center>
- </
body>
- </
html>
Press F5 to run the program.
Output:

Full source code of the sampleApplet.java:
- import
javax.swing.*
;
- import
java.awt.*
;
- public
class
sampleApplet extends
JApplet
{
- public
void
init(
)
{
- Container
con =
getContentPane(
)
;
- con.setLayout
(
new
FlowLayout
(
)
)
;
- JLabel
lbl =
new
JLabel
(
"Hello World!"
)
;
- con.add
(
lbl)
;
- }
- }
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
If you have some queries, feel free to contact the number or e-mail below.
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware