1. Home
  2. Computing & Technology
  3. Java

Building Your First Java Applet

By Paul Leahy, About.com

8 of 10

Create the HTML File

HTML File

Microsoft product screen shot(s) reprinted with permission from Microsoft Corporation.

It’s worth noting that so far you have followed exactly the same steps as you would if you were creating a Java application. The applet has been created and saved in a text file, and it has been compiled by the javac compiler.

Java Applets differ from Java applications when it comes to running them. What’s needed now is a web page that references the FirstApplet.class file. Remember, the class file is the compiled version of your applet; this is the file your computer can understand and execute.

Open up Notepad, and type in the following HTML code:

<HTML>
<HEAD>
<TITLE>My First Java Applet</TITLE>
</HEAD>
<BODY>
Here's my first Java Applet: <BR><BR>

<applet code="FirstApplet.class" width="300" height ="300">

</BODY>
</HTML>

Save the file as “MyWebpage.html” in the same directory as your Java applet files.

This is the most important line in the webpage:

<applet code="FirstApplet.class" width="300" height ="300">

When the web page is displayed, it tells the browser to open up your Java applet and run it.

Explore Java
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Java
  4. Tutorials
  5. Create the HTML File

©2009 About.com, a part of The New York Times Company.

All rights reserved.