157 Lab - RandomBoxes
157 Lab - RandomBoxes

Assigned partners for today are...
  • Alex and Joe
  • Beau and Drew
  • Mads and Calid
  • Mikayla and Jeremy
  • Jake and Robin
  • Matt and Toya
  • Jennifer and Will
  • Zosimo and Hailey
  • Amanda and Shomari

Partner names to the left type first. Your team will work only on this person's account today. I will tell you when to switch to the second partner typing. The second partner should not be logged into any machine today.

Put as much space as you reasonably can between yours and the other teams.


As we did last week, you will work in teams of two.

To remind you of the rules:

In team programming, a pair of programmers works side-by-side, collaborating on the same design and code. One programmer, the driver, has control of the keyboard/mouse and actively implements the program. Only the current driver may use the keyboard/mouse. The other programmer, the observer, continuously observes the work of the driver to identify tactical (syntactic, spelling, etc.) defects and also thinks strategically about the direction of the work. The reason you are working in teams is not to "divide the work" but rather to work in close collaboration with one another. Therefore, the observer may not use any keyboard or mouse until their turn comes to drive.

As necessary, the two programmers can brainstorm any challenging problem. Because the two programmers periodically switch roles, they work together as equals to develop software.

Both team members should understand the code they are working on together!

You and your partner will work at a single machine with one of you doing the driving and the other observing. Situate yourselves in the room so that there's lots of space between teams. This means no two teams are trying to use adjacent computers.


The first person will drive through Part I of the assignment below. Only after you have completed all of Part I will you switch roles and begin Part II.

  1. Create a CLIENT called RandomBoxClient with the following features:

    • When the program begins, it creates a filled rectangle of random size with rounded corners (make your limits for both width and height be 40-240 pixels) centered on the screen

      See your online documentation for how to construct rounded corner boxes.

    • When the mouse is clicked anywhere inside the colored box, the terminal command line console reports the dimensions and location (location of upper left corner is fine ) of the rounded box *AND* so does the canvas window. In the example image, you see the canvas report in the lower left corner of the window.

    • When the mouse exits the window, the box and any other information disappears

    • When the mouse re-enters the window, it generates a new size (both width & height) for the rounded box and re-centers it on the screen

  2. Modify the above so that it

    • generates a random color in addition to the random size for the rounded box. Make sure your rounded box has a frame so that it can easily be seen even if it is given a very light color.

    • only the red and blue color components are reported in the terminal console while on the canvas all red, green and blue color components are reported. Your text on the canvas should never overlap your rectangle.

      The content and formatting of all informative strings is required for both canvas display and terminal display. If you need to discuss/review System.out.printf, let me know.

      (Hint: The Color class has accessor methods that you may find useful.)