Threads are tricky! You start them easily.. but how do you stop them. Consider this example (it works more or the less) but each time I test the pedal a new thread is started.... so what are all these started threats doing:
class PedaltestThread extends Thread {
private int cnt; // The name of this thread.
public PedaltestThread(int cnt) { // the thread counter
this.cnt = cnt;
}
public void run() {
midipedalflag=false; // the flag set by midipedal
do { // and space bar
} while (!midipedalflag);
midipedalflag=false;
midipedalTest.setSelected(false);
System.out.println(" pedal pushed " + cnt);
}
}
private class EventHandler implements ActionListener {
public void actionPerformed(ActionEvent evt) {
Object source = evt.getSource();
if (source == midipedalTest) {
if (midipedalTest.isSelected()) {
threadcount++; // thread counter
pedtest = new PedaltestThread(threadcount);
pedtest.start();
}
if (!midipedalTest.isSelected()) {
}
}