⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clipcontrol.java

📁 一个按钮控制程序
💻 JAVA
字号:
// Copyright (c) 1996 Stephen B Kinzler.  All rights reserved.//// THIS PROGRAM IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIES OR// MODIFICATIONS MADE ONLY IN ACCORDANCE WITH THE TERMS OF THAT LICENSE AND// WITH THE INCLUSION OF THIS COPYRIGHT NOTICE.  NO TITLE TO OR OWNERSHIP// OF THE PROGRAM IS HEREBY TRANSFERRED.//// LICENSE: This program may be freely used and distributed provided the// following conditions are met:// (1) This license and the following disclaimer must remain with this//     program however distributed or published.// (2) All advertising materials mentioning features or use of this software//     must display the following acknowledgement://       This product includes software developed by the Stephen B Kinzler.// (3) Any commercial use or distribution of this program, or its use or//     distribution by any commercial entity, must first have the express//     permission of Stephen B Kinzler.  A modest fee may be requested to//     help fund this program's support and development.//// THIS SOFTWARE IS PROVIDED BY STEPHEN B KINZLER ``AS IS'' AND ANY EXPRESS// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE// ARE DISCLAIMED.  IN NO EVENT SHALL STEPHEN B KINZLER BE LIABLE FOR// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE// POSSIBILITY OF SUCH DAMAGE.import java.applet.*;import java.awt.*;import java.net.*;///////////////////////////////////////////////////////////////////////////////// ClipControl // Declaration /////////////////////////////////////////////////public class ClipControl extends Applet implements Runnable {	int width  = 260, height = 40;	String url = "http://www.cs.indiana.edu/hyplan/kinzler/fun/"		   + "shr_sounds/index.html";	public String getAppletInfo() {		return"ClipControl - an AudioClip control applet with play/loop/stop/load buttons\n"+ "Steve Kinzler, kinzler@cs.indiana.edu, May 96/Sep 96\n" + url+ "\nVersion 2.0.2, see source code for license\n"+ "Copyright (c) 1996 Stephen B Kinzler.  All rights reserved.\n\n"+ "color  := hexadecimal number prefixed with '#'\n"+ "action := load = reload the clip\n"+ "          play = play the clip, loading it first if needed\n"+ "          loop = loop the clip, loading it first if needed\n"+ "          quit = quit loading the clip\n"+ "          stop = stop the clip";	}	String pinfo[][] = {	    {"clip",      "URL",     "audio clip"},	    {"bgcolor",   "color",   "background color"},	    {"fgcolor",   "color",   "foreground color"},	    {"bgstatus",  "string",  "background status string"},	    {"noplay",    "boolean", "don't show play button [false]"},	    {"noloop",    "boolean", "don't show loop button [false]"},	    {"nostop",    "boolean", "don't show stop button [false]"},	    {"noload",    "boolean", "don't show load button [false]"},	    {"boxplay",   "boolean", "use a checkbox for play button [false]"},	    {"boxloop",   "boolean", "use a checkbox for loop button [false]"},	    {"boxstop",   "boolean", "use a checkbox for stop button [false]"},	    {"playlabel", "string",  "play button label [Play]"},	    {"looplabel", "string",  "loop button label [Loop]"},	    {"stoplabel", "string",  "stop button label [Stop]"},	    {"loadlabel", "string",  "load button label [Load]"},	    {"nextlabel", "string",  "next load button label [Reload]"},	    {"nextload",  "boolean", "keep load button for reloads [false]"},	    {"oninit",    "actions", "actions on applet initialization []"},	    {"onstart",   "actions", "actions on applet start []"},	    {"onstop",    "actions", "actions on applet stop [quitstop]"},	    {"ondestroy", "actions", "actions on applet destruction [stop]"},	};	public String[][] getParameterInfo() {		return pinfo;	}	String	  clipname, status, nextlabel;	URL	  clipurl;	boolean	  nextload = false;	String	  oninit, onstart, onstop, ondestroy;	AudioClip clip = null;	Component play = null, loop = null, stop = null, load = null;	Event	  pend = null;	Thread	  thrd = null;	boolean	  looping = false, loading = false;// ClipControl // Initialization //////////////////////////////////////////////	public synchronized void init() {		Dimension d = size();		if (d.width  > 0) width  = d.width;		if (d.height > 0) height = d.height;		resize(width, height);		String s = getParameter("BGCOLOR");		if (s != null && s.startsWith("#")) {			int i = Integer.parseInt(s.substring(1), 16);			setBackground(new Color(i));		}		s = getParameter("FGCOLOR");		if (s != null && s.startsWith("#")) {			int i = Integer.parseInt(s.substring(1), 16);			setForeground(new Color(i));		}		s = getParameter("BGSTATUS");		status = (s != null) ? s : "ClipControl: click, type 'h' " +					   "for home page or '?' for keys";		s = clipname = getParameter("CLIP");		try { clipurl = (s != null) ? new URL(getDocumentBase(), s)					    : null; }		catch (MalformedURLException e) { clipurl = null; }		if (clipurl == null) return;		s = getParameter("NEXTLABEL");		nextlabel = (s != null) ? s : "Reload";		s = getParameter("NEXTLOAD");		nextload  = (s != null) ? s.equals("true") : false;		play = makeButton(play, "PLAY", "Play");		loop = makeButton(loop, "LOOP", "Loop");		stop = makeButton(stop, "STOP", "Stop");		load = makeButton(load, "LOAD", "Load");		oninit	  = getParameter("ONINIT");		onstart   = getParameter("ONSTART");		s	  = getParameter("ONSTOP");		onstop	  = (s != null) ? s : "quitstop";		s	  = getParameter("ONDESTROY");		ondestroy = (s != null) ? s : "stop";		doAction(oninit);	}	synchronized Component makeButton(Component button,					  String param, String label) {		if (button != null) remove(button);		String l = getParameter(param + "LABEL");		if (l == null) l = label;		if (param.equalsIgnoreCase("LOAD")) {			button = new Checkbox((clip == null) ? l : nextlabel);			setButton(button, loading);			String s = getParameter("NO" + param);			if ((s == null || ! s.equals("true")) &&			    (nextload || clip == null)) add(button);			return(button);		}		String s = getParameter("BOX" + param);		if (s != null && s.equals("true"))			button = new Checkbox(l);		else			button = new Button(l);		setButton(button, (param.equalsIgnoreCase("LOOP")) ? looping								   : false);		s = getParameter("NO" + param);		if (s == null || ! s.equals("true")) add(button);		return(button);	}	void setButton(Component button, boolean state) {		if (button instanceof Checkbox)			((Checkbox) button).setState(state);	}	public void start() {		doAction(onstart);	}// ClipControl // Actions /////////////////////////////////////////////////////	void doAction(String action) {		if (action == null) return;		String a = action.toLowerCase();		if (a.indexOf("load") >= 0) {			quitLoad();			pressButton(load);		}		if (a.indexOf("play") >= 0) pressButton(play);		if (a.indexOf("loop") >= 0) {			if (loop instanceof Checkbox && looping)				pressButton(loop);			pressButton(loop);		}		if (a.indexOf("quit") >= 0) quitLoad();		if (a.indexOf("stop") >= 0) pressButton(stop);	}	void pressButton(Component button) {		action(new Event(button, Event.ACTION_EVENT, this), this);	}// ClipControl // Events //////////////////////////////////////////////////////	public boolean mouseEnter(Event evt, int x, int y) {		requestFocus();		showStatus(status);		return true;	}	public boolean mouseExit(Event evt, int x, int y) {		showStatus(null);		return true;	}	public boolean keyDown(Event evt, int key) {		switch (key) {		case 'h':                case 'H':	toHome();	  break;		case 'p':                case 'P':	doAction("play"); break;		case 'l':                case 'L':	doAction("loop"); break;		case 's':                case 'S':	doAction("stop"); break;		case 'r':                case 'R':	doAction("load"); break;		case 'q':                case 'Q':	doAction("quit"); break;		case '?':		default:	showStatus("(h)ome (p)lay (l)oop (s)top " +					   "(r)eload (q)uit loading");		}		return true;	}	void toHome() {		try { getAppletContext().showDocument(new URL(url)); }		catch (MalformedURLException e) {			showStatus("Ignoring Malformed Home URL");		}	}	public synchronized boolean action(Event e, Object o) {		if (e.target == null) return true;		if (e.target.equals(play)) {			setButton(play, true);			if (! getClip(e)) {				showStatus("Playing " + clipname);				clip.play();			}			setButton(play, false);		} else if (e.target.equals(loop)) {			if (loop instanceof Checkbox && looping) {				showStatus("Stopping " + clipname);				clip.stop();				looping = false;				setButton(loop, false);				return true;			}			setButton(loop, true);			if (! getClip(e)) {				looping = true;				showStatus("Looping " + clipname);				clip.loop();			} else				setButton(loop, false);		} else if (e.target.equals(stop)) {			setButton(stop, true);			if (clip != null) {				showStatus("Stopping " + clipname);				clip.stop();				if (looping) setButton(loop, false);			}			pend    = null;			looping = false;			setButton(stop, false);		} else if (e.target.equals(load)) {			if (loading) { quitLoad(); } else { getClip(null); }		}		return true;	}// ClipControl // Loading /////////////////////////////////////////////////////	synchronized boolean getClip(Event e) {		if (e != null && clip != null) return false;		if (e == null) quitLoad();		if (loading) {			pend = e;			showStatus("Still loading " + clipname);			return true;		}		loading = true;		setButton(load, true);		showStatus("Loading " + clipname);		if (e != null) pend = e;		thrd = new Thread(this);		thrd.start();		return true;	}	public void run() {		AudioClip c = getAudioClip(clipurl);		synchronized (this) {			if (clip != null) doAction("stop");			clip = c; c = null;			loading = false;			showStatus("Loaded " + clipname);			if (! nextload) remove(load);			((Checkbox) load).setLabel(nextlabel);			setButton(load, false);			if (pend != null) action(pend, this);			pend = null; thrd = null;		}	}	synchronized void quitLoad() {		if (thrd != null) {			thrd.stop();			showStatus("Quit loading " + clipname);		}		loading = false; pend = null; thrd = null;		setButton(load, false);	}// ClipControl // Destruction /////////////////////////////////////////////////	public void stop() {		doAction(onstop);	}	public void destroy() {		doAction(ondestroy);		quitLoad();	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -