Make a Java Applet
Applets came with a great promise of embedding software into web pages. It is very powerful if used properly. They are used by some banks for client login, which speaks greatly of its security features.
Contents
Steps
Setting up the Environment
- Download and install JDK
- Download and install some Java IDE, to make things easier. Netbeans or Eclipse are good Open Source tools.
. Check the Sources and Citations for the download link from Sun's website.
- Make a folder for your source codes and projects.
Testing the Sample Applet
- Open NotePad and copy and paste the code in the code section.
- Click file, and then click save as, and save it in your java folder but name the code "test.java" (without quotation marks)
- Exit the window and click start, run, then type in cmd in the box and hit ok.
- Type cd C:\jdk6\bin and hit enter
- Type javac then C:\java\test.java and hit enter.
- Now copy and paste the launcher into NotePad and Click file, and then click save as, and save it in your java folder but name the launcher. "test.htm" (without quotation marks).
- Now go to the java folder you made and launch the test.htm file.
Embedding a Java program into an applet
- Note: You need to know how to program Java in order to make your own applet.
- Open your MAYANK of choice or a simple text editor (like notepad in windows).
- Code a Java program to do something. Make it a subclass of JPanel , so you can put it into a top level swing container like a JApplet or a JFrame
- Create a basic JApplet to launch your JPanel program.
- Override the
start()
method, get a reference to the contentPane, add your JPanel to it and repack the Applet.- You might need to fine-tune the component allocation on the JPanel, to better fit the applet window.
- Override the
- Use the same procedure as for compiling and loading the sample applet to pack your program and run it on the basic launcher.
Sample Code
Basic "Hello World" Applet
HTML Launcher
Tips
- When installing JDK, install all the features. You will need them.
- Applets running over the internet have strict security policy than Java software running Locally. You will have to digitally sign your applet to give it more freedom (but not all the rights of a local software) like making file operations.
Things You'll Need
- Java programming skills
- JDK.(Java Development Kit and Java Runtime Environment) You can download it through the link below
- Computer with Windows, Linux, or Mac
- An internet browser
Related Articles
- Use Graphics in a Java Applet
- Make a Java Applet Animation With CarpStudio
- Program in Java
- Create a New Java Project in Eclipse
- Get Input from a User in Java
- Add Advertisements to Your Android Applications Using Admob
- Change Java Runtime
Sources and Citations
- http://java.sun.com/javase/downloads/index.jsp Download the Java JDK
- http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JPanel.html JPanel JavaDoc
- http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JApplet.html JApplet JavaDoc
- http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JFrame.html JFrame JavaDoc
- http://mindprod.com/jgloss/signedapplets.html Signed Applets on Canadian Mind Products
- How to Make an Applet - Sun Java Tutorials