Core Java - [Run Applet]

♠ Posted by Unknown in at 22:30

How to run Applet Program

1. To run applet using "appletviewer" program


If you want to run Applet program using third-party "appletviewer" program then, you must add <APPLET> tag with necessary  property setting in Java applet program as an comment. It shows in below Example.

Example:

//Write an Applet To Print "Hello Java"
/*
<APPLET
CODE = "HelloJava.class"
WIDTH = "400"
HEIGHT = "200">
</APPLET>
*/

import java.awt.*;
import java.applet.*;

public class  HelloJava extends Applet
{
            public void paint(Graphics g)
            {
                        g.drawString("Hello Java", 10, 100);
            }
}


1. Save above program as "HelloJava.java".
2. Compile Program [Command: prompt> javac HelloJava.java]
3. Create HTML File in same directory with same name "HelloJava.html".

HTML File

<HTML>
<HEAD>
<TITLE>Applet-01</TITLE>
</HEAD>

<BODY>
<APPLET
CODE = "HelloJava.class"
WIDTH = "400"
HEIGHT = "200">
</APPLET>
</BODY>
</HTML>


4. Run Program [Command: prompt>appletviewer HelloJava.html]


Output:


2. To Run Applet as HTML File.


When you create HTML file for your applet program then, you can run your applet directly opening HTML file into web-browser.

1 comments:

Thanks for Sharing this valuble information and itis useful for me and CORE JAVA learners.We also provides the best Online CORE JAVA Training classes.

Post a Comment