/** This is a metronome ! @author : Serge Derhy address : sderhy@imaginet.fr @version:1.0 09/28/96 * */ import java.awt.*; import java.applet.Applet; import java.applet.AudioClip; public class metron1 extends Applet { TextField TF1; // to get the tempo Button bStop; // On Off button, if it's getting on your nerves ! int var1 ; boolean Right = true ; // side of the needle boolean BoutonState = true ; AudioClip ClickSound; Image offscrImg ; // On crée une image Offscreen int exes[] = { 100,135,165,200 }; // La boite int whys[] = { 250,50,50,250}; int NeedlexR[] = { 145,155,220}; // L'aiguille int NeedleyR[] = { 208,212,60}; int NeedlexL[] = { 145,155,70}; int NeedleyL[] = { 212,208,60}; public void init() { ClickSound = getAudioClip(getCodeBase(), "Audio/ClickSound.au");//son.au TF1 = new TextField(10); bStop = new Button("On-Off"); setBackground(Color.pink); add(TF1); add(bStop); } public void paint( Graphics g ) { g.drawString( "Tempo ", 20 ,20); drawMetro(g,Right); } public void update(Graphics g) { // creates an offScreen image the size of the applet : if (offscrImg == null) offscrImg = createImage( size().width ,size().height); Graphics og = offscrImg.getGraphics(); // clipping area og.setColor(getBackground()); og.fillRect(0,0, size().width, size().height); og.clipRect(70,50,155,200); // offscreen drawing paint(og); g.drawImage(offscrImg,0,0,this); og.dispose(); } private void drawMetro( Graphics gr, boolean right) { gr.setColor( Color.red); gr.fillPolygon(exes,whys,4); gr.setColor(Color.blue); if( right) gr.fillPolygon(NeedlexR,NeedleyR,3); else gr.fillPolygon(NeedlexL,NeedleyL,3); } }// End of Applet