Answer all numbered and bulleted questions. Upload your answers and program files to the VikingWeb coursework section. Besides uploading your written answers to the VikingWeb, please turn in a printed copy either in class on the due date or leave a copy in the box outside my door later on during the day. (You may turn in the printed copies later than 5PM on the due date, but the files must be uploaded to VikingWeb at or before 5PM.)
You may work in pairs for all parts of this assignment, including the homework exercises. Remember also, your code will be graded for robustness - i.e. how well it handles in cases of erroneous input, etc. Be sure to think about things that could go wrong and try to deal with them.
The Java SDK comes with several demonstration applets and their source code. It can be interesting and helpful to read this source code if you want to learn new and exciting features of Java. We will not be doing anything further with these applets in this course, but you may want to browse the examples in the folder:
C:\Program Files\Java\jdk1.4.2\demo
(In general, the example files are in the demo
directory of wherever you installed the Java SDK. The applets
can also be accessed online at this site.)
To run the applets, either find the appropriate HTML file in the directory of the applet you wish to view and open it with the web browser. Or else, if Java is not installed in the web browser, or there are security restrictions on the browser, you can view the applets by running the appletviewer program from the terminal (command window).
For this lab, just try running the TicTacToe and DrawTest applets and take a brief look at their source code. You can look in detail at their source code and the other applets at your leisure.
x1, y1
fields in
the DrawPanel? What is the purpose of the x2,
y2
fields? (Note: the two pairs are used in
different ways.)
Download the following program and image data files: LogoAnimator.java, LogoAnimatorJPanel.java, images.zip. (The images archive should be uncompressed into a directory named "images" in the same directory as the Java files.)
This program displays an animated logo by displaying a
different image every 50 milliseconds, using the Swing
Timer
class. Run the program, look through the
source code, then:
LogoAnimatorApplet
, extending JApplet, that
adds the LogoAnimatorPanel panel to itself, with code to
start and stop the animation as appropriate (i.e. define the
methods init(), start(), and stop() appropriately for your
applet). You will also need to write an HTML web page in
which the applet is embedded. Call your HTML file
"LogoAnimator.html
".
The HTML applet tag embedded in a web page has a way of
specifying parameters for use by the applet. Within the
<APPLET>
...</APPLET>
on
can specify optional PARAM
elements with a
name
and value
. Look at the source
for this web page and the corresponding applet code to see how
this works: HelloApplet.html,
HelloApplet.java. (To
view the source of the web page, there is usually a
menu command "View Source" somewhere under the "View" menu of
your browser.
HelloApplet.java
applet so that it
also accepts an optional parameter allowing one to specify
the size of the font. To change the font size, you can use
the getFont
method of the Graphics
class to obtain the current font. Obtain a modified version
of the font using the appropriate deriveFont
method of the Font
class to change the
size. Then use the setFont
method in the
Graphics
class to update the font of the
applet's panel.
The following files make up the skeleton for what could be developed into a simple arcade game.
draw
method to describe how to
draw the actual object
Download, compile, and view the applet. A homework assignment (below) is left for you to exercise your creativity.
Based on material from Deitel & Deitel, Java How to Program, 6e.