Quick Learn JAVA

Hour III. Applets
Now we are going to learn how to create Applets, to include in your web pages and amaze your friends.
Example V.
import java.applet.Applet; // Includes standard Applet classes
import java.awt.*; // Standard Graphics Routines

public class Wow extends Applet {
  // Applets use paint instead of main
  public void paint (Graphics page) {
    page.drawString("Wow, this is an Applet!", 5, 10);
  } // method paint
} // class Wow
The page.drawString statement is like the print command. Note that it also accepts the coordinates for the text. In the above example, the text is placed five pixels right and ten down from the top left corner of the Applet.

To actually use this Applet :
•    compile it like a normal program with javac
•    create the following HTML file
•    <HTML>
•    <HEAD>
•    <TITLE>The Wow Applet!</TITLE>
•    <BODY>
•    <APPLET CODE="Wow.class" WIDTH="150" HEIGHT="50">
•    </APPLET>
•    <HR>
•    Was that easy or what?
•    </BODY>
•    </HTML>
•    load the HTML file with a web browser
•    then watch the magic
Applets is a topic that could easily be the subject matter of an entire book, to learn more visit :
Sun's Java Tutor (http://java.sun.com/docs/books/tutorial)

No comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More