/* ***************************************************************** Homework #6 Author: Butler, Martin Date: 2004.12.02 Due: 2004.12.09 CMPT 505 ***************************************************************** */ import java.awt.*; import javax.swing.*; import java.util.*; import java.awt.event.*; public class CanvasPanel extends JPanel { boolean [] exists; // display toogle for circle. int [] size; // store random size of circle. int [] speed; // store random speed of circle movement. int [] xPos; // circle x coordinate int [] yPos; // circle y coordinate int [] xDirection; // store random value for x coordinate movement. int [] yDirection; // store random value for y coordinate movement. boolean [] clearBubble; // for clearing bubble from panel. int maxBubble; // max number of concurrent circles. int width = 0; // store the width of panel. int height = 0; // store the height of panel. int totBubbles = 0; // track number of circles created. int totHit = 0; // track number of circles pressed by mouse boolean gameOver = false; boolean gameStarted = false; boolean goodbye = false; public CanvasPanel (int max) { // ************************************************************* // initilization. build all arrays with max number passed in. // add mouse listener // ************************************************************* System.out.println ("canvas panel constructed"); maxBubble = max; exists = new boolean [maxBubble]; size = new int[maxBubble]; speed = new int[maxBubble]; xPos = new int[maxBubble]; yPos = new int[maxBubble]; xDirection = new int[maxBubble]; yDirection = new int[maxBubble]; clearBubble = new boolean [maxBubble]; for (int n =0; n= move) { xPos[n] += xDirection[n]; yPos[n] += yDirection[n]; if (((xPos[n] + size[n]) < 0) || ((xPos[n] - size[n]) > height) || ((yPos[n] + size[n]) < 0) || ((yPos[n] - size[n]) > width)) { System.out.println("Bubble off screen:x="+xPos[n]+" y="+yPos[n]+" size="+size[n]); xPos[n] = -100; yPos[n] = -100; size[n] = 0; clearBubble[n] = true; } } } } } public void paint (Graphics g) { System.out.println ("paint method called for canvas"); for (int n=0;n