How to use Applets
By Ramakrishna on Aug 9, 2008 in Applets Tutorial
How to use Applets
1)–>An applet is a Panel that allows interaction with a Java program
A applet is typically embedded in a Web page and can be run from a browser
You need special HTML in the Web page to tell the browser about the applet
For security reasons, applets run in a sandbox: they have no access to the client’s file system
2)–>Most modern browsers support Java 1.4 if they have the appropriate plugin
In the PC labs, Internet Explorer 5.5 has been updated, but Netscape has not
The best support isn’t a browser, but the standalone program appletviewer
In general you should try to write applets that can be run with any browser
3)–>You write an applet by extending the class Applet
Applet is just a class like any other; you can even use it in applications if you want
When you write an applet, you are only writing part of a program
The browser supplies the main method
The simplest possible applet:
TrivialApplet.java
import java.applet.Applet;
public class TrivialApplet extends Applet { }
TrivialApplet.html
<applet code=”TrivialApplet.class” width=150 height=100>
</applet>
<!– /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:”"; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:”Times New Roman”; mso-fareast-font-family:”Times New Roman”;} @page Section1 {size:8.5in 11.0in; margin:333.0pt 3.0in 333.0pt 3.0in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} –>
The above are the sample programs for you to know how to run an applet
First we have write the code in the java by saving the file with an .java extension and then compile that file by that extension, you will get the .class file from that
After getting the class file you just embedd that .class path in the <applet code=”"> .It can be used in two ways just place the above code in your java file itself (or)
You can write the .html file to run the above java file using the above applet code in the html file
