|
|
JAVA, JSP, SERVLETS, TOMCAT, SERVLETS MANAGER,
Private JVM (Java Virtual Machine),
Private Tomcat Server
Alden Hosting offers private JVM (Java Virtual Machine), Java Server Pages (JSP), Servlets, and Servlets Manager with our Web Hosting Plans
WEB 4 PLAN and
WEB 5 PLAN ,
WEB 6 PLAN .
At Alden Hosting we eat and breathe Java! We are the industry leader in providing
affordable, quality and efficient Java web hosting in the shared hosting marketplace.
All our sites run on our Java hosing platform configured for
optimum performance using Java 1.6, Tomcat 6.0.X, MySQL 5.0.x, Apache 2.2.xx and web
application frameworks such as Struts, Hibernate, Cocoon, Ant, etc.
We offer only one type of Java hosting - Private Tomcat. Hosting accounts on the Private
Tomcat environment get their very own Tomcat server. You can start and re-start
your entire Tomcat server yourself.
The Life Cycle of an Applet (The Java™ Tutorials >
Deployment > Applets)
The Life Cycle of an Applet
Home Page
>
Deployment
>
Applets
The Life Cycle of an Applet
Here is the Simple applet.
The following is the source code for the Simple.
The Simple applet displays a descriptive string
whenever it encounters a major milestone in its life, such as when the user first visits the page the applet's on. The pages that follow
use the Simple applet and build upon it to illustrate concepts that are common to many applets. If you find yourself baffled by the Java source code, you might want to go to
Learning the Java Language to learn about the language.
/*
* Java(TM) SE 6 Version
*/
import java.applet.Applet;
import java.awt.Graphics;
//No need to extend JApplet, since we don't add any components;
//we just paint.
public class Simple extends Applet {
StringBuffer buffer;
public void init() {
buffer = new StringBuffer();
addItem("initializing... ");
}
public void start() {
addItem("starting... ");
}
public void stop() {
addItem("stopping... ");
}
public void destroy() {
addItem("preparing for unloading...");
}
private void addItem(String newWord) {
System.out.println(newWord);
buffer.append(newWord);
repaint();
}
public void paint(Graphics g) {
//Draw a Rectangle around the applet's display area.
g.drawRect(0, 0,
getWidth() - 1,
getHeight() - 1);
//Draw the current string inside the rectangle.
g.drawString(buffer.toString(), 5, 15);
}
}
Note: In this example, we extend the Applet class, not the Swing JApplet class, as we do not need to add Swing components to this applet.
Loading the Applet
You should see "initializing... starting..." above, as the result of the applet being loaded. When an applet is loaded, here's what happens:
- An instance of the applet's controlling class (an
Applet subclass)is created.
- The applet initializes itself.
- The applet starts running.
Leaving and Returning to the Applet's Page
When the user leaves the page for example, to go to another page
the browser stops the applet. When the user returns to the page,
the browser starts the applet.
Browser note:
Some browsers reload the applet when you return to its page.
In at least one browser, a bug exists where an applet can
initialize itself more than once without being reloaded.
Reloading the Applet
Some browsers let the user reload applets,
which consists of unloading the applet and then loading it again.
Before an applet is unloaded,
it's given the chance to stop itself
and then to perform a final cleanup,
so that the applet can release any resources it holds.
After that, the applet is unloaded
and then loaded again, as described in
Loading the Applet,
above.
Try this:
If your browser or other applet viewer
lets you easily reload applets,
reload the applet.
Look at the
standard output
to see what happens when you reload the applet.
(See
Displaying Short Status Strings for information about the standard output.)
You should see "stopping..." and "preparing for unloading..."
when the applet is unloaded.
You can't see this in the applet GUI
because the applet is unloaded before the text can be displayed.
When the applet is reloaded,
you should see "initializing..." and "starting...",
just like when you loaded the applet for the first time.
Quitting the Browser
When the user quits the browser
(or whatever application is displaying the applet),
the applet has the chance to stop itself and do final cleanup
before the browser exits.
Summary
An applet can react to major events in the following ways:
- It can initialize itself.
- It can start running.
- It can stop running.
- It can perform a final cleanup,
in preparation for being unloaded.
The next page describes the four applet methods
that correspond to these four types of reactions.
JAVA, JSP, SERVLETS, TOMCAT, SERVLETS MANAGER,
Private JVM (Java Virtual Machine),
Private Tomcat Server
Alden Hosting offers private JVM (Java Virtual Machine), Java Server Pages (JSP), Servlets, and Servlets Manager with our Web Hosting Plans
WEB 4 PLAN and
WEB 5 PLAN ,
WEB 6 PLAN .
At Alden Hosting we eat and breathe Java! We are the industry leader in providing
affordable, quality and efficient Java web hosting in the shared hosting marketplace.
All our sites run on our Java hosing platform configured for
optimum performance using Java 1.6, Tomcat 6.0.X, MySQL 5.0.x, Apache 2.2.xx and web
application frameworks such as Struts, Hibernate, Cocoon, Ant, etc.
We offer only one type of Java hosting - Private Tomcat. Hosting accounts on the Private
Tomcat environment get their very own Tomcat server. You can start and re-start
your entire Tomcat server yourself.
|