1. Technology

Building Your First Java Applet


2 of 10

Write the Java Source Code
Writing the Source Code

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

I’m using Notepad to create my Java source code file. Open up your chosen editor, and type in this code:

 //Reference the required Java libraries
 import java.applet.Applet; 
 import java.awt.*; 
 //The applet code
 public class FirstApplet extends Applet {
     public void paint(Graphics g) {
       //Draw a rectangle width=250, height=100
       //Set the color to blue
       //Write the message to the web page
       g.drawString("Look at me, I'm a Java Applet!",10,50); 

Don’t worry too much about what the code means. For your first applet, it’s more important to see how it’s created, compiled and run.

  1. About.com
  2. Technology
  3. Java
  4. Web Applications
  5. Write the Java Source Code

©2014 About.com. All rights reserved.