►Open any text editor like notepad and type below code to print ‘Hello’ as an applet.
♦A = imported for applet programs.
♦B = AWT is stands for Abstract Window Toolkit.Contains many tool pack like graphics.
♦C = Paint function is to perform different graphics activities.
♦D = to print a string.
♦E = String you want to print.
♦F = X coordinate of your string in applet window.
♦G = Y coordinate of your string in applet window.
♦H = ‘test’ is your class name is must be equal to your program name.
►Now save your file with .java extension. (Program name must be equal to class name)
►Compile your java program. (Same as compiling of java application program)
[Learn How to save a file with .java extension and compiling a java application program.]
Method to run a Java applet program is not similar to method to run a java application program.
There are two methods to run a Java applet program.
♦ Using Java compatible web browser
♦ Using Applet Viewer included with your JDK.
Using Java compatible web browser
► Open any text editor like notepad.
► Type below code
|<applet code = "test" width = 400 height = 300> </applet>|
►Save as a .html file in location of your java file.
♦If you want to save your html file in different location,
Change above code to:
|<applet code = "your location\test" width = 400 height = 300> </applet>|
|<applet code = "D:\my java files\test" width = 400 height = 300> </applet>|
► Now you can see your applet in that browser.
Using Applet Viewer
► Normally your JDK already contain an Applet Viewer for viewing applets (Search in your jdk folder).
► For using this method, add this line of code to your java program just before of your class.
|/* <applet code = "test" width = 300 height = 300> </applet> */|
/* <applet code = "test" width = 300 height = 300> </applet> */
public class test extends Applet
public void paint(Graphics g)
► Compile your Program.
► After successful compilation, type: appletviewer test.java to run your applet.
For any assist, comment below...