Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
The first bold line of the following listing begins a block that defines theHelloWorld
class.import javax.swing.JApplet; import java.awt.Graphics; public class HelloWorld extends JApplet { public void paint(Graphics g) { g.drawRect(0, 0, getSize().width - 1, getSize().height - 1); g.drawString("Hello world!", 5, 15); } }
The
extends
keyword indicates that HelloWorld is a subclass of the class whose name follows:JApplet
. To learn more about subclasses and inheritance, see Object-Oriented Programming Concepts.
Applets inherit a great deal of functionality from the
Applet
orJApplet
class, including the abilities to communicate with the browser and to present a graphical user interface (GUI).For example, when a Java-capable browser loads a page containing an applet, the browser sends a request to the applet, telling the applet to initialize itself and start executing. You'll learn more about what the Applet class provides in the rest of this lesson.
An applet must extend either
Applet
orJApplet
. You can also write other classes to support the applet's functionality. Java Plug-in loads other classes from the same location from which it loaded the applet's main class.
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.