CS 5741 - Programming Assignment 1

Due Tue Sep 22, 10 points

Introduction

In this programming assignment you will create a simple combined applet/application program that draws some simple figures. You will do this using a toolkit that I provide.

Setup

You will start your work for this assignment with two netbeans project directories. They are available in zipped form through the links below.

You should be able to download both of these files by clicking on their links. You should put them both into the same directory. It is best to create a new directory that you will be using for other netbeans projects for this course. Then unzip both of the files.

Start up netbeans. Bring up the "Projects" pane if it is not already open by clicking on "Window->Projects" in the menu bar.

Then open the two projects that you downloaded. One way to do this is t right-click in the "Projects" pane and then click on "Open Project...". When the "Open Project" dialog appears, use it to find and open the two projects.

To test that your setup is working, right-click on "CS5741_Testing" in the "Projects" pane, then click on "Run". The CS5741_Testing project is set up so that the appBaseTest.ResourceViewer program will run. If you get a program running you have set everything up correctly.

Contents of the Projects

The CS5741_Toolkit project contains several utility Java packages for building applets and applications. You can create javadoc for this project by right-clicking on "CS5741_Toolkit" in the "Projects" pane then clicking on "Generate Javadoc" in the popup menu. While netbeans is generating the javadoc it will print out some warnings. These just indicate some deficiencies in the documentation. When it is done, netbeans will bring up the index page for it in your browser, starting it up if necessary. You will probably want to bookmark the web page.

The code in the toolkit is all working (as far as I know), but some of it is experimental in nature. That means that it has been tested but the organization of the classes may need some refactoring to make them easier to use. Generally, the quality of the documentation of a class reflects the quality and stability of its code.

The CS5741_Testing project contains some of the code that has been used for testing the code in CS5741_Toolkit. In addition to testing the toolkit, these programs are illustrations of how it is used.

The Programming Assignment

Your assignment is to create a program that draws some simple figures. The testing project already contains a program that does this (guiTest.DrawPanelTest), but it only runs as a standalone application. You will first convert it so that it can run either as an applet or as a standalone application using the appBase.AppBase class in the toolkit. Then you will enhance the program so that it has a menu for drawing several different figures.

The Combined Applet/Application

To make the program run as either an applet or as a standalone application, you should start by creating a new netbeans java application project. To do this, right-click in the "Projects" pane and click on "New Project...". The dialog that comes up will prompt you for project type (choose "Java Application"), project name (your choice; could be "PA1" for example), and the class name for the main program (go with the default supplied by netbeans).

This new project should include CS5741_Toolkit as a package library. You can do this by right-clicking on the new project in the "Projects" pane then selecting "Properties" from the popup menu. In the dialog that comes up click on "Libraries" in the "Categories:" pane. On the right of the dialog there should be a button labeled "Add Project...". Click on it, then browse around to find the CS5741_Toolkit project. When you have selected the library click on the "Add Project Jar Files" button on the right side of the dialog.

Edit the main class that was create earlier to make the class a subclass of AppBase. You will initially get an error indication because you do not have an import statement for the AppBase class. That is easily fixed: right-click in the editor pane, the click on "Fix Imports" in the popup menu.

After fixing the imports you will still get error indications from the editor because you need to implement some methods that are declared abstract in the AppBase class. At this point, you need to read the javadoc documentation for the class to find out how to complete the implementation. It is largely a matter of cutting and pasting code from guiTest.DrawPanelTest into the abstract methods that you need to implement. Some variables that declared local to a method in guiTest.DrawPanelTest may need to be converted to instance variables so they can be accessed by more than one method. The main method in your program should be the same as the one in appBaseTest.ResourceViewer except for the class names that appear in the first line of code.

In fact, appBaseTest.ResourceViewer also inherits from the AppBase class and can be viewed as a template for all AppBase subclasses. In the appBaseTest package you will also find two .html files. These are also intended as templates for testing AppBase subclasses as applets. Put copies of them, modified as directed by internal comments, into the directory that contains your program class. When you bring them up in the netbeans editor, you can view them as web pages by right-clicking in the editor pane and selecting "View" from the popup menu.

The Enhanced Program

If everything is working as an applet then it is time to have a bit of creative fun. Enhance the DrawPanel class so that it can do more than one drawing. I'll leave the choice of drawings to you. It will probably be easier to take the anonymous constructor for the DrawPanel subclass out into a separate java file.