Use the getSize() method, which the Applet class inherits from the Component class in the Java.awt package. The getSize() method returns the size of the applet as a Dimension object, from which you extract separate width, height fields.
The following code snippet explains this:
Dimension dim = getSize();
int appletwidth = dim.width();
int appletheight = dim.height();
@Place the .class file in the directory containing the HTML document into which you want to insert the applet.
@Copy the <applet>...</applet> tag from your applet implementation or examples to the clipboard.
@In FrontPage select the "HTML" tab from the lower left hand corner.
@Paste the <applet>...</applet> tag in an appropriate place between the <body> and </body> tags. You'll find a gray box with the aqua letter "J" in the "Normal" view indicating the the applet tag has been inserted.
@To see the applet appearance select the "Preview" tab.
The following are the Applet’s information methods:
getAppletInfo() method: Returns a string describing the applet, its author, copyright information, etc.
getParameterInfo( ) method: Returns an array of string describing the applet’s parameters.
The applet stub interface provides the me by which an applet and the browser communicate. Your code will not typically implement this interface.
Java v1.02 only supports the "voice format" of the .au sound files. This is also know as "µ-law, 8/16-bit, mono, 8000hz sample rate"
Applets are small programs trferred through Internet, automatically installed and run as part of web-browser. Applets implements functionality of a client. Applet is a dynamic and interactive program that runs inside a Web page displayed by a Java-capable browser. We don’t have the concept of Constructors in Applets. Applets can be invoked either through browser or through Appletviewer utility provided by JDK.
Ask the applet for its applet context and invoke showDocument() on that context object.
URL targetURL;
String URLString
AppletContext context = getAppletContext();
try
{
targetURL = new URL(URLString);
}
catch (MalformedURLException e)
{
// Code for recover from the exception
}
context. showDocument (targetURL);
JComponent (except top-level containers)
We can use the java.net.URLConnection and java.net.URL classes to open a standard HTTP connection and "tunnel" to a Web server. The server then passes this information to the servlet. Basically, the applet pretends to be a Web browser, and the servlet doesn't know the difference.
As far as the servlet is concerned, the applet is just another HTTP client. Applets can communicate with servlets using GET or POST methods. The parameters can be passed between the applet and the servlet as name value pairs. Objects can also be passed between applet and servlet using object serialization. Objects are serialized to and from the inputstream and outputstream of the connection respectively.
Name your applets inside the Applet tag and invoke AppletContext’s getApplet() method in your applet code to obtain references to the other applets on the page.
We can use the java.net.URLConnection and java.net.URL classes to open a standard HTTP connection and "tunnel" to the web server. The server then passes this information to the servlet in the normal way. Basically, the applet pretends to be a web browser, and the servlet doesn't know the difference. As far as the servlet is concerned, the applet is just another HTTP client
The getParameter() method can be used within the init() method to access the parameter data.
It takes the parameter name as an argument.
Example:
public void init()
{
String val = getParameter("foreground-color");
}
The Canvas class of java.awt is used to provide custom drawing and event handling. It provides a general GUI component for drawing images and text on the screen. It does not support any drawing methods of its own, but provides access to a Graphics object through its paint() method. The paint() method is invoked upon the creation and update of a canvas so that the Graphics object associated with a Canvas object can be updated.
drawString( ) method is used to output a string to an applet. This method is included in the paint method of the Applet.
Following are the main differences:
Application: Stand Alone, doesn’t need web-browser.
Applet: Needs no explicit installation on local machine. Can be trferred through Internet on to the local machine and may run as part of web-browser.
Application: Execution starts with main() method. Doesn’t work if main is not there.
Applet: Execution starts with init() method.
Application: May or may not be a GUI.
Applet: Must run within a GUI (Using AWT). This is essential feature of applets.
Whenever a screen needs redrawing (e.g., upon creation, resizing, validating) the update method is called. By default, the update method clears the screen and then calls the paint method, which normally contains all the drawing code.
Applet class consists of a single class, the Applet class and three interfaces: AppletContext, AppletStub, and AudioClip.
Yes. Add a main() method to the applet.
The simplest method is to use the static variables of a shared class since there's only one instance of the class and hence only one copy of its static variables.
A slightly more reliable method relies on the fact that all the applets on a given page share the same AppletContext.
We obtain this applet context as follows:
AppletContext ac = getAppletContext();
AppletContext provides applets with methods such as getApplet(name), getApplets(),getAudioClip, getImage, showDocument and showStatus().
Use the parseInt() method in the Integer Class, the Float(String) constructor or parseFloat() method in the Class Float, or the
Double(String) constructor or parseDoulbl() method in the class Double.