import java.applet.*; import java.awt.*; import java.lang.Math; public class Clicker extends Applet implements Runnable { String copyright="Copyright (C) 2002 Anders Johnson"; Thread animation; boolean running; int width, height; int state; double x, y, d; double theta, pi4; double A, B, C; Image offscreen; Graphics b; AudioClip click1, click2; public void init() { // Some (maybe all) Macintoshes don't support getSize(), which is // a shame because it means that the applet won't scale on any // platform now. (Insert favorite "run anywhere" joke here.) //width = getSize().width; //height = getSize().height; width=321; height=301; setBackground( Color.gray ); state=0; x=4.0; y=8.0; d=9.0; theta=0.0; pi4=16.0*Math.atan(1); double m=-1; // minimum d double M1=9; // maximum d double M2=5; // maximum "shallow" d A=(M1+M2+2*m)/4.0; B=(M1+M2-2*m)/4.0; C=(M1-M2)/2.0; click1=getAudioClip(getDocumentBase(), "click1.au"); click2=getAudioClip(getDocumentBase(), "click2.au"); offscreen=createImage(width, height); b=offscreen.getGraphics(); animation=new Thread(this); running=true; animation.start(); } public void move(double din) { d=din; if((state==0 || state==2) && d<=0.0) { click1.play(); state=(state+1)%4; } if((state==1 || state==3) && d>=4.0) { click2.play(); state=(state+1)%4; } if(state==0) { x=4.0; y=d; if(y>8) { y=8; } } if(state==1) { double d1=0.0; if(d>0.0) { d1=d; } x=5.0+d1/2.0; y=1+d-d1/2.0; } if(state==2) { double d1=4.0; if(d0.0) { d1=d; } x=1.0+d1/2.0; y=1+d-d1/2.0; } } int xc(double xin) { return (int) Math.rint((width-1) * xin/16.0); } int yc(double yin) { return (int) Math.rint((height-1)*(10.0-yin)/15.0); } void xfill(int targ[], double in[], double delta, int ofs) { for(int i=0; i pi4) { theta-=pi4; } } try { // Wait 100ms (10Hz) animation.sleep(100); } catch(InterruptedException e) { System.out.println(e); } } } public void destroy() { running=false; animation=null; } }