Create Applet in Java
Submitted by donbermoy on Tuesday, November 17, 2015 - 10:26.
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
- import javax.swing.*;
- import java.awt.*;
- public void init(){
- //create a container that will have the components to be placed
- // have the flowlayout as the layout manager to directly arrange the component
- // have the label to have the text "Hello World"
- // then add the label into the component
- con.add(lbl);
- }
- <html>
- <head>
- </head>
- <body bgcolor="000000">
- <center>
- <applet
- code = "sampleApplet.class"
- width = "500"
- height = "300"
- >
- </applet>
- </center>
- </body>
- </html>
- import javax.swing.*;
- import java.awt.*;
- public void init(){
- con.add(lbl);
- }
- }
Add new comment
- 186 views