home *** CD-ROM | disk | FTP | other *** search
Wrap
import java.applet.Applet; import java.applet.AudioClip; import java.awt.Button; import java.awt.Checkbox; import java.awt.Color; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.Event; import java.net.MalformedURLException; import java.net.URL; public class ClipControl extends Applet implements Runnable { int width = 260; int height = 40; String url = "http://www.cs.indiana.edu/hyplan/kinzler/fun/shr_sounds/index.html"; String clipname; URL clipurl; boolean backload = false; boolean backplay = false; AudioClip clip; Button play; Button loop; Button stop; Checkbox load; Event pend; Thread thrd; boolean loading = false; String[][] pinfo = new String[][]{{"clip", "URL", "audio clip"}, {"bgcolor", "color", "background color"}, {"fgcolor", "color", "foreground color"}, {"playlabel", "string", "play button label [Play]"}, {"looplabel", "string", "loop button label [Loop]"}, {"stoplabel", "string", "stop button label [Stop]"}, {"loadlabel", "string", "load button label [Load]"}, {"noload", "boolean", "don't show load button [false]"}, {"preload", "boolean", "load clip at start [false]"}, {"preplay", "boolean", "play clip at start [false]"}, {"preloop", "boolean", "loop clip at start [false]"}, {"backload", "boolean", "keep loading on applet stop [false]"}, {"backplay", "boolean", "keep playing on applet stop [false]"}}; public String getAppletInfo() { return "ClipControl - a AudioClip control applet with play/loop/stop/load buttons\nSteve Kinzler, kinzler@cs.indiana.edu, May 96\n" + this.url + "\nVersion 1.1.0"; } public String[][] getParameterInfo() { return this.pinfo; } public synchronized void init() { Dimension var1 = ((Component)this).size(); if (var1.width > 0) { this.width = var1.width; } if (var1.height > 0) { this.height = var1.height; } ((Applet)this).resize(this.width, this.height); String var2 = ((Applet)this).getParameter("BGCOLOR"); if (var2 != null && var2.startsWith("#")) { int var3 = Integer.parseInt(var2.substring(1), 16); ((Component)this).setBackground(new Color(var3)); } var2 = ((Applet)this).getParameter("FGCOLOR"); if (var2 != null && var2.startsWith("#")) { int var14 = Integer.parseInt(var2.substring(1), 16); ((Component)this).setForeground(new Color(var14)); } var2 = this.clipname = ((Applet)this).getParameter("CLIP"); try { this.clipurl = var2 != null ? new URL(((Applet)this).getDocumentBase(), var2) : null; } catch (MalformedURLException var4) { this.clipurl = null; } if (this.clipurl != null) { var2 = ((Applet)this).getParameter("PLAYLABEL"); if (this.play != null) { ((Container)this).remove(this.play); } this.play = new Button(var2 != null ? var2 : "Play"); ((Container)this).add(this.play); var2 = ((Applet)this).getParameter("LOOPLABEL"); if (this.loop != null) { ((Container)this).remove(this.loop); } this.loop = new Button(var2 != null ? var2 : "Loop"); ((Container)this).add(this.loop); var2 = ((Applet)this).getParameter("STOPLABEL"); if (this.stop != null) { ((Container)this).remove(this.stop); } this.stop = new Button(var2 != null ? var2 : "Stop"); ((Container)this).add(this.stop); var2 = ((Applet)this).getParameter("LOADLABEL"); if (this.load != null) { ((Container)this).remove(this.load); } this.load = new Checkbox(var2 != null ? var2 : "Load"); if (this.loading) { this.load.setState(true); } var2 = ((Applet)this).getParameter("NOLOAD"); if (this.clip == null && (var2 == null || !var2.equals("true") || false)) { ((Container)this).add(this.load); } var2 = ((Applet)this).getParameter("BACKLOAD"); this.backload = var2 != null ? var2.equals("true") : false; var2 = ((Applet)this).getParameter("BACKPLAY"); this.backplay = var2 != null ? var2.equals("true") : false; this.preAction("PRELOAD", this.load); this.preAction("PRELOOP", this.loop); this.preAction("PREPLAY", this.play); } } void preAction(String var1, Component var2) { String var3 = ((Applet)this).getParameter(var1); if (var3 != null && var3.equals("true") && true) { this.action(new Event(var2, 1001, this), this); } } public boolean mouseEnter(Event var1, int var2, int var3) { ((Applet)this).showStatus(this.url); return true; } public boolean mouseExit(Event var1, int var2, int var3) { ((Applet)this).showStatus((String)null); return true; } public boolean mouseUp(Event var1, int var2, int var3) { if (this.url != null) { try { ((Applet)this).getAppletContext().showDocument(new URL(this.url)); } catch (MalformedURLException var4) { this.url = null; ((Applet)this).showStatus("Ignoring Malformed Home URL"); } } return true; } public synchronized boolean keyDown(Event var1, int var2) { if (this.clip != null) { this.clip.stop(); } if (this.thrd != null) { this.thrd.stop(); } this.load.setState(false); this.clip = null; this.pend = null; this.thrd = null; this.loading = false; this.getClip((Event)null); return true; } public boolean action(Event var1, Object var2) { if (var1.target == null) { return true; } else { if (var1.target.equals(this.play)) { if (!this.getClip(var1)) { ((Applet)this).showStatus("Playing " + this.clipname); this.clip.play(); } } else if (var1.target.equals(this.loop)) { if (!this.getClip(var1)) { ((Applet)this).showStatus("Looping " + this.clipname); this.clip.loop(); } } else if (var1.target.equals(this.stop)) { this.pend = null; if (this.clip != null) { ((Applet)this).showStatus("Stopping " + this.clipname); this.clip.stop(); } } else if (var1.target.equals(this.load)) { this.getClip((Event)null); } return true; } } synchronized boolean getClip(Event var1) { this.load.setState(true); if (!this.loading) { this.loading = true; if (this.clip == null) { ((Applet)this).showStatus("Loading " + this.clipname); if (var1 != null) { this.pend = var1; } this.thrd = new Thread(this); this.thrd.start(); return true; } } if (this.clip == null) { if (var1 != null) { this.pend = var1; } ((Applet)this).showStatus("Still loading " + this.clipname); return true; } else { return false; } } public void run() { this.clip = ((Applet)this).getAudioClip(this.clipurl); ((Applet)this).showStatus("Loaded " + this.clipname); ((Container)this).remove(this.load); ((Component)this).repaint(); if (this.pend != null) { this.action(this.pend, this); } this.pend = null; this.thrd = null; } public synchronized void stop() { if (this.clip != null && !this.backplay) { this.clip.stop(); } if (this.thrd != null && !this.backload) { this.thrd.stop(); this.load.setState(false); this.clip = null; this.pend = null; this.thrd = null; this.loading = false; } } }