Homework #7 -- sample code

This page presents the instructor's code for CISC370-011 homework #7.


Part 1: Applet

The instructor's code for the applet is in LanderApplet07.java and Ship07.java. It includes a 'Help' menu which displays a help message in a JOptionPane. The code to display the JOptionPane uses the requestFocus() method to get the focus back after the 'About->Help' menu item is selected. You can see the applet in action here.

The commands used to build the applet and its JAR file are given below. Note how an auxiliary file, appletclasses.txt, was used to pass the arguments to the jar command. The classes must be listed explicitly in the jar command because the applet's classes and the application's classes are in the same directory.

D:\CIS370\code>javac -d classes -sourcepath sources ^
    sources\com\bozoid\cis370\hw07\LanderApplet07.java ^
	sources\com\bozoid\cis370\hw07\Ship07.java

D:\CIS370\code>javadoc -sourcepath sources ^
    -d docs/hw07 com.bozoid.cis370.hw07
Loading source files for package com.bozoid.cis370.hw07...
Constructing Javadoc information...
Standard Doclet version 1.4.0

Generating docs/hw07\constant-values.html...
Building tree for all the packages and classes...
Building index for all the packages and classes...
Generating docs/hw07\overview-tree.html...
Generating docs/hw07\index-all.html...
Generating docs/hw07\deprecated-list.html...
Building index for all classes...
Generating docs/hw07\allclasses-frame.html...
Generating docs/hw07\allclasses-noframe.html...
Generating docs/hw07\index.html...
Generating docs/hw07\packages.html...
Generating docs/hw07\com\bozoid\cis370\hw07\package-frame.html...
Generating docs/hw07\com\bozoid\cis370\hw07\package-summary.html...
Generating docs/hw07\com\bozoid\cis370\hw07\package-tree.html...
Generating docs/hw07\com\bozoid\cis370\hw07\ActionTest07.html...
Generating docs/hw07\com\bozoid\cis370\hw07\AnimatedBalls.html...
Generating docs/hw07\com\bozoid\cis370\hw07\AnimatedLines.html...
Generating docs/hw07\com\bozoid\cis370\hw07\AnimationAction.html...
Generating docs/hw07\com\bozoid\cis370\hw07\LanderApplet07.html...
Generating docs/hw07\com\bozoid\cis370\hw07\Panel07.html...
Generating docs/hw07\com\bozoid\cis370\hw07\Ship07.html...
Generating docs/hw07\com\bozoid\cis370\hw07\Spinner.html...
Generating docs/hw07\com\bozoid\cis370\hw07\Trajectory.html...
Generating docs/hw07\serialized-form.html...
Generating docs/hw07\package-list...
Generating docs/hw07\help-doc.html...
Generating docs/hw07\stylesheet.css...

D:\CIS370\code>type sources\com\bozoid\cis370\hw07\appletclasses.txt
-C classes
com/bozoid/cis370/hw07/LanderApplet07.class
-C classes
com/bozoid/cis370/hw07/Ship07.class
-C classes
com/bozoid/cis370/hw07/AppletPanel07.class
-C classes
com/bozoid/cis370/hw07/AppletPanel07$1.class
-C classes
com/bozoid/cis370/hw07/AppletPanel07$GravAction.class
-C classes
com/bozoid/cis370/hw07/AppletPanel07$ShipKey.class
-C classes
com/bozoid/cis370/hw07/AppletPanel07$ShipTimer.class
-C classes
com/bozoid/cis370/hw07/AppletPanel07$ShipMouse.class

D:\CIS370\code>jar cvf lander07.jar ^
    @sources/com/bozoid/cis370/hw07/appletclasses.txt
added manifest
adding: com/bozoid/cis370/hw07/LanderApplet07.class(in = 829) (out= 472)(deflated 43%)
adding: com/bozoid/cis370/hw07/Ship07.class(in = 4242) (out= 2141)(deflated 49%)
adding: com/bozoid/cis370/hw07/AppletPanel07.class(in = 5326) (out= 2515)(deflated 52%)
adding: com/bozoid/cis370/hw07/AppletPanel07$1.class(in = 1058) (out= 583)(deflated 44%)
adding: com/bozoid/cis370/hw07/AppletPanel07$GravAction.class(in = 824) (out= 472)(deflated 42%)
adding: com/bozoid/cis370/hw07/AppletPanel07$ShipKey.class(in = 1110) (out= 533)(deflated 51%)
adding: com/bozoid/cis370/hw07/AppletPanel07$ShipTimer.class(in = 1121) (out= 541)(deflated 51%)
adding: com/bozoid/cis370/hw07/AppletPanel07$ShipMouse.class(in = 1046) (out= 519)(deflated 50%)

D:\CIS370\code>move /y lander07.jar sources\com\bozoid\cis370\hw07

D:\CIS370\code>

Part 2: Application

The instructor's code for the application is:

It is essentially unchanged from the code for homework #5, except that (a) the package statement was changed to place the application in com.bozoid.cis370.hw07, (b) some classes were renamed to reflect the homework number (e.g., Panel05 became Panel07), and (c) the required Preferences were implemented, mostly in two methods of the ActionTest07 class called saveState() and restoreState(). You can download the JAR file from here.

The statements used to compile the application and build its self-starting JAR file are given below. The jar statement uses the 'm' option and an auxiliary manifest file, mf.txt, to define the application's main class. Two other auxiliary files, appsources.txt and appclasses.txt, are used to simplify the javac and jar commands.

D:\CIS370\code>type sources\com\bozoid\cis370\hw07\appsources.txt
sources/com/bozoid/cis370/hw07/ActionTest07.java
sources/com/bozoid/cis370/hw07/Panel07.java
sources/com/bozoid/cis370/hw07/Animator.java
sources/com/bozoid/cis370/hw07/Trajectory.java
sources/com/bozoid/cis370/hw07/AnimationAction.java
sources/com/bozoid/cis370/hw07/AnimatedBalls.java
sources/com/bozoid/cis370/hw07/AnimatedLines.java
sources/com/bozoid/cis370/hw07/Spinner.java

D:\CIS370\code>javac -d classes @sources/com/bozoid/cis370/hw07/appsources.txt

D:\CIS370\code>type sources\com\bozoid\cis370\hw07\mf.txt
Main-Class: com.bozoid.cis370.hw07.ActionTest07

D:\CIS370\code>type sources\com\bozoid\cis370\hw07\appclasses.txt
-C classes
com/bozoid/cis370/hw07/ActionTest07$AMouse.class
-C classes
com/bozoid/cis370/hw07/ActionTest07$ExitListener.class
-C classes
com/bozoid/cis370/hw07/ActionTest07.class
-C classes
com/bozoid/cis370/hw07/AnimatedBalls$Ball.class
-C classes
com/bozoid/cis370/hw07/AnimatedBalls.class
-C classes
com/bozoid/cis370/hw07/AnimatedLines.class
-C classes
com/bozoid/cis370/hw07/AnimationAction.class
-C classes
com/bozoid/cis370/hw07/Animator.class
-C classes
com/bozoid/cis370/hw07/Panel07$1.class
-C classes
com/bozoid/cis370/hw07/Panel07$Panel07WindowListener.class
-C classes
com/bozoid/cis370/hw07/Panel07.class
-C classes
com/bozoid/cis370/hw07/Spinner.class
-C classes
com/bozoid/cis370/hw07/Trajectory.class

D:\CIS370\code>jar cvfm action07.jar ^
    sources/com/bozoid/cis370/hw07/mf.txt
    @sources/com/bozoid/cis370/hw07/appclasses.txt
added manifest
adding: com/bozoid/cis370/hw07/ActionTest07$AMouse.class(in = 1074) (out= 566)(deflated 47%)
adding: com/bozoid/cis370/hw07/ActionTest07$ExitListener.class(in = 669) (out= 408)(deflated 39%)
adding: com/bozoid/cis370/hw07/ActionTest07.class(in = 4707) (out= 2395)(deflated 49%)
adding: com/bozoid/cis370/hw07/AnimatedBalls$Ball.class(in = 1732) (out= 970)(deflated 43%)
adding: com/bozoid/cis370/hw07/AnimatedBalls.class(in = 1559) (out= 810)(deflated 48%)
adding: com/bozoid/cis370/hw07/AnimatedLines.class(in = 1654) (out= 945)(deflated 42%)
adding: com/bozoid/cis370/hw07/AnimationAction.class(in = 1174) (out= 569)(deflated 51%)
adding: com/bozoid/cis370/hw07/Animator.class(in = 184) (out= 158)(deflated 14%) 
adding: com/bozoid/cis370/hw07/Panel07$1.class(in = 561) (out= 348)(deflated 37%)
adding: com/bozoid/cis370/hw07/Panel07$Panel07WindowListener.class(in = 1326) (out= 574)(deflated 56%)
adding: com/bozoid/cis370/hw07/Panel07.class(in = 2067) (out= 919)(deflated 55%) 
adding: com/bozoid/cis370/hw07/Spinner.class(in = 2070) (out= 1099)(deflated 46%)
adding: com/bozoid/cis370/hw07/Trajectory.class(in = 1282) (out= 717)(deflated 44%)

D:\CIS370\code>move /y action07.jar sources\com\bozoid\cis370\hw07\

D:\CIS370\code>