/** This is a metronome ! * If you can find a better sound please, send it to me ! @author : Serge Derhy address : sderhy@imaginet.fr @version:1.0 09/28/96 * */ // Methodes de la classe metron 1 // public void init() // public void paint( Graphics g ) { // public void update(Graphics g) { // private void drawMetro( Graphics gr, boolean right) import java.awt.*; import java.applet.Applet; public class Metronome extends metron1 implements Runnable { Thread runner; int TickTime=400; /***************************< démarrage du Thread >******************/ public void start() { if (runner == null) { runner = new Thread( this); // creation du Thread runner.start() ; // Démarrage du Thread } } /***************************< arrêt du Thread >**********************/ public void stop() { if(runner != null) { runner.stop(); runner = null; } } /***************************< Corps du Thread >************/ public void run () { while(true) { PlayMetro(TickTime); } } public boolean action(Event evt, Object arg) { if (evt.target instanceof TextField) { String s = TF1.getText(); try {var1 = Integer.parseInt(s);}catch(NumberFormatException e) { } // tester les ecarts trops importants : if (var1 > 300) var1 = 300; if (var1 < 40) var1 = 40; TickTime = 60*1000/var1; // 60sec *1000 ms divisées par le tempo } if ( evt.target instanceof Button ) { if(runner != null) { runner.stop(); runner = null; } else if (runner == null) { runner = new Thread( this); // creation du Thread runner.start() ; // Démarrage du Thread } } return true; }// END OF ACTION // PlayMetro*****************< méthode gérée par le Thread********/ public void PlayMetro( int TickTime) { // right side repaint(); if (ClickSound != null) ClickSound.play(); try{Thread.sleep(TickTime);} catch(InterruptedException e){}// pause Right = false ; // Left side repaint(); if (ClickSound != null) ClickSound.play(); try{Thread.sleep(TickTime);} catch(InterruptedException e){}// pau Right = true ; } } // End of Metronome.class