Programming Assignment 3
CS 45500
Computer Graphics
Fall, 2026

This assignment makes use of the files contained in this zip file. This assignment is due Friday, November 20.

For this assignment, you will implement a simple event driven GUI program that combines our 3D renderer with the Java GUI framework. This assignment is base on Renderer 2, renderer_2.zip, JavaGui.zip, and JavaGuiEvents.zip.

In the hw3 zip file there is a program file Hw3.java that you need to complete. Also in the zip file is a demo program hw3_demo.jar that you can run (on Windows) by double clicking on hw3_demo.cmd. On Linux or Macs (and also on Windows) you can run the demo program from the command-line with this command.

        > java -jar hw3_demo.jar

Play around with the demo program quite a bit to get a sense of what your code should implement.

Carefully read the code in Hw3.java to understand the outline of what you need to write. Think in terms of the Model-View-Controller (MVC) design pattern. Notice how the program's outline specifies code for each of the Model, the View, and the Controller. The Model part of MVC is pretty much complete in Hw3.java. You need to implement about half of the View part (the GUI components) and most of the Controller part (the event handlers).

You need to implement two (broad) steps. First, create all the GUI components needed by the program and add them to the appropriate GUI containers. Second, define event handlers for all of the GUI components. You should complete the first step before working on the second.

If you compile and run the Hw3.java program from the zip file, you will see that it produces a window (a JFrame) containing a framebuffer with a GUI panel below it. The framebuffer should display a black sphere. In the GUI panel below the framebuffer, the model combo box should work and let you change the model displayed in the framebuffer. However, the other GUI components in the bottom panel do not do anything yet (you need to implement their event handlers). Also, the window is missing a GUI panel along its right edge (the east panel). You need to create GUI components and add them to the east panel so that the window looks like the demo program. Then you need to add event handlers for each of the GUI components.

When you implement the east panel, notice that the panel object is already defined for you in Hw3.java as a Box container. The Box container has the ability to equally space its components vertically in the container. (A standard JPanel with a BoxLayout manager would bunch all the components together at the top of the panel.) To get the Box container to equally space its components, you need to put glue into the container between the components (specifically, vertical glue). To get your components all centered on the panel's vertical midline, your need to call setAlignmentX(Component.CENTER_ALIGNMENT) on each component. Each pair of radio buttons should be contained in a JPanel. Those two panels should be given borders using the setBorder() method. You create the needed Border object with this code.

      final Border line = BorderFactory.createLineBorder(Color.black, 1, true);
      final Border padding = BorderFactory.createEmptyBorder(5, 5, 5, 5);
      final Border indentedBorder = BorderFactory.createCompoundBorder(padding, line);

Write your component code in small steps. Compile and run your program after you create and add each component to the east panel. It is easier to debug one small step rather than debug seven or eight steps with an unknown number of errors in them.

After the GUI looks correct, start to implement the event handlers. The event handler for the model combo box is implemented for you. You need to implement all the other event handlers. Start with simple event handlers.

  1. Make the "Axis" checkbox turn on and off the red axes.
  2. Make the "Information" button print the scene object to the console window.
  3. Make the "Perspective/Orthographic" radio buttons switch between the two Camera modes.
  4. Make the "Debug" checkbox turn on and off the renderer's debug logging.

Then make the "Screenshot" button save the FrameBuffer as a PPM file. Look in the clients_r2 folder from renderer_2.zip for the file InteractiveModelsAll_R2.java. It implements a "screenshot" feature using the '+' key command.

Write the event handler for the color combo box (use the model combo box handler as a guide). The color combo box event handler should translate the selected name in the combo box into an integer value and store that value in the colorChoice field (which is part of the Model in MVC). Then the updateGUI() method (which is the View in MVC) should use the colorChoice value to select an appropriate (static) method from the utility class renderer.scene.util.ModelShading. That class in the renderer contains static methods for shading models in a number of different ways. Read the Javadocs for renderer_2 for the API to the ModelShading class.

Write the event handlers for the White and Black radio buttons. When the background color is black, it does not make sense to have the color black as a choice in the color combo box. When the user changes the background color from white to black, the first entry in the color combo box needs to be changed from black to white. Similarly, when the user changes the background color to white, the first entry in the color combo box needs to be changed from white to black. The two radio button event handlers should modify the three instance variables backgroundColor, foregroundColor, and foregroundColorName (from the MVC's Model). The updateGUI() method should actually change the first entry in the combo box (that is implemented for you).

Write the event handlers for moving the model. Moving the model involves three slider objects. Each slider needs its own ChangeListener event handler. There are three variables in the MVC's Model to help you manage this, xAxisSliderValue, yAxisSliderValue, and zAxisSliderValue. The slider event handlers should just update the values of these variables. The updateGUI() method is where these values are actually used to change the translation Vector in the scene's Position object.

After a slider event handler (which is part of the Controller in MVC) updates one of the three slider variables (which are part of the Model in MVC), then the View needs to use the x, y, and z slider values to translate the Scene's Model. (Notice that we have both a Model class in the renderer and a Model in the MVC pattern; they are not the same thing!) The slider values are always integers between 0 and 100. The View (which is the updateGUI() method) needs to convert the x, y, and z slider values into camera coordinates for the position's translation vector. Here is how that translation should be done.

The updateGUI() method should put the converted translation values into the translation Vector of the Position that holds the Model.

Next, write the event handler for the reset button. It should set the three variables xAxisSliderValue, yAxisSliderValue, and zAxisSliderValue back to their initial values, then call the setvalue() method on each slider, and then call the updateGUI() method.

Finally, make the "Clipping" checkbox turn on and off the renderer's line clipping. You need to be able to move a model past the left or right edge of the framebuffer to see the effect of clipping.

According to the Model-View-Controller design pattern, the event handlers are part of the Controller and their job is to update variables in the Model. The Model, in this program, is the collection of instance variables at the beginning of the Hw3 class. In particular, notice that the scene object is part of the Model. After the Controller updates the Model, the View is supposed to take over and update the GUI. In this assignment, the View is the method updateGUI(). So most of the event handlers should update some Hw3 instance variable and then end with a call to updateGUI(). But not all of the event handlers fall into this pattern. For example, the "Information" button does not really have any affect on the Model or the appearance of the GUI. It just prints the scene object to the console window. So the "Information" button can be thought of as not being part of the MVC pattern. What other event handlers are not really part of the MVC pattern?

The event handler for the combo box of model names is written for you in the "Hw3.java" file. It is written in the style of an "anonymous inner class". There are several styles of code for event handlers (nested classes, inner classes, anonymous inner classes, etc.). See, for example, the programs in the "clients_r2" folder from renderer_2.zip, or the "how_to_handle_handlers" folder from JavaGuiEvents.zip. You can write your event handlers in any of these styles.

Remember, do NOT try to write all the code for this program and then start to debug it. That will not work. First get all the GUI components in the right place (without any event handlers). Then get one event handler at a time working. Writing event handlers is not easy. Debugging multiple event handlers at once is extremely difficult and foolish since you don't have to write your code that way.

You should not change the package structure of the hw3 folder. The files Hw3.java and ModelList.java are in the default package of the folder hw3. Do not give those classes a package statement. All the renderer classes are in the renderer_2.jar jar file. The included build script, build_&_run_client.cmd, sets the classpath appropriately.

Turn in a zip file called CS455Hw3Surname.zip (where Surname is your last name) containing Hw3.java, ModelList.java, and any other files that you created as part of your solution. Please submit a clean, professional, distribution of your project. If you force me to go through your files and keep what's needed and delete what isn't, I may just delete the whole project and not grade it.

This assignment is due Friday, November 20.

Here are references to relevant classes in the Java API.