This assignment makes use of the files contained in this zip file. This assignment is due Wednesday, March 2.
This assignment is based on the Java GUI program that we wrote in class over the last couple of weeks.
In the hw2
zip file there is a demo program, Hw2_demo.jar
that you can run by either double clicking directly on the jar file or by double clicking on the Hw2_demo.cmd
file. Your assignment is to write a program Hw2.java
that does everything that the demo program does.
The demo program adds several features to the program that we wrote in class. There is a JComboBox for selecting a drawing color. There is a ButtonGroup
of JRadioButtons for selecting a background color. There is a JCheckBox
that makes the program window non-resizable.
Notice that the three radio buttons have short-cut keys assignment to them. You use the short-cut keys along with the Alt-key (i.e., Alt-1, Alt-2 and Alt-3).
The controls along the bottom of the screen are in a JPanel
container just like the controls along the top of the screen.
Notice that in this program, the drawing circle is the same color as the trail that it draws. When you select a color from the combo box, the drawing circle changes color immediately and then draws in the selected color. The drawing circle (that you click on) is actually a white disk with a color ring around it. This makes it easier to see where you need to click.
An important change in this program from the one we wrote in class is that when you resize this program's window, this program keeps its drawing at the center of the graphics panel. To accomplish this, you need to do two things. First, you need a ComponentListener that responds to window resizing events. Second, the state information about the circle's trail needs to be relative to the center of the screen. When the graphics panel redraws all the circles stored in the trail, each circle's coordinates should be relative to the center of the screen. Another way to put this is that instead of storing in the trail the absolute coordinates of a circle, you should store the circle's "delta x" and delta y" from the current window's center. Then, when the window gets resized and has a different center coordinate, the circles can be drawn relative to that new center.
Notice that in the bottom panel there is a check box for debugging output. When this is checked, your program should write to stdout the contents of the trail list. You should implement this before you try to add the resizing feature. Being able to see what is in the history list can help you debug the change of coordinates the resizing feature needs. Also, give the DotState
class a toString()
method and use it to help you print out the trail list.
To do this assignment, start with the code that we wrote in class. Then add just one new feature at a time. You will need to write a lot of (short) event handlers (my version has a total of 14 event handlers, about half of them from the code we wrote in class).
Turn in a zip file called CS51580Hw2Surname.zip
(where Surname
is your last name) containing your version of Hw2.java
and all the supporting classes that complete your program and make it run.
This assignment is due Wednesday, March 2.