Reference: Printing and 2D Graphics links on class page.
Modify the program of the previous assignments to allow the user to:
(1) pop up a print dialog that allows the user to print the picture, and
(2) drag a drawing object to a new position.
(1) Add a "Print" menu item to the "File" menu that pops up a print dialog. Here is the code for the HelloWorldPrinter program file, which has an example of popping up a printer dialog.
(2) To drag an object in the drawing area, you first select it by clicking down in its bounding rectangle, and then drag it around by holding the mouse key down (releasing the key stops the dragging). Here is the code for the SwingShapeMover program file, which has an example of (double buffered) dragging. Here is a version of the program that doesn't do double buffering (Swing does it automatically): ShapeMover program file . You should have another icon on the toolbar to initiate this. Often an arrow pointing up to the left is used as a "selection" icon (Acrobat Reader uses a hand icon). After clicking on this "drag" icon, click on one of your objects to generate a "mouse pressed" event. To identify which object was clicked on, iterate through your list of objects until the bounding rectangle of the object contains the "click point" (actually you should iterate backward through the list - why??). After that, while the mouse button is down, get "mouse dragged" events and update the position of the object (you might have to redraw all the objects either on each "mouse dragged" event or when you are done dragging).
Some applications have two toolbars: a "general" toolbar across the top to perform general operations such as printing, selection, cut, copy, paste, etc., and an application-specific toolbar down the left side (to choose shapes and colors in our case). This isn't required, just something to think about.
What to turn in:
Turn in the following items from the
Computer Science Lab Report Format:
1. (1 point) The Basic Information (your name, class, section, TA's name, assignment number, and date) can be on a separate cover sheet or as (highlighted) comments at the top of your main program file.
11. (5 points) Include the program listings. This listing should show good style, be appropriately commented, have the important/new parts highlighted, and include handwritten explanations if it helps the reader's understanding of the code.
13./14. (9 points) Do a demo of your modified program for the TA that demonstrates that the program works correctly.