- Example - Home
- Example - Environment
- Example - Strings
- Example - Arrays
- Example - Date & Time
- Example - Methods
- Example - Files
- Example - Directories
- Example - Exceptions
- Example - Data Structure
- Example - Collections
- Example - Networking
- Example - Threading
- Example - Applets
- Example - Simple GUI
- Example - JDBC
- Example - Regular Exp
- Example - Apache PDF Box
- Example - Apache POI PPT
- Example - Apache POI Excel
- Example - Apache POI Word
- Example - OpenCV
- Example - Apache Tika
- Example - iText
- Java Useful Resources
- Java - Quick Guide
- Java - Useful Resources
How to create a basic Applet in Java
Problem Description
How to create a basic Applet?
Solution
Following example demonstrates how to create a basic Applet by extending Applet Class. You will need to embed another HTML code to run this program.
import java.applet.*;
import java.awt.*;
public class Main extends Applet {
public void paint(Graphics g) {
g.drawString("Welcome in Java Applet.",40,20);
}
}
Now compile the above code and call the generated class in your HTML code as follows −
<HTML>
<HEAD>
</HEAD>
<BODY>
<div >
<APPLET CODE = "Main.class" WIDTH = "800" HEIGHT = "500"></APPLET>
</div>
</BODY>
</HTML>
Result
The above code sample will produce the following result in a java enabled web browser.
Welcome in Java Applet.
java_applets.htm
Advertisements