HOME
J2ee tutorials
Java introduction
Java basic
Java installation
Java Packages Learn
Applets Java Threads Java Gui component

Java Event Handaling Java Streams and Files
 Java Swings Java JDBC
 Java Network Programming Java RMI
 Java Servlets Java javabeans
 EJB Struts

|
applet
Applet is a program that appears embedded in a web document and is meant to be hosted by a web browser.e view using a tool called appletviewer.java applets are embeded in a web page using html.
what is the difference between applet nad application
-
applet can be embeded in html and download over the internet but application havE no support in html for embedding or downloading.
-
Applets can only be executed inside a java compitable container,such as a modern web browser.Application can be executed from the command line with the
help of an executable file called java.exe
Creating Applets
To create the applet you should use class called applet
steps for creating Applet
step1: open notepad and type the following code
|
import java.applet.Applet;
import java.awt.*;
public class test extends Applet
{
public void paint(Graphics g)
{
g.drawString("welcome to freewbschools.com",50,100);
}
}
|
let us understand the line of the program
line 1-- Imports the applet class. which present inside the pacakage java.applet
line 2-- Imports the classes present inside java.awt package.
line 3-- Creates class test and procede by public modifier and inherited by applet class.
line 4--The line is creating a method called paint() which is present inside the applet class. This method display the text on the applet.
line 5-- When u run applet the method drawstring() used in this line dispaly "welcome to freewebschools.com" on the applet at 50th row and 100 th column.
step 2-- Save the file as test.java and compile
step 3 --open the notepad and create html file that call the applet. save the file as test.html
The contents are below
|
<html>
<body>
<applet code="test" width=400 height=200>
</applet>
</body>
</html>
|
the above code applet tags has been used the attribute "code".This tag indicates the class name "test" and the attribute "width" and "height"
indicates width and height of the applet respectively.
step 4 run the applet by executing the html file . This can be done by 2 methods
Give this command on the command prompt
appletviewer test.html
or
invoke the html file form the browser
|
|
Inform Friend About This Site |