0% found this document useful (0 votes)
35 views9 pages

Applets: Using The Status Window

The document discusses several methods for displaying information in applets, including: - Using showStatus() to output a message to the browser's status window. The status window is good for feedback, options, and errors. - getDocumentBase() and getCodeBase() return the URLs of the directory containing the HTML file and applet class file, which can be used to load resources. - AppletContext provides information about the applet's environment, and methods like showDocument() can display web pages. - The audiochip interface defines methods like play(), stop(), and loop() for controlling audio clips. - System.out.println() sends output to the Java console rather than

Uploaded by

achutha795830
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views9 pages

Applets: Using The Status Window

The document discusses several methods for displaying information in applets, including: - Using showStatus() to output a message to the browser's status window. The status window is good for feedback, options, and errors. - getDocumentBase() and getCodeBase() return the URLs of the directory containing the HTML file and applet class file, which can be used to load resources. - AppletContext provides information about the applet's environment, and methods like showDocument() can display web pages. - The audiochip interface defines methods like play(), stop(), and loop() for controlling audio clips. - System.out.println() sends output to the Java console rather than

Uploaded by

achutha795830
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 9

Applets

Using the Status Window:


•In addition to displaying information in its
window, an applet can also output a message to
the status window of the browser or applet
viewer on which it is running. To do so, call
showstatus() with the string that you want
displayed.
•The status window is a good place to give the
user feedback about what is occurring in the
applet suggest options or possibly report some
types of errors.
•The status window also makes an excellent
debugging aid, because it gives you an easy
way to output information about your applet.
The following applet demonstrates showstatus()
• Import java.awt.*;
• Import java.applet.*;
• /*
• <applet code = “status window” width = 300 height=50>
• </applet>
• */
• Public class statuswindow extends Applet
• {
• Public void init()
• {
• setBackground(color.cyan);
• }
• // display msg in applet window
• Public void paint(Graphics g)
• {
• g.drawString(“This is in the applet window”,10,20);
• showStatus(“This is shown in the status window”);
• }
• }
The HTML Applet Tag:

• The applet tag can be used to start an applet from both an HTML document and from
an applet viewer. An applet viewer will execute each applet tag that it finds in a
separate window, while web browser will allow many applets on a single page.
• The syntax for a full form of the applet tag is shown below:
• <Applet
• [codebase = codebaseURL]
• Code = appletfile
• [Alt = alternate text]
• [Name = apllet instance name]
• Width = pixels Height = pixels
• [Align = alignment]
• [vspace = pixels] [Hspace = pixels]
• >
• [<param name = AttributeName value = AttributeValue>]
• [<param name = AttributeName value = AttributeValue>]
• ….
• [HTML displayed in the absence of java]
• </applet>
Passing Parameters To
Applets:
• getDocumentBase() and getCodeBase():
• You will create applets that will need to explicitly load
media and text.
• Java will allow the applet to load data from the directory
holding the HTML file that started the applet (the
document base) and the directory from which the
applet’s class file was loaded (the code base).
• These directories are returned as URL objects by
getDocumentBase() and getCodebase(). They can be
concatenated with a string that names the file you want
to load.
• The following applet illustrates these methods :
• // display code and document bases :
• Import java.awt.*;
• Import java.applet.*;
• Import java.net.*;
• /*
• <applet code = “Bases” width = 300 height = 50>
• </applet>
• */
• Public class bases extends applet
• {
• // display code and document bases
• Public void paint(Graphics g)
• {
• String msg;
• URL url = getCodeBase(); // get code base
• Msg = “Code Base” + url.toString()
• g.drawString(msg,10,20);
• url = getDocumentBase(); //get doc base
• msg = “Document Base:” + url.toString();
• g.showString(msg,10,40);
• }
• }
AppletContext and
ShowDocument()-
• AppletContext is an interface that lets you get
information from the applet’s execution environment.
The context of the currently executing applet is
obtained by a call to the getAppletContext() method
defined by applet.
• There are two showDocument() methods. The
method shoDocument(URL) displays the document
at the specified URL. The method
showDocument(URL,string) displays the specified
document at the specified location within the browser
window
• /* using an applet context getCodebase() and showDocument() to display an HTML file */
• Import java.awt.*;
• Import java.applet.*;
• Import java.net.*;
• /*
• <applet code = “ACDemo” width = 300 height = 50>
• </applet>
• */
• Public class ACDemo extends Applet
• {
• Public void start()
• {
• appletContext ac = getAppletContext();
• URL url = getCodeBase(); // get url of this applet
• Try
• {
• Ac.showDocument(new URL (url + “test.html”));
• }
• Catch(malformedURLException e)
• {
• showStatus(“URL not found”);
• }
• }
• }
The Audiochip Interface:
– The audiochip interface defines these
methods.
• Play() – play a clip from the beginning
• Stop() – stop playing the clip
• Loop() – play the loop continuously
• After you have loaded an audio clip using
getAudioClip() you can use these methods
to play it.
Output to the console:
– Output to an applet’s window must be accomplished through
GUI-based methods such as drawstring() , it is still possible to
use console output in your applet- is still possible to use console
output in your applet – especially for debugging purpose.
• In an applet , when you call a method such as
system.out.printly() the output is not sent to your applet’s
window.
• Instead it appears either in the console session in which
you launched the applet viewer or in the java console
that is available in some browsers.
• Use of console output for purposes other then debugging
is discouraged, since it violates the design principles of
the graphical interface most users will expect.

You might also like