Creating Java Applet
Hi folks,
Today I’ll be talking about How to create Java Applet. An applet is a program written in the Java programming language that can be included in an HTML page, same as an image or Adobe Flash content.
What can HTML NOT do?
An HTML cannot do the following:
- Interact with hardware
- Interact with OS and tasks
- Interact with hard drive
Also, all the dynamic stuff is restricted to the capability of JavaScript and VBScript. We need client code that runs on the system, can do all of the above and is secure too.An APPLET can do this job.
It is a program written in the Java and it can be included in an HTML page. It requires a Java technology-enabled browser to view a page that contains an applet.The applet’s code is transferred to the client’s system it is executed by the browser’s Java Virtual Machine (JVM). To embed the Java Applet in the web page, tag is used.To make you life easy, start building Applets using NetBeans. NetBeans is a free, easy to use IDE that allows you to quickly create and test Java Applications including an Applet.
- Start NetBeans
- Create New Project Select Java Application, Next
- Uncheck Create Main Class, Finish
- Source Package in Projects Tab
- Click New, Select Java -> JApplet, Next
- Specify Name (Optional), Finish
- In New Window write:
- Open Project Directory
- Goto build directory
- Copy Classes directory
- Create New Directory and Paste it in
- Create New HTML Page in that Directory
- Add Code:
- Save and Run the HTML file
import javax.swing.JApplet;
import java.awt.Graphics;
/**
*
* @author Umair
*/
public class NewJApplet extends JApplet {
/**
* Initialization method that will be called after the applet is loaded
* into the browser.
*/
@Override
public void init() {
// TODO start asynchronous download of heavy resources
}
@Override
public void paint(Graphics g)
{
g.drawRect(0, 0,
getSize().width – 1, getSize().height – 1);
g.drawString(“Hello world!”, 5, 15);
}
// TODO overwrite start(), stop() and destroy() methods
}
Press Shift+F6 to run the file.
Remember, the paint function is a default function that is overridden here. It uses a Graphics object to draw text on the Applet Surface.
<APPLET codebase="classes" code="NewJApplet.class" width=350 height=200></APPLET>
Walaahh !!! You first ever Applet is ready and running.
Follow us on Twitter or join our Facebook fanpage for latest Tech News and Tutorials.

How web design best practices can affect Search Engine Ranking
How to add Digg button in WordPress without Plugin
Sn0wbreeze 2.2 for Creating iOS 4.2.1 Custom Firmware on Windows is now Available for Download
Important SEO Tips to consider while Making your Site
Google’s Interactive Book Teaches About the Web