How to Make a JAVA Applet

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.

Instructions

    • 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

      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

      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

      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

      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.

Related Searches:

Resources

Comments

You May Also Like

Related Ads

Featured