home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.applet.AudioClip;
- import java.awt.Component;
- import java.awt.Event;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.MediaTracker;
- import java.net.MalformedURLException;
- import java.net.URL;
-
- public class LoopSound extends Applet implements Runnable {
- MediaTracker tracker;
- boolean inited = false;
- Thread tickTock;
- AudioClip theSound;
- int soundOnOrOff;
- Image soundOnImage;
- Image soundOffImage;
- boolean mouseOut = true;
- boolean mouseIsDown = false;
- boolean notUpdatedYet = true;
-
- public String getAppletInfo() {
- return new String("LoopSound 1.0 (c) J. Criswick - criswick@conveyor.com, Mar.25.96");
- }
-
- public void init() {
- this.tracker = new MediaTracker(this);
- String var6 = ((Applet)this).getParameter("on-icon");
- String var1 = var6 == null ? "sound-on.gif" : var6;
- var6 = ((Applet)this).getParameter("off-icon");
- String var2 = var6 == null ? "sound-off.gif" : var6;
- var6 = ((Applet)this).getParameter("volume");
- this.soundOnOrOff = var6 == null ? 1 : Integer.valueOf(var6);
- if (this.soundOnOrOff != 0 && this.soundOnOrOff != 1) {
- this.soundOnOrOff = 1;
- }
-
- var6 = ((Applet)this).getParameter("sound");
- URL var3 = null;
- URL var4 = null;
- Object var5 = null;
-
- try {
- var3 = this.MakeAbsoluteURL(var1);
- var4 = this.MakeAbsoluteURL(var2);
- this.MakeAbsoluteURL(var6);
- } catch (Exception var11) {
- System.out.println("A problem occurred with one of the URLs.");
- }
-
- if (var4 != null) {
- try {
- this.soundOffImage = ((Applet)this).getImage(var4);
- this.tracker.addImage(this.soundOffImage, 0);
- this.tracker.waitForID(0);
- } catch (InterruptedException var10) {
- System.out.println("A problem occurred in loading the on image");
- }
- }
-
- if (var3 != null) {
- try {
- this.soundOnImage = ((Applet)this).getImage(var3);
- this.tracker.addImage(this.soundOnImage, 1);
- this.tracker.waitForID(1);
- } catch (InterruptedException var9) {
- System.out.println("A problem occurred in loading the on image");
- }
- }
-
- var6 = ((Applet)this).getParameter("width");
- int var7 = var6 == null ? 32 : Integer.valueOf(var6);
- var6 = ((Applet)this).getParameter("height");
- int var8 = var6 == null ? 32 : Integer.valueOf(var6);
- ((Applet)this).resize(var7, var8);
- }
-
- private URL MakeAbsoluteURL(String var1) throws MalformedURLException {
- URL var2;
- try {
- var2 = new URL(var1);
- } catch (MalformedURLException var3) {
- var2 = new URL(((Applet)this).getDocumentBase(), var1);
- }
-
- return var2;
- }
-
- public void paint(Graphics var1) {
- if (this.soundOnOrOff == 0) {
- if (this.tracker.checkID(0)) {
- var1.drawImage(this.soundOffImage, 0, 0, this);
- return;
- }
- } else if (this.tracker.checkID(1)) {
- var1.drawImage(this.soundOnImage, 0, 0, this);
- }
-
- }
-
- public boolean mouseMove(Event var1, int var2, int var3) {
- if (this.notUpdatedYet) {
- this.notUpdatedYet = false;
- if (this.soundOnOrOff == 0) {
- ((Applet)this).showStatus("Turn sound on");
- } else {
- ((Applet)this).showStatus("Turn sound off");
- }
- }
-
- return true;
- }
-
- public boolean mouseDrag(Event var1, int var2, int var3) {
- if (this.notUpdatedYet) {
- this.notUpdatedYet = false;
- if (this.mouseOut) {
- if (this.soundOnOrOff == 0) {
- ((Applet)this).showStatus("Leave sound off");
- } else {
- ((Applet)this).showStatus("Leave sound on");
- }
- } else if (this.soundOnOrOff == 0) {
- ((Applet)this).showStatus("Turn sound on");
- } else {
- ((Applet)this).showStatus("Turn sound off");
- }
- }
-
- return true;
- }
-
- public boolean mouseEnter(Event var1, int var2, int var3) {
- Graphics var4 = ((Component)this).getGraphics();
- if (this.mouseIsDown) {
- if (this.soundOnOrOff == 0) {
- if (this.tracker.checkID(1)) {
- var4.drawImage(this.soundOnImage, 0, 0, this);
- }
- } else if (this.tracker.checkID(0)) {
- var4.drawImage(this.soundOffImage, 0, 0, this);
- }
- }
-
- if (this.soundOnOrOff == 0) {
- ((Applet)this).showStatus("Turn sound on");
- } else {
- ((Applet)this).showStatus("Turn sound off");
- }
-
- this.mouseOut = false;
- return true;
- }
-
- public boolean mouseDown(Event var1, int var2, int var3) {
- Graphics var4 = ((Component)this).getGraphics();
- this.mouseIsDown = true;
- if (this.soundOnOrOff == 0) {
- ((Applet)this).showStatus("Turn sound on");
- if (this.tracker.checkID(1)) {
- var4.drawImage(this.soundOnImage, 0, 0, this);
- }
- } else {
- ((Applet)this).showStatus("Turn sound off");
- if (this.tracker.checkID(0)) {
- var4.drawImage(this.soundOffImage, 0, 0, this);
- }
- }
-
- return true;
- }
-
- public boolean mouseUp(Event var1, int var2, int var3) {
- this.mouseIsDown = false;
- if (!this.mouseOut) {
- if (this.soundOnOrOff == 0) {
- this.soundOnOrOff = 1;
- ((Applet)this).showStatus("Turn sound off");
- this.start();
- } else {
- this.soundOnOrOff = 0;
- ((Applet)this).showStatus("Turn sound on");
- this.stop();
- }
- }
-
- this.paint(((Component)this).getGraphics());
- return true;
- }
-
- public boolean mouseExit(Event var1, int var2, int var3) {
- Graphics var4 = ((Component)this).getGraphics();
- this.notUpdatedYet = true;
- this.mouseOut = true;
- if (this.mouseIsDown) {
- if (this.soundOnOrOff == 0) {
- ((Applet)this).showStatus("Leave sound off");
- if (this.tracker.checkID(1)) {
- var4.drawImage(this.soundOffImage, 0, 0, this);
- }
- } else {
- ((Applet)this).showStatus("Leave sound on");
- if (this.tracker.checkID(0)) {
- var4.drawImage(this.soundOnImage, 0, 0, this);
- }
- }
- } else {
- ((Applet)this).showStatus("");
- }
-
- return true;
- }
-
- public void start() {
- if (this.tickTock == null) {
- this.tickTock = new Thread(this);
- this.tickTock.start();
- if (this.theSound != null && this.soundOnOrOff == 1) {
- this.theSound.loop();
- return;
- }
- } else if (this.theSound != null && this.soundOnOrOff == 1) {
- this.theSound.loop();
- }
-
- }
-
- public void stop() {
- if (this.tickTock != null) {
- this.tickTock.stop();
- this.tickTock = null;
- this.theSound.stop();
- }
-
- }
-
- public void run() {
- if (!this.inited) {
- try {
- this.theSound = ((Applet)this).getAudioClip(new URL(((Applet)this).getDocumentBase(), ((Applet)this).getParameter("sound")));
- } catch (MalformedURLException var1) {
- }
-
- this.inited = true;
- this.theSound.loop();
- }
-
- }
- }
-