CS116      Lab 5 - Drawing

Objectives:

  1. Before starting this lab you should have read chapter 7 in your text.
     
  2. Open Eclipse and import the cs116 project. 
     
  3. There are many useful classes that are part of the Java API which we can use to manipulate pictures.  Take a look at the documentation for the Java API http://phoenix.goucher.edu/j2sdk-1_4_2/api/
    Take a look at the listing for the Graphics class and notice all the drawing methods that are provided.

    Suppose we are writing a method in the Picture class.  We can use these methods with code like:

    Graphics g = this.getGraphics();
    g.setColor(Color.red);
    g.drawRect(100,100,50,50);


    This code will draw a red rectangle on the picture.
     

  4.  

    Assignment:
    Write a program which draws glasses on a person who does not normally wear glasses.
    Add a caption horizontally centered on the bottom of your picture using the drawString method.
    Hint: Look at code on p226 for centering text


     

  5. More advanced drawing techniques can be achieved with the Graphics2D class.  The Graphics2D class is a subclass of the Graphics class -- it inherits everything from the Graphics class plus has more stuff.  Look at the documentation for that class and feel free to try out a few methods.  Many of these are described in your text as well.
     

  6.  

    Assignment:
    Picture collage redux.
    Now that we have completed the section on the text on Pictures, use all your knowledge to generate another picture collage.  Your collage MUST include some use of the Graphics or Graphics2D classes but other than that feel free to be as creative as you want!


     

  7. Email your modified code and resulting pictures to me at jill.zimmerman@goucher.edu