Java Reference
In-Depth Information
Java
binary
code
Java
code
image
file
image
HTML
text
file
file
compile
TicTacToe.java
TicTacToe.class
y.jpg
x.jpg
TicTacToe.html
server
client
FIGURE 15.1: Java Applet architecture.
specified inside the head section. This is the title that will be displayed as the title of the
web browser window when the page is opened. Inside the body of an HTML file, one cannot
specify the point size of the text. Instead, one can specify headers of different size (e.g., H1,
H2, and so on, where H1 is the biggest size). The < P > and < /P > canbeusedtocreatea
new paragraph that is surrounded by horizontal lines.
Examine the code: <APPLET codebase="classes" code="TicTacToe.class" width =
350 height=200></APPLET> . This means display an applet at this place on the HTML web
page. The codebase parameter specifies the directory (relative to the directory where the
.html file is located) where the .class file can be found. As suggested in Figure 15.1, both
the .html and .class files need to be sent to the client.
An applet is similar to a Java application, but it has limited capabilities. It cannot
execute any program other than the applet on the client side. It cannot access any
files on the client's computer, except for the files that come with the applet. The
applet can communicate with the server from which the applet came and with no
other computers.
15.2 Principles of Java Applets
In order to create a Java Applet from a regular Java application, follow the following
general steps.
1. Remove the main method.
2. Create a class that extends JApplet . This will be the applet's window (i.e., substitutes
the class that inherits from JFrame ).
3. Add to this class the init method. The init method will be the first method to be
executed (similar to the main method).
 
Search WWH ::




Custom Search