Computer Science 252
Problem Solving with Java

Fall 2014, The College of Saint Rose

Lab 4: Bubble Blower
Due: 11:59 PM, Wednesday, October 8, 2014

This week's lab will give you your first experience with ActiveObjects and animation by implementing a bubble blowing simulation.

You may work alone or with a partner on this lab. There is no formal design document to be graded this week, but you are strongly encouraged to begin, as usual, with pencil and paper sketching out a plan before you start coding.

Problem Description

The program begins with a message displayed centered on the canvas. When you press the mouse on the canvas, the message disappears and a bubble begins to grow, centered at the mouse press point. When you release the mouse, the bubble is free to float about the canvas until it pops.

A working solution for this program will appear below. Click inside the applet to interact with it.

Your program should include two Java classes. BubbleBlower is an extension of WindowController that manages the mouse events to create new bubbles and to tell existing bubbles when it's time to stop growing and start floating around. The Bubble class is an extension of ActiveObject that manages one bubble throughout its lifetime: creation, growth, floating, and popping.

In many ways, this example is similar to ones we have seen in class. One difference here is that you need to create your ActiveObject in response to one mouse event, but then modify its behavior in response to another. This means your WindowController will need to remember the bubble it created when you pressed the mouse (at which point it automatically starts to grow on its own - it is an ActiveObject after all), and send it a message to tell it to stop growing. Sending a message is straightforward enough: that's just a method call. The other task is to organize your loop (or, hint, loops) in your Bubble's run method to grow the bubble from the time it is created until the time it receives the message to stop growing, then to have it float around on the canvas for a while, then finally to pop and disappear.

The specifics of how quickly your bubbles grow and how they float are not that important, but strive to make them look nice and to give it as much of a feel for how real bubbles float around as you can. Avoid having your bubbles fly too quickly off the canvas so we can observe them a bit. The solution above has the bubbles change velocity randomly in both the x and y directions, but with a slight preference for "up" rather then "down." Bubbles should float around for several seconds before they pop. Hopefully you can make something that looks a little nicer than the demo.

Grading Note: There will be an extra emphasis on the use of named constants where appropriate, good variable names, declaring variables vs. local variables, and good commenting.

There are no specific extra credit tasks, but you may feel free to propose your own, for up to a total of 2 points.


Before 11:59 PM, Wednesday, October 8, 2014, submit your lab for grading. There are two things you need to do to complete the submission: (i) Upload a copy of your lab (a .7z or .zip file containing your project directory) using Submission Box under assignment "Lab4". (ii) Demonstrate the execution of your programs for your instructor. (2 business day grace period for demos).


This assignment is worth 60 points, which are distributed as follows:

> FeatureValueScore
Style, Design, and Efficiency
Appropriate comments 5
Good variable names 3
Appropriate variable declarations 6
Good use of constants 6
Appropriate formatting 1
Efficiency/Does not generate new objects unnecessarily 2
Good overall design and methods 4
Program Requirements
Instructions displayed, centered, removed 3
Bubble begins growing on press 6
Bubble drawn centered on press point 5
Bubble grows symmetrically around the point 5
Growth stops when mouse released 6
Bubbles move around realistically 4
Bubbles disappear after a while 4
Extra Credit
Come up with your ideas! 2
Total 60