Class browser.Applet
All Packages This Package Previous Next
Class browser.Applet
java.lang.Object
|
+----browser.Applet
-
public class
Applet
-
extends Object
Base applet class. All applets are subclasses of this class.
Once the applet is loaded it is associated with an AppletDisplayItem
in which it can draw. An applet's life is summarized by four methods:
- init()
- This method is called after the applet is created.
The applet can use this method to resize itself, download resources, get fonts,
get colors, etc.
- start()
- This method is called when the applet's document is visited.
The applet can use this method to start a background thread for animation, to play
a sound etc.
- stop()
- This method is called when the applet's document is no longer on
the screen. The applet should stop any thread it has forked and any long sounds
that are playing. It is garanteed to be called before the applet is destroyed.
- destroy()
- This method is called when the applet is discarded. It is the
last opportunity for the applet to clean up its act! Calls stop() if the applet
is still active.
When an applet is started it cannot directly draw to the screen. Instead it needs
to call repaint(). This will cause the paint(Graphics) method of the applet to be
called as soon as possible. This mechanism is needed so that the applet will not
get confused when the document in which it is embedded is scrolled or resized.
The applet class contains various method that help you get images, get fonts,
play audio, etc. If you can use these methods instead of doing the work yourself,
they are more likely to be supported in the future.
Here is a very simple example of an applet.
import awt.*;
import browser.*;
public class HelloInternet extends Applet {
public void init() {
resize(150, 25);
}
public void paint(Graphics g) {
g.drawString("Hello Internet!", 5, 20);
}
}
To try it out you need to add this in an html file.
<app class="HelloInternet">
-
See Also:
-
AppletDisplayItem
-
Author:
-
Chris Warth,
Arthur van Hoff
-
Version:
-
1.35, 13 May 1995
-
appletURL
-
The URL of the applet.
-
bgColor
-
The background color of the applet.
-
documentURL
-
The URL of the document in which the applet is embedded.
-
fgColor
-
The foreground color of the applet.
-
font
-
The font of the applet.
-
height
-
The height of the applet.
-
item
-
The display item in which this applet is being displayed.
-
tag
-
The tag.
-
width
-
The width of the applet.
-
Applet()
-
-
createImage(int, int)
-
Creates an image given a width and height.
-
destroy()
-
Cleans up whatever resources are being held.
-
getAttribute(String)
-
Gets an attribute out of theapplet's app tag.
-
getAudioData(String)
-
Gets audio data given a name.
-
getAudioData(URL)
-
Gets audio data given a url.
-
getAudioStream(URL)
-
Gets an audio stream given a url.
-
getColor(int, int, int)
-
Gets a Color.
-
getContinuousAudioStream(URL)
-
Gets a continuous audio stream given a URL.
-
getFocus()
-
Gets the focus.
-
getFont(String, int)
-
Gets a font with the given font name and size.
-
getFont(String, int, int)
-
Gets a font with the given font name, style, and size.
-
getFontMetrics(Font)
-
Gets the metrics for the given font.
-
getImage(String)
-
Gets an image given an image name.
-
getImage(URL)
-
Gets an image given a URL.
-
gotFocus()
-
Got focus.
-
init()
-
Initializes the applet.
-
isActive()
-
Returns true if the applet is started.
-
keyDown(int)
-
A character is typed inside the applet and it has
the focus.
-
lostFocus()
-
Lost focus.
-
mouseDown(int, int)
-
Mouse down.
-
mouseDrag(int, int)
-
Mouse drag (the mouse button is down).
-
mouseEnter()
-
Called when the mouse enters the applet (regardless of
the mouse button state).
-
mouseExit()
-
Called when the mouse exits the applet (regardless of
the mouse button state).
-
mouseMove(int, int)
-
Mouse move (the mouse button is up).
-
mouseUp(int, int)
-
Mouse up.
-
paint(Graphics)
-
Paints the applet, given a graphics context.
-
play(String)
-
Plays an audio sample.
-
play(AudioData)
-
Plays an audio sample.
-
repaint()
-
Repaints the applet, this will actually happen at
some later time.
-
resize(int, int)
-
Resizes the applet.
-
showDocument(URL)
-
Shows a Document.
-
showStatus(String)
-
Shows a status string at the bottom of the HotJava window.
-
start()
-
Called to start the applet.
-
startPlaying(InputStream)
-
Starts playing a stream of audio data.
-
stop()
-
Called to stop the applet.
-
stopPlaying(InputStream)
-
Stops playing a stream of audio data.
-
update(Graphics)
-
item
public AppletDisplayItem item
-
The display item in which this applet is being displayed.
Don't modify it.
documentURL
public URL documentURL
-
The URL of the document in which the applet is embedded.
Don't modify it.
appletURL
public URL appletURL
-
The URL of the applet. This can differ from the documentURL
when a "src" attribute is specified in the app tag.
Don't modify it.
tag
public TagRef tag
-
The tag. Use getAttribute() to get attributes in the tag.
Don't modify it.
-
See Also:
-
getAttribute
width
public int width
-
The width of the applet. Use resize() to change the size of
the applet and the display item in which it is located.
You can change it by calling resize().
-
See Also:
-
resize
height
public int height
-
The height of the applet. Use resize() to change the size of
the applet and the display item in which it is located.
You can change it by calling resize().
-
See Also:
-
resize
font
public Font font
-
The font of the applet. This font will be set when the paint()
method is called. If you want to modify it, you need to do this
in the init() method. This variable is initialized to an initial
value, feel free to modify it.
-
See Also:
-
paint,
init
fgColor
public Color fgColor
-
The foreground color of the applet. This color will be the foreground
color when the paint() method is called. This variable is initialized
to an initial value, feel free to modify it.
-
See Also:
-
paint
bgColor
public Color bgColor
-
The background color of the applet. This color is the background
color of the window the applet is in when the applet was created.
-
See Also:
-
paint
Applet
public Applet()
repaint
public void repaint()
-
Repaints the applet, this will actually happen at
some later time. To actually paint the applet HotJava
will call the paint() method.
-
See Also:
-
paint
resize
public void resize(int width,
int height)
-
Resizes the applet. You should resize the applet in the init() method.
Resizing the applet at another time may cause the document to be reformatted.
Don't worry about calling repaint(), resize will do the right thing for you.
-
See Also:
-
repaint
isActive
public boolean isActive()
-
Returns true if the applet is started. This will be true from just before
start() is called until just after stop() is called.
getAttribute
public String getAttribute(String name)
-
Gets an attribute out of theapplet's app tag. Note that the
width and height attributes are used to determine the initial
dimensions of the applet.
-
Returns:
-
the attribute value or null if the attribute is not defined.
getImage
public Image getImage(String name)
-
Gets an image given an image name. The name is assumed to be
relative to the appletURL. If the image can't be found there,
the documentURL is used.
-
Returns:
-
the image or null if something went wrong.
createImage
public Image createImage(int width,
int height)
-
Creates an image given a width and height. This is useful
to do double-buffered graphics which can be done by creating a
Graphics object that points to this image and then drawing
directly to the image.
-
See Also:
-
Graphics
-
Returns:
-
the image or null if something went wrong.
getImage
public Image getImage(URL url)
-
Gets an image given a URL.
-
Returns:
-
the image or null if something went wrong.
getAudioData
public AudioData getAudioData(String name)
-
Gets audio data given a name. The name is assumed to be
relative to the appletURL. If the data can't be found there,
the documentURL is used.
-
Returns:
-
the audio data or null if it could not be found.
-
See Also:
-
play
getAudioData
public AudioData getAudioData(URL url)
-
Gets audio data given a url.
-
Returns:
-
the audio data or null if the URL is invalid.
-
See Also:
-
play
getAudioStream
public InputStream getAudioStream(URL url)
-
Gets an audio stream given a url. The actual audio data
can be very large because it will be read as the audio
is being played.
-
Returns:
-
the stream or null if the URL is invalid.
-
See Also:
-
startPlaying
getContinuousAudioStream
public InputStream getContinuousAudioStream(URL url)
-
Gets a continuous audio stream given a URL. Note that
all of the data will read before the stream can be used.
-
Returns:
-
the stream or null if the URL is invalid.
-
See Also:
-
startPlaying
play
public void play(String name)
-
Plays an audio sample. The data is obtained using
getAudioData(). Nothing happens if the data could not
be found.
-
See Also:
-
getAudioData
play
public void play(AudioData data)
-
Plays an audio sample.
startPlaying
public void startPlaying(InputStream stream)
-
Starts playing a stream of audio data. Use stopPlaying to
stop the audio from playing.
-
See Also:
-
getAudioStream,
stopPlaying
stopPlaying
public void stopPlaying(InputStream stream)
-
Stops playing a stream of audio data.
-
See Also:
-
startPlaying
showStatus
public void showStatus(String msg)
-
Shows a status string at the bottom of the HotJava window.
showDocument
public void showDocument(URL doc)
-
Shows a Document.
getFont
public Font getFont(String name,
int size)
-
Gets a font with the given font name and size.
-
See Also:
-
Font
getFont
public Font getFont(String name,
int style,
int size)
-
Gets a font with the given font name, style, and size.
-
See Also:
-
Font
getFontMetrics
public FontMetrics getFontMetrics(Font font)
-
Gets the metrics for the given font.
-
See Also:
-
FontMetrics
getColor
public Color getColor(int r,
int g,
int b)
-
Gets a Color.
-
See Also:
-
Color
init
protected void init()
-
Initializes the applet.
You never need to call this directly, it is called automatically
by HotJava once the applet is created.
start
protected void start()
-
Called to start the applet. You never need to call this method
directly it is called when the applet's document is visited.
-
See Also:
-
stop
stop
protected void stop()
-
Called to stop the applet. It is called when the applet's document is
no longer on the screen. It is guaranteed to be called before destroy()
is called. You never need to call this method directly.
-
See Also:
-
start,
destroy
destroy
protected void destroy()
-
Cleans up whatever resources are being held. If the applet is active
it is first stopped.
-
See Also:
-
stop
paint
public void paint(Graphics g)
-
Paints the applet, given a graphics context.
The origin will be in the topleft corner of the applet.
The clipping area is set to the exact size of the applet.
The font, foreground color and background color are set to
default values.
You never have to call this method explicitly!
It will be called automatically by HotJava in response
to damage or expose events, or when you call repaint().
-
See Also:
-
repaint
update
public void update(Graphics g)
mouseDown
public void mouseDown(int x,
int y)
-
Mouse down. The x,y coordinates are relative to the
applet's top left corner. A call to mouseUp() is
guaranteed to follow when the mouse is released.
mouseDrag is called when the mouse is moved.
-
See Also:
-
mouseUp,
mouseDrag
mouseDrag
public void mouseDrag(int x,
int y)
-
Mouse drag (the mouse button is down). The x,y coordinates
are relative to the applet's top left corner.
mouseUp
public void mouseUp(int x,
int y)
-
Mouse up. The x,y coordinates are relative to the
applet's top left corner. This must have been preceded by
a call to mouseDown().
-
See Also:
-
mouseDown
mouseMove
public void mouseMove(int x,
int y)
-
Mouse move (the mouse button is up). The x,y coordinates
are relative to the applet's top left corner.
mouseEnter
public void mouseEnter()
-
Called when the mouse enters the applet (regardless of
the mouse button state). A call to mouseExit is guaranteed
to follow.
-
See Also:
-
mouseExit
mouseExit
public void mouseExit()
-
Called when the mouse exits the applet (regardless of
the mouse button state). Must have been preceded by a
call to mouseEnter().
-
See Also:
-
mouseEnter
getFocus
public void getFocus()
-
Gets the focus. This is usually called in the
mouseDown() method. A gotFocus() call will follow.
-
See Also:
-
gotFocus,
mouseDown
gotFocus
public void gotFocus()
-
Got focus. The user can now type into the applet.
-
See Also:
-
keyDown
lostFocus
public void lostFocus()
-
Lost focus.
keyDown
public void keyDown(int key)
-
A character is typed inside the applet and it has
the focus.
All Packages This Package Previous Next