please dont rip this site

import java.applet.*;
import java.awt.*;
import java.util.*;
import java.net.*;
import netscape.javascript.*;

public class GizmoButton extends Applet {

	private static Hashtable buttons = new Hashtable();
	private Image on, off;
	private boolean locking, alternating, isPressed = false;
	private URL url;
	private String name, target, function, interlocking;
	private Graphics graphics;
	private AudioClip clickOn, clickOff;

	public void init() {

		if (getParameter("name") != null) {
			name = getParameter("name");
			buttons.put(name, this);
		};
		graphics = getGraphics();

		if (getParameter("on") != null && getParameter("off") != null) {
			MediaTracker tracker = new MediaTracker(this);
			on = getImage(getDocumentBase(), getParameter("on"));
			tracker.addImage(on, 0);
			off = getImage(getDocumentBase(), getParameter("off"));
			tracker.addImage(off, 1);
			try {
				tracker.waitForAll();
			} catch(Exception e) {

			};
			if (tracker.isErrorAny()) {
				on = makeButton(false);
				off = makeButton(true);
			};
		} else {
			on = makeButton(false);
			off = makeButton(true);
		};

		if (getParameter("click_on") != null) {
			try {
				clickOn = getAudioClip(new URL(getDocumentBase(), getParameter("click_on")));
				if (clickOn != null) {
					clickOn.play();
					clickOn.stop();
				};
			} catch (MalformedURLException e) {

			};
		};

		if (getParameter("click_off") != null) {
			try {
				clickOff = getAudioClip(new URL(getDocumentBase(), getParameter("click_off")));
				if (clickOff != null) {
					clickOff.play();
					clickOff.stop();
				};
			} catch (MalformedURLException e) {

			};
		};

		locking = false;
		if (getParameter("locking") != null) {
			if (getParameter("locking").equals("true")) {
				locking = true;
			};
		};

		interlocking = null;
		if (getParameter("interlocking") != null && name != null) {
			interlocking = getParameter("interlocking");
		};

		alternating = false;
		if (getParameter("alternating") != null) {
			if (getParameter("alternating").equals("true")) {
				alternating = true;
				locking = true;
			};
		};

		try {
			url = new URL(getParameter("url"));
		} catch(MalformedURLException e) {
			url = null;
		};

		if (getParameter("function") != null) {
			function = getParameter("function");
		};

		target = getParameter("target");
		if (target == null) {
			target = "_top";
		};
	};

	public void start() {
		System.out.println("GizmoButton Applet\nCopyright 2000 William Johns.");
	};

	public void update(Graphics g) {
		paint(g);
	};

	public void paint(Graphics g) {
		if (isPressed) {
			g.drawImage(on, 0, 0, this);
		} else {
			g.drawImage(off, 0, 0, this);
		};
	};

	public void buttonUp(String set) {
		if (interlocking != null) {
			if (interlocking.equals(set)) {
				isPressed = false;
				paint(graphics);
			};
		};
	};

	public void buttonUp() {
		isPressed = false;
		paint(graphics);
	};

	public boolean state() {
		if (isPressed) {
			return true;
		} else {
			return false;
		};
	};

	private Image makeButton(boolean raised) {
		Image image = createImage(size().width, size().height);
		Graphics g = image.getGraphics();
		g.setColor(Color.lightGray);
		g.fill3DRect(0, 0, size().width, size().height, raised);
		String text = getParameter("text");
		if (text != null) {
			FontMetrics f = g.getFontMetrics();
			for (int i = image.getHeight(this); i > 4; i--) {
				g.setFont(new Font("Helvetica", Font.PLAIN, i));
				f = g.getFontMetrics();
				if (f.stringWidth(text) < image.getWidth(this) * 0.8) {
					break;
				};
			};
			int x = (image.getWidth(this) - f.stringWidth(text)) / 2;
			int y = (image.getHeight(this) / 2) + f.getDescent() + 1;
			if (raised) {
				x++;
				y++;
			};
			g.setColor(Color.black);
			g.drawString(text, x, y);
		};
		return image;
	};

	public boolean mouseDown(Event e, int x, int y) {

		if (isPressed) {
			if (alternating) {
				isPressed = false;
				paint(graphics);
				if (clickOff != null) {
					clickOff.play();
				};
			};
			return true;
		};
		isPressed = true;
		paint(graphics);
		if (clickOn != null) {
			clickOn.play();
		};
		if (interlocking != null) {
			GizmoButton b;
			for (Enumeration eb = buttons.elements() ;eb.hasMoreElements() ;) {
				try {
					b = (GizmoButton) eb.nextElement();
				} catch (NoSuchElementException ex) {
					break;
				};
				if (b != this) {
					b.buttonUp(interlocking);
				};
			};
		};
		if (url != null) {
			getAppletContext().showDocument(url, target);
		};
		if (function != null) {
			try {
				JSObject.getWindow(this).eval(function);
			} catch (Exception ex) {

			};
		};
		return true;
	};

	public boolean mouseUp(Event e, int x, int y) {
		if (!locking) {
			isPressed = false;
			paint(graphics);
		};
		return true;
	};

	public String getAppletInfo() {
		String info= "GizmoButton Applet Copyright 2000 William Johns";
		return info;
	};
};

file: /images/language/java/gizmobutton/GizmoButton.java, 4KB, , updated: 2000/5/10 16:33, local time: 2012/2/10 16:21,
TOP NEW HELP FIND: 
38.107.179.231:LOG IN

 ©2012 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE! / 

<A HREF="http://www.piclist.com/images/language/java/gizmobutton/GizmoButton.java"> </A>

Did you find what you needed?

 
Stepper motors CAN be smooth!
And stepper controllers can be strong and cheap. Roman Black's Linistep stepper controller kits:
o 18th microstep
o Linear smoothing
  o Open source
o Full kit $25!
  'What can I do?' - SiCKO

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .