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

Lab 4

Introduction

We have learned about how to communicate with an object multiple times by using an instance variable. We have also explored the realization relationship and create a class that implements an interface. We will use these ideas to see how we can create our very own button on our Applet that will react when we click upon it.

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 realization relationship in code (i.e. you will write a class which implements a given 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:
  • realization
  • declaring instance variables
  • defining methods
  • calling methods

Assignment Specifications

For this program, the user will be in charge 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 a button that when clicked upon, will create an instance of an image on the Applet itself. 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 three types of images that you can create are:

lab4lib.Breakout

lab4lib.Earth

lab4lib.Elephant

Your job is to have your button create ONE of these three types of images. After you have completed that first button, 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 3 and the beginning of 4 of the book before coming to lab. Also make sure you have reviewed your lecture notes.


Lab set-up tasks (If you are working at home see these directions for this lab)

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. Before you start work on the lab itself, you must carry out each of the following set-up tasks. Your teaching assistant will guide you through this process. Refer back to other lab assignments if you do not remember how to complete these tasks.

Step 1: Log in

Step 2: Start Eclipse

Step 3: Check out Lab4 project from LabSkeletons repository

Step 4: Begin work on your assignment 


Lab Design

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. When running this lab, you should set your size preferences to 575 wide by 500 tall to see the entirety of the Applet. If you do not remember how to do this, refer back to Lab 3.

In short, the Applet class provided for you will use an instance of a top-level object. This top-level object will create an instance of a lab4lib.Button. You will need to create a class that implements java.awt.event.ActionListener and implement the actionPerformed method. Inside that method is where you will write the code that is to be executed each time the button is clicked.

For some additional help, you should be sure to check out all of the Javadocs for the Classlibs.jar, located here.

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 write the part of the code so that Applet uses the instance of the top-level object first, then run it.  Then, create an instance of the button which will position itself automatically on the Applet. Then you should create the class that implements the ActionListener interface and hook up the button to the listener. Then, write the code that will run when the button is clicked. After all of that, you are strongly encouraged to try it again with another button that performs a slightly different action.


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.

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 earlier labs.


Due dates

You have one week from the meeting of your lab to submit your solution.  The due dates are summarized in the table below. You are always welcome to submit early. If you submit more than once, the later submission will simply overwrite the previous one.

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 13 Monday, February 19
Wednesday, February 14 Tuesday, February 20
Thursday, February 15 Wednesday, February 21
Friday, February 16 Thursday, February 22

 

CSE 115 - Spring 2007 - Footer

 

 
Last modified: Sun Feb 11 15:59:18 2007
© Adrienne Decker