Freshman Honors Seminar

CS U231 Fall 2008

http://www.ccs.neu.edu/jpt/fhs/

Materials from previous years are at:

Links to Course Materials

Introductory Links

The plan or syllabus for the CCIS Freshman Honors Seminar as a PDF document.

Access to the Sun Java site

Sun Java Downloads

Javadocs

Java Language Specification

Access to the Eclipse site for Eclipse “Ganymede”

Eclipse Downloads

At this site, choose “Eclipse IDE for Java Developers (85 MB)”.

Access to Eclipse 3.2 for Windows (an older version I like to use)

eclipse-SDK-3.2-win32.zip

Access to the Java Power Tools.

The JPT Home site

The JPT 2.7.0 site

The JPT 2.7.0 library jpt.jar

The JPT 2.7.0 javadocs

The JPT 2.7.0 annotated source and tutorial

The JPT 2.7.0 applets

The template methods class Methods.java for the Java Power Framework

The template methods applet class MethodsApplet.java for the Java Power Framework Applet

Access to cascading style sheets

The main cascading style sheet for this web site: fhs.css.

The screen cascading style sheet for this web site: fhs_screen.css.

The applet cascading style sheet for this web site: applet.css.

Back to Top.

Down to Bottom.

Introductory Links

Links to Course Materials

9/12/08: First Applet
9/14/08: First Sample Application
9/14/08: Homework #1
9/18/08 Tic Tac Toe
9/23/08: Homework #2

Course Materials

9/12/08: First Applet

To execute the first applet, click on the snapshot below.

First applet snapshot and access to the applet

The applet source will be available from the applet page. The applet extends JPFApplet which is a class that automatically creates the graphical user interface (GUI) that you see above and automatically defines the green buttons that execute the simple public methods defined in the extending class.

In particular, the one green button “Test” that you see is created based on the following simple method:

    public void Test() {
        Shape shape1 = new XRect(100, 100, 100, 50);
        
        Paintable paintable1 =
            new ShapePaintable
                (shape1, PaintMode.FILL_DRAW, Colors.red);
        
        Shape shape2 = new XOval(150, 125, 100, 50);
        
        Paintable paintable2 =
            new ShapePaintable
                (shape2, PaintMode.FILL_DRAW, Colors.yellow, Colors.blue);
        
        window.clearSequence();
        window.appendPaintable(paintable1);
        window.appendPaintable(paintable2);
        window.repaint();
    }

The button executes the method which:

The sample applet is set up so that you can drag the shapes in the window using the mouse.

Back to Top.

Back to Links to Course Materials.

Back to Start of First Apple.

Down to Bottom.

9/14/08: First Sample Application

The sample application must be compiled in a development environment such as Eclipse and run on your local machine rather than through a browser. This is your task in Homework 1 below.

The first sample application is defined in the file Methods.java .

The file Methods.java contains a public class named Methods. It is a Java requirement that the name of the public class and the name used in its file name be the same. This is a historical requirement which now seems unfortunate but that is the way things are. We often use a file with the name Methods.java to run experiments. This is fine as long as the files belong to different projects and are in different folders on the machine.

In the sample application, class Methods extends JPF. Therefore, as with the sample applet above, there will be an automatic GUI with green buttons to execute the simple public methods defined in Methods.

The first public method defined is:

    public double EvalDouble(double x) {
        return x;
    }

Since this method has both a parameter x of type double and a return type which is also double, it is necessary to bring up an auxiliary GUI to allow the user to enter the input parameter and see the return value. Here is a snapshot of this auxiliary GUI:

FirstSample/EvalDouble snapshot

Notice that the input parameter on the right may be entered with mathematical expressions including function calls. The evaluation of such mathematical expressions is built into the I/O system of Java Power Tools.

The second public method defined is:

    public void Plot() {
        new FunctionsPlotter().frame();
    }

This method uses the sophisticated FunctionsPlotter class that is built into JPT. After creating a new object of this class, the method call frame() asks the functions plotter object to put itself into a frame, that is, a new top-level window on the system.

Here is a snapshot of the function plot tab of the functions plotter. This snapshot is reduced to 75% of its original size. To see the full size snapshot, click on the snapshot.

FunctionsPlotter function plot tab

As you see, two functions are plotted. The sine function denoted sin is built into Java and JPT. The other function f is user-defined.

Here is a snapshot of function definition tab of the functions plotter with the definition of function f illustrated. This snapshot is reduced to 75% of its original size. To see the full size snapshot, click on the snapshot.

FunctionsPlotter function definition tab

Back to Top.

Back to Links to Course Materials.

Back to Start of First Sample.

Down to Bottom.

9/14/08: Homework #1

The purpose of Homework 1 is simply to get Java, Eclipse, and the JPT library jpt.jar installed and then to test that everything is working correctly. To do that, you will test using the First Sample Application discussed above. For convenience, we repeat the link:

The First Sample Application is defined in the file Methods.java .

Here are the steps. Note that the download links are given above.

Step 1: Unless you are using Mac OS X, download and install Java.

Step 2: Download and install Eclipse.

Step 3: Download jpt.jar. Place this file in an easily accessible folder on your system so that when an update is available you may easily do the replacement.

Step 4: Open Eclipse. Either accept the default “workspace” or choose a folder for the workspace that is also easily accessible.

Step 5: Following the directions and screen snapshots on the JPT site, set the Eclipse defaults so that they are convenient for student programming. Note that the screen snapshots are from an earlier version of Eclipse but the settings for the current version should be similar.

Step 6: In the compiler settings of Eclipse, be sure to define a variable named “JPT” that refers to your copy of jpt.jar.

Step 7: Create a new Java project and name it “FirstSample”. Make sure you do both of the following:

Step 8:Download the first sample application Methods.java and place it on the desktop. Then with the Eclipse window covering only part of the screen, drag the file Methods.java into the src directory of the “FirstSample” project. This drag operation will make a copy of the file so the original is unchanged.

Step 9: Run and test the first sample application and try the 2 examples discussed above. Use these experiments to see some of the possibilities in JPT.

Back to Top.

Back to Links to Course Materials.

Back to Start of Homework #1.

Down to Bottom.

9/18/08: Tic Tac Toe

The Tic Tac Toe game is elementary and so provides a simple setting in which to illustrate several ideas in building graphical user interfaces (GUIs) using the Java Power Tools. Consider two screen snapshots from the Tic-Tac-Toe program. In the first screen snapshot, player X has won the game and the winning sequence is highlighted in yellow. In the second screen snapshot, the game has been played to a tie since neither X nor O has won and no more moves are possible.

TicTacToe image with a winner       TicTacToe image with a tie

Click on either snapshot above to go to the JPT 2.6.0 Applets Page where there is a more complete dicussion of Tic-Tac-Toe together with access to the applet and the source code. When you reach that page, click on the snapshots there to launch the applet and get to the source code.

You will see that the Tic-Tac-Toe source code is structured into 2 Java classes in 2 files. The class TicTacToe defines Tic-Tac-Toe as an application. The class TicTacToeApplet uses TicTacToe to define Tic-Tac-Toe as an applet. It is very convenient to build an application class in such a way that it can easily be utilized to create a corresponding applet.

Back to Top.

Back to Links to Course Materials.

Back to Start of Tic Tac Toe.

Down to Bottom.

9/23/08: Homework #2

In last week's class (9/18/09), I asked you to "look at" the code for:

Actually, I would like you to do a bit more before the next class (9/25/08).

Please print these two files.

Then “annotate” these printouts with comments that explore a number of questions:

You may not be able to fully understand the Java details but you should be able to locate where things happen.

In class, I will go over questions like this and use them as a means for explaining lots of Java principles.

In my opinion, it is far easier to explain how something works if you see what it is good for.

I will ask you to hand in your printout of TicTacToe.java signed with your name at the end of the class.

Back to Top.

Back to Links to Course Materials.

Back to Start of Homework #2.

Down to Bottom.