CSE 115 - Spring 2008 - Banner
   CSE 115 - Spring 2008 - Introduction to Computer Science for Majors I
CSE 115 - Spring 2008 - Navigation CSE 115 - Spring 2008 - Lab 4

Lab 4

Introduction

We have now learned how to model some more relationships between classes, those that use instance variables. We will use at least one of the new relationships and some of the old relationships to get a deeper understanding of creating our own graphics programs.

Note: The clip art images used in this lab assignment were downloaded from http://www.allfreeclipart.com/


Objectives

The high-level objectives of this lab are to have you,
  • declare instance variables
  • call methods on objects using an instance variable
  • express the association relationship
  • create a button that will react with the user clicks upon it
  • implement a design which is provided to you in the form of a UML diagram.
The following are the new concepts covered in this lab:
  • association
  • declaring instance variables
  • defining methods

Assignment Specifications

For this program, the user will be in charge of some of the look and feel of the program after they run it. Your job as the programmer is to provide a program that will allow the user this control. Most often, control of a program is given to the user through the use of graphical widgets. These widgets are things within the program that the user can use to manipulate the program. In this program, we will provide the user with two buttons. The first button, when clicked upon, will create an instance of an image on the window itself. The second button when clicked upon, will manipulate a property of the lab3lib.BouncingBall that we will place on the screen for them when the program first starts. There are many other types of widgets and in the upcoming labs, we will see how to use other types to help the user interact with our programs.

The first button can create one of three types of images:

lab4lib.Breakout

lab4lib.Earth

lab4lib.Elephant

Your job is to have your button create ONE of these three types of images.

 

The second button will manipulate a lab3lib.BouncingBall and change one of its properties. See Javadocs for which properties can be changed.

After you have completed the two required buttons, you are MOST STRONGLY ENCOURAGED to create another button on your own that creates one or more of these three types of images.


Helpful Hints

Read through the entire lab before you start working, so that you know what to expect. Make sure you save your work often, and keep track of what you are expected to submit.

Do not be afraid to refer to earlier labs to recall what things mean or what commands are available for you to use.


Reading

Make sure you have read chapter 4 of the book before coming to lab. Also make sure you have reviewed your lecture notes.


Lab set-up tasks

At your lab session your teaching assistant will briefly discuss how to carry out each of the set-up tasks below. She or he will also be available to answer questions you might have.

These are things that you must do that you learned how to do in previous labs. If you don't remember how to do any of these tasks, refer to Lab 1.

Step 1: Log in

Step 2: Open Eclipse

Step 3: Make sure you have the DrJava interactions pane visible

Step 4: Make sure you can see the connections to the code repositories

These are things that you must do that you learned how to do in previous labs. If you don't remember how to do any of these tasks, refer to Lab 2.

Step 5: Check out Lab4 project from LabSkeletons repository


Lab Assignment (To be completed in Lab and handed in to TA for attendance)

Your TA will have a handout that is a print out of a Java source code file. Your job is to circle and identify using the number from the list below, each of the following elements from that code (one example ONLY).

  1. package declaration
  2. class definition begin
  3. class definition end
  4. class header
  5. name of class
  6. access control modifier
  7. constructor definition
  8. parameter list
  9. method call
  10. code that creates a new instance of an object
  11. local variable name
  12. assignment statement
  13. non-constructor method definition
  14. instance variable declaration

Once you have completed this task, make sure to give your completed paper to the TA because successful completion of the assignment will count as your attendance this week. Yes, that means your answers will be graded.


Lab Assignment (To be turned in by due date)

This time in lab, the TAs will help you to develop the appropriate class diagram for this assignment in recitation (with your help!). Your submitted lab must implement the UML class diagram discussed in recitation.

In short, you will be putting various pre-defined pieces together to create the finished product. There is a lab4lib.WindowWithButtons object that will allow you to add buttons and graphics to it. You will create two instances of a javax.swing.JButton. You will create an instance of the lab3lib.BouncingBall and you will copy and modify the class given in theLab 4 skeleton called ButtonListener to help you do what you need to do for this lab.

Build up the Code Incrementally

As we said in the last lab, it is important to build your code in small stages until you get to the finished product.  You should first create a class that will represent what we would call a top-level object. This is the object that is "in charge" of all of the others and sets up basically how the program parts interact with each other. This top-level object should create an instance of the lab4lib.WindowWithButtons. Once you have written that code, create an instance of your top level object in the DrJava interactions pane. Then, add the code to add a lab3lib.BouncingBall to the screen (stop and run to see that you were correct). Then, write the code to add the first button to the screen (stop and run to see if you were correct). Write the code to add the second button to the screen (stop and run to see that you were correct). Now, fill in the code for the ButtonListener so that it creates an instance of an image when the user clicks upon it. Make sure to tell the button you created who its action listener is and then stop and run. Finally, write the code to manipulate the ball and run it again.

As stated before, if you are done with all of these, attempt to add another button to the screen that does something else to get used to the idea of how buttons and listeners work.


What you hand in

When you are finished, you need to export your solution from the Eclipse environment so that you can submit it.  You need to follow the same steps as you did for disconnecting from the repository and exporting as you did in Lab 2.  If you are not sure how to do this, please refer back to those instructions.  This time, you should name your Jar file Lab4.jar. Your Jar file should include your source code as well as a UML diagram of your submission named Lab4.grn.

Then you can submit the Lab4.jar file using the electronic submission program.  If you do not remember how to use the the submission program, refer back to Lab 2.


Due dates

Due dates are summarized in the table below.

To check that your lab was submitted, you can always refer back to the Submit Inspector on the Resources page of the website. After you have entered your user name, your submissions will be shown. Clicking on the name of a file that is a zip file will show you the contents of the zip file so you can verify that you indeed zipped up all the correct files.

Date of lab Due date for electronic submission
Tuesday, February 12 Monday, February 18
Wednesday, February 13 Tuesday, February 19
Thursday, February 14 Wednesday, February 20
Friday, February 15 Thursday, February 21

 

CSE 115 - Spring 2008 - Footer

 

 
Page Maintained by: Adrienne Decker