CSE 115 - Spring 2010 - Banner
UB -
University at Buffalo, The State University of New York Computer Science and Engineering
  • CSE 115 - Spring 2010
CSE 115 - Spring 2010 - Navigation
CSE 115 - Spring 2010 - Announcements

Lab 4

CSE 115 - Spring 2010 - 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

You can find information about the graphics library and functionality available in it here (this is linked from the Course Resources page as well).

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 current color of a square on the screen to be a random color.
  • Create a blue rectangle on the screen.
  • Create a red circle 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).
  4. When the program loads, the drawing canvas should have one white square on the screen (size and location of square up to you).
  5. The change color button must change the color of the square on the screen to be a random color each time it is pushed.
  6. The create blue rectangle button creates a blue rectangle with a random dimension with values for width and height between
    20 and 100, but the location of the rectangle is always (100, 36) each time it is pushed.
  7. The create red circle button creates a red circle with diameter of 56 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. The entire lab work will be due the day before your recitation meets the week of March 1st. For your reference, consult the table below for due dates.

Recitation Lab 4 due
A6 Sunday, February 28th at 11:00pm
A1 Monday, March 1st at 11:00pm
A2 & A5 Tuesday, March 2nd at 11:00pm
A3 Wednesday, March 3rd at 11:00pm
A4 Thursday, March 4th at 11:00pm

 


CSE 115 - Spring 2010 - Footer

Page maintained by Adrienne Decker

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