Objectives

In this lab you will work with a few of the basic graphics programming methods of the Graphics2D class in the Java Abstract Windows Toolkit (AWT).

Preparation

  • Set up a new eclipse project for each lab (detailed instructions)
    • Copy the files DrawingPanel.java, BoxGuy.java into your lab3 project folder.  To copy files, right click on the link and save the file to the desktop. (On a Mac you may need to use Crtl-click.) After saving to the desktop you can drag it into the lab3 project. Alternatively, just clicking on the link, highlighting the entire text and copying the program (Ctrl-c or command-c on Macs).  Then just paste it into your lab3 project by right clicking on the lab3 project and pasting (Ctrl-v or command-v on Macs)   (If the word "snippet" arises at any time, you did it wrong ... delete that and try again)

Exercise 1: (4 points)

Run the BoxGuy program to make sure it works. This program illustrates a few of the functions available in the Graphics2D class. Programs using the Drawing Panel stay running until you close the pop up Drawing Panel window, so try to remember to close the Drawing Panel each time before running your program again.  It will get confusing if you leave several versions of your program running. Basic documentation about the DrawingPanel and Graphics2D class can be found at: http://www.cs.usm.maine.edu/~boothe/cos160/UsingJavaGraphics.pdf and Comprehensive documentation about Graphics2D can be found at: https://docs.oracle.com/javase/7/docs/api/index.html?java/awt/Graphics2D.html

Look over the BoxGuy program and make sure you understand it. You are going to be making a few small changes. Below are the changes that you need to make. Make each change one at a time and test it and make sure you understand it before moving on.

  • Change the background color
  • Change the eyes to white
  • Add small round black pupils to the eyes
  • Change the word the box guy says

Screen capture your final drawing panel and paste it into your solutions document. 

On a Mac,

  • command-shift-4 key initiates the capture
  • click on one corner of the image and drag to the other diagonal corner.
  • You will likely find the file with the image on the desktop.

In Windows this can be done by:

  • Selecting the window you want to capture.
  • Hit Alt-PrintScreen to capture an image of your window to the clipboard.
  • Switch into your editor and paste it with Ctrl-V.

Also paste your final program into your solutions document.

Exercise 2: (3 points)

We take inspiration from the Pyramid of Djoser (a few artist liberties) to motivate us to produce an image that looks like :

Step Pyramid


Create a new Java class called StepPyramid in your lab3 project and, using the example code from step 1 as a guide, develop a Java program that produces an image similar to the above (you can exercise a few artistic liberties of your own).

Create a screen capture and put it in your solutions document and include your code as well.

Exercise 3: (3 points)

Make a copy of the StepPyramid code. Right click on the StepPyramid.java file and select the copy option. Next, right click on the default package and select paste. It will ask for a new name and you should type RedSnowMan. Modify the RedSnowMan code to produce :

 Red SnowMan

Include a screen snapshot in your solutions document (code not necessary)

Exercise 4: Extra Credit (2 Points)

Draw the Box Guy a hat of your own design.

Include a screenshot and your code in the solutions document.

YOU ARE DONE!

Save this document document to your USB flash drive, and submit it through Brightspace.