Java Reference
In-Depth Information
Chapter 15
Java Applets
15.1 HTML and the Java Applet Architecture .............................................. 343
15.2 Principles of Java Applets .............................................................. 344
15.3 Creating Popup Windows .............................................................. 346
15.4 The Tic-Tac-Toe Game ................................................................. 347
15.5 Summary ................................................................................ 358
15.6 Syntax .................................................................................. 358
15.7 Important Points ....................................................................... 359
15.8 Exercises ................................................................................ 360
15.9 Lab ...................................................................................... 360
15.10 Project
.................................................................................. 360
The last game of this topic is the popular Tic-Tac-Toe game. In order for the player to
be able to play the game from more places, we will show how to place the game inside an
applet. This means that the user can play the game from their favorite web browser without
worrying about where to find the game and how to install it.
15.1 HTML and the Java Applet Architecture
Consider Figure 15.1. The file TicTacToe.java contains the code of our program. When
we compile it, the TicTacToe.class file is created. This file contains Java binary code that
can be executed by the Java Virtual Machine (JVM) .IfwewanttorunaJavaApplet,we
first need to download a .html file from the server. Here is part of an example .html file
that was automatically generated by NetBeans.
< HTML >
< HEAD >
< TITLE > Applet HTML Page < /TITLE >
< /HEAD >
< BODY >
< H3 >< HR WIDTH= "100%" > Applet HTML Page < HR WIDTH= "100%" >< /H3 >
< P >
< APPLET c o d e b a s e= "classes" code= "TicTacToe.class" width=350 height
=200 >< /APPLET >
< /P >
< /BODY >
< /HTML >
HTML stands for hypertext markup language .Itisoneofthesimplestkindofwebpages
that a web browser can display. An HTML file contains the text to be displayed together
with markup information (i.e., directions of how to display the text). An HTML file must
start with the < HTML > tag and then end with an < /HTML > tag. The symbol / means
end of the section. An HTML file usually has two sections: head and body. The title is
343
 
Search WWH ::




Custom Search