CSE 115/503 - Spring 2011 - Banner
  • CSE 115/503 - Spring 2011
CSE 115/503 - Spring 2011 - Navigation
CSE 115/503 - Spring 2011 - Lab 4

Lab 4
Last modified: February 20 2011 02:44:01 PM

CSE 115/503 - Spring 2011 - Lab 4

Introduction

You will be using some of the knowledge you have about graphics to create finish the code of a program that has already been started. You will also learn in recitation this week how to create the Java code so that your program does not need the DrJava interactions pane to run.


Objectives

We will concentrate on the following ideas that were discussed in class:

  • Creating objects
  • Calling methods
  • Using variables that hold references to objects
  • Creating a class definition
  • Defining a constructor
  • Creating your own Java graphics objects
  • Writing a method that is not a constructor
  • Instance Variables

Lab Tasks

  • Log in
  • Start Eclipse
  • Check out the SP2011-CSE115-Lab4 project from the Labs repository

You can find information about the graphics library and functionality available in it here.

You are creating a program that when run opens a window that allows the user to draw a limited set of graphics to the screen. The window will have four user controls (buttons) that will allow the user to do the following things:

  • Change the location of a circle on the screen to a random location.
  • Create a green circle on the screen.
  • Create a yellow rectangle on the screen.
  • Create a new square on the screen.

You will find that some of the code already written for you when you download the lab skeleton. Please take note of the fact that some of the code you have been given should not be modified, while other parts most certainly need to be modified to complete the tasks of the lab.

  1. Keep in mind the following requirements:
  2. There must be a JFrame used in your program.
  3. The program must have a drawing canvas on the frame (color: black, size 400x400). Note that this object must be created in the Drawing class and assigned to the instance variable declared in that class.
  4. When the program loads, the drawing canvas should have one circle on the screen (size, location, and color are up to you).
  5. The change location button must change the location of the circle on the screen to be a random location each time it is pushed.
  6. The create yellow rectangle button creates a yellow rectangle with a random dimension with values for width and height between
    20 and 150, but the location of the rectangle is always (55, 62) each time it is pushed.
  7. The create green circle button creates a green circle with diameter of 45 at a random location on the screen each time it is pushed.
  8. The create square button creates a square with random side length, positioned randomly on the screen, with a random color each time it is pushed.

 

The files you download are already set to create a stand-alone program. To run the program, select the App class in the package explorer, right click and select "Run As -> Java Application". You will not need to use the DrJava window for this assignment.


Due dates

You will submit your Lab 4 assignment using the Web-CAT submission plugin from Eclipse. (At this time, the grading is not enabled for this assignment, so EVERYONE will receive a zero when submitting the assignment.) The entire lab work will be due the day before your recitation meets the week of February 28th. For your reference, consult the table below for due dates.

Recitation Due Date
A1 Monday, February 28th at 9:00pm
A2 & A5 Tuesday, March 1st at 9:00pm
A3 & A6 Wednesday, March 2nd at 9:00pm
A4 Thursday, March 3rd at 9:00pm

CSE 115/503 - Spring 2011 - Footer

Page maintained by Adrienne Decker

Contact: adrienne@buffalo.edu | 130 Bell Hall | (716)645-3184