Java Reference
In-Depth Information
The menus don't actually work at the moment but at least they look good! We will start adding the code
to implement menu operations in the next chapter.
More on Applets
Applets are a peculiar kind of program as they are executed in the context of a web browser. This
places some rather severe restrictions on what you can do in an applet, to protect the environment in
which they execute. Without these restrictions they would be a very direct means for someone to
interfere with your system - in short, a virus delivery vehicle.
System security in Java programs is managed by a security manager. This is simply an object that provides
methods for setting and checking security controls that determine what is and what is not allowed for a Java
program. What an applet can and cannot do is determined by both the security manager that the browser
running the applet has installed, and the security policy that is in effect for the system.
Unless permitted explicitly by the security policy in effect, the main default limitations on an applet are:
An applet cannot have any access to files on the local computer.
An applet cannot invoke any other program on the local computer.
An applet cannot communicate with any computer other than the computer from which the
HTML page containing the applet was downloaded.
Obviously there will be circumstances where these restrictions are too stringent. In this case you can set
up a security policy that allows certain operations for specific trusted programs, applets, or sites, by
authorizing them explicitly in a policy file . A policy file is an ASCII text file that defines what is
permitted for a particular code source. We won't be going into details on this, but if you need to set up a
policy file for your system, it is easiest to use the policytool program supplied with the JDK.
Because they are normally shipped over the Internet as part of an HTML page, applets should be
compact. This doesn't mean that they are inevitably simple or unsophisticated. Because they can access
the host computer from which they originated, they can provide a powerful means of enabling access to
files on that host, but they are usually relatively small to allow them to be easily downloaded.
The JApplet class includes the following methods, which are all called automatically by the browser
or applet viewer controlling the applet:
Method
Description
void init()
You implement this method to do any initialization that is necessary for
the applet. This method is called once by the browser when the applet
starts execution.
void start()
You implement this method to start the processing for the applet. For
example, if your applet displays an animated image, you would start a
thread for the animation in this method.
This method is called by the browser immediately after init() . It is also
called if the user returns to the current .html page after leaving it.
Search WWH ::




Custom Search