import java.awt.*; import java.applet.*; import java.util.*; class Location { int x; int y; Location(int x, int y) { this.x = x; this.y = y; } } public class BubbleWrap extends java.applet.Applet { Image wrap; Graphics osg; Image bubble; Image popped; MediaTracker t; AudioClip pop; AudioClip yahoo; Location cell; Vector cells; int counter; Font cf; Font tf; Color purp; Color gren; void makewrap() { counter = 300; osg.clearRect(0,0,this.size().width,this.size().height-20); osg.setColor(new Color(51,0,204)); osg.fillRect(0,0,this.size().width,this.size().height-20); for (int y = 0; y <= this.size().height - 20; y += 20) { for (int x = 0; x <= this.size().width; x += 20) { cell = new Location(x,y); cells.addElement(cell); osg.drawImage(bubble,x,y,this); } } repaint(); } public void init() { cf = new Font("Courier", Font.BOLD + Font.ITALIC, 30); tf = new Font("TimesRoman",Font.BOLD + Font.ITALIC, 20); purp = new Color(182,57,204); gren = new Color(85,176,99); cells = new Vector(); pop = getAudioClip(getDocumentBase(), "pop.html"); yahoo = getAudioClip(getDocumentBase(), "yahoo.html"); t = new MediaTracker(this); wrap = createImage(this.size().width, this.size().height - 60); osg = wrap.getGraphics(); osg.setColor(new Color(51,0,204)); osg.fillRect(0,0,this.size().width, this.size().height - 60); bubble = getImage(getDocumentBase(), "booble.html"); popped = getImage(getDocumentBase(), "pped.html"); t.addImage(bubble, 0); t.addImage(popped, 0); try { t.waitForAll(); } catch (InterruptedException e) {} makewrap(); } public boolean mouseDown(Event e, int x, int y) { y -= 60; int tempx = x % 20; int realx = x - tempx; int tempy = y % 20; int realy = y - tempy; loop: for (int i = 0; i < cells.size(); i++) { Location temp = (Location)cells.elementAt(i); if (temp.x == realx) { if (temp.y == realy) { cells.removeElementAt(i); osg.drawImage(popped,realx,realy,this); counter--; repaint(); pop.play(); if (counter == 0) { try { Thread.sleep(1000); } catch (InterruptedException exc) {} yahoo.play(); makewrap(); } break loop; } } } return true; } public void paint(Graphics g) { g.setColor(purp); g.setFont(cf); g.drawString("Virtual Bubble Wrap!!", 10, 40); g.setColor(gren); g.setFont(tf); g.drawString("Bubbles Left: " + counter, 400, 40); g.drawImage(wrap,0,60,this); } }