How To

How to Make a JAVA Applet

Contributor
By eHow Contributing Writer
(8 Ratings)

A Java applet is a small program written in Java source code. Java is an object-oriented programming language suited to client-server architectures, or the Web. An applet is a program with a limited function. A Java applet can be positioned in a remote computer, a server or your own computer. Java applets can be embedded in hypertext markup language (HTML) code and are executed by the browser. Read on to learn more.

Difficulty: Easy
Instructions
  1. Step 1

    Install the tools that will let you build Java programs. Create a folder under your C drive and name it '"jdk." Visit the Sun Microsystems website and download the Java Development Kit (JDK) and the Java Runtime Environment (JRE) to that folder. Install these packages.

  2. Step 2

    Type the following source code on a Notepad:

    import java.awt.*;
    import java.applet.Applet;
    public class MyFirstApplet extends Applet {
    public void paint (Graphics g) {
    g.drawString("This is my first Applet!!!", 100, 25);
    }
    }

    Save the test file as "C:\MyFirstApplet.java."

  3. Step 3

    Compile the Java source code. This produces the Java applet. Click Start. Select Run. Type: "javac C:\MyFirstApplet.java". This will create file, 'MyFirstApplet.class'. It is your Java applet.

  4. Step 4

    Embed your Java applet into Hypertext Markup Language (HTML) code so you can see it through a browser. Open Notepad and type the following HTML script (replace starting and closing quotation marks with carrots):
    "HTML"
    "HEAD"
    "TITLE"My First Applet"/TITLE"
    "BODY"
    "CENTER"
    "APPLET CODE = 'MyFirstApplet.class' WIDTH = 100 HEIGHT = 25 "/APPLET"
    "/CENTER"
    "/BODY"
    "/HTML"
    Save it as, "C:\MyFirstApplet.html."

  5. Step 5

    Launch your default browser. Type, "C:\MyFirstApplet.html" in the URL space. Verify that you see "This is my first Applet!!!" in a rectangle in the middle of your browser page.

Tips & Warnings
  • This article assumes a Windows operating system and JDK/JRE Version 6.0.
  • Make sure you select the fuetars option when installing JDK.

Post a Comment

Post a Comment
  • Have you done this? Click here to let us know.
I Did This

Related Ads

Computers
Alexia Petrakos,

Meet Alexia Petrakos eHow's Computers Expert.

Get Free Computers Newsletters

Copyright © 1999-2009 eHow, Inc. Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy Policy.   en-US

eHow Computers
eHow_eHow Technology and Electronics