• Java Applet Example

    Java Applet Example

    Java Applet Example, is created using java Applet class functionality. Java Applets are special purpose GUI programs those can be run on several ways like, using appletviewer tool or on third party web browser.

    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. Run Program [Command: prompt>appletviewer HelloJava]

    Output:

    Java Applet Example

    Figure: Java Applet Example

    2. To Run Applet as HTML File.

    If programmer need to run Java Applet using third party web browsers like, Internet Explorer, Mozila Firefox, of Google Chrome, he need to create HTML file for above applet program then, he can run his applet directly opening HTML file into web-browser.

    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>

    Appreciate my work :Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrDigg thisShare on YummlyShare on VKFlattr the authorBuffer this page

Leave a Reply

Your email address will not be published. Required fields are marked *