Java Reference
In-Depth Information
TABLE 12-3
Some Members of the
class
JApplet
(
package
javax.swing
)(continued)
public void
destroy()
//Called by the browser or applet viewer. Informs this applet that
//it is being reclaimed and that it should destroy any resources
//that it has allocated. The method stop is called before destroy.
public void
showStatus(String msg)
//Displays the string msg in the status bar.
public
Container getContentPane()
//Returns the ContentPane object for this applet.
public
JMenuBar getJMenuBar()
//Returns the JMenuBar object for this applet.
public
URL getDocumentBase()
//Returns the URL of the document that contains this applet.
public
URL getCodeBase()
//Returns the URL of this applet.
public void
update(Graphics g)
//Calls the paint() method.
protected
String paramString()
//Returns a string representation of this JApplet; mainly used
//for debugging.
Unlike Java application programs, Java applets do not have the method
main
. Instead,
when a browser runs an applet, the methods
init
,
start
,and
paint
are guaranteed to be
invoked in sequence. Therefore, as a programmer, to develop an applet, all you have to do
is override one or all of the methods
init
,
start
,and
paint
. Of these three methods, the
paint
method has one argument, which is a
Graphics
object. This allows you to use the
class
Graphics
without actually creating a
Graphics
object. Later in this chapter, when
the
class
Graphics
is presented in detail, you will notice that it is an
abstract
class;
therefore, you cannot create an instance of this class. For now, all you need to do is import
the
package
java.awt
so that you can use various methods of the
class
Graphics
in
the
paint
method. To do so, you need the following two
import
statements:
import
java.awt.Graphics;
import
javax.swing.JApplet;
Because you create an applet by extending the
class
JApplet
, a Java applet in skeleton
form looks something like this:
import
java.awt.Graphics;
import
javax.swing.JApplet;
public class
WelcomeApplet
extends
JApplet
{
}
Search WWH ::
Custom Search