CS 101 - Intro to Computing, Fall 2009

Lab 6

Lab Assignment

Due: Thursday 2/25/2010 by 11:59 pm

For this lab assignment, complete the following:

  1. Prompt the user for an picture and open that picture. Once the picture has been opened, add a simple text message to the bottom left side of the picture. Then prompt the user for a filename to save the modified picture and save the picture in that file. You should use the pickAFile() method from the FileChooser class to prompt the user for the picture and for the filename to same the modified image.

    To add the text message, use the addMessage () method of the Picture class. This method takes 3 parameters:

    1. message - The text message to the added to the picture.
    2. xpos - the pixel position of the left side of the string
    3. ypos - the pixel position of the bottom of the string

    We want the text to be on the bottom left side of the picture. Let us put it 20 pixels over the left edge of the the picture and 20 pixels above the bottom edge of the picture. The xpos value is simple, that will be 20. However, we must calculate the ypos value.

    Fortunately, the Picture class has a method getWidth() method and a getHeight() method. Each of these return the distance in pixels across the width (which is the X direction) or the height (which is the Y direction) of the picture. The coordinate position of (0,0) is in the upper left corner of the picture.

    Thus to calculate the value for the ypos for the addMessage() method, we need to subtract 20 from the height of the picture.

    The message that you put in the picture can really be anything you want. If you can't think of anything interesting, just put "CS 101 - Lab 6" followed by your name. This sort of idea is normally used to add a caption to a picture or to add a copyright statement. Note: you should only be adding copyright statements to pictures that you took/created yourself.

    The following is an example a before and after picture:

  2. Be sure to change comment with the name of the author to contain the following:

  3. You are also to submit the Java file electronically via the following steps:

    How assignments should be submitted

    1. Go to the blackboard site for the class
    2. Select "Assignments" on the left bar
    3. Locate the correct assignment to submit; click on "View/Complete Assignment" at the bottom of that assignment
    4. Next to "Attach local file", click "Choose file", choose the file you want to submit; please submit only ONE file, properly named.
      For example for lab2, name it Lab2yournetid.java, for example if your Net ID is sfranz3, the filename would be Lab2sfranz3.java
      Please only submit source code file (the .java file, not the .class). Also, if you have any comment about your program, please write it down in the same file; please do NOT write in the "Comments" field on the submission page (this will go into a different file and will be easily missed).
    5. Hit "Submit"
    6. Go back once again to View/Complete assignment and make sure that your file was submitted; also, this page will show your grade and comments (if any) after assignments are graded.