Hi. I'm trying to learn about using threads in java, so I decided to try to make a new thread in which an alarm rings while the rest of the program continues.
My program is supposed to go about it's business graphing some data, and then if the data exceeds a certain value it trips an alarm.
When I compile I get this error
So when I compile It says:
cannot resolve symbol
symbol : method start ()
location: class Alarm
alert.start();//audible warning
Then in the main part of the program where I actually use the alarm is this.
Alarm alert;
alert = new Alarm();
//... more code
if (tripped){
//...do stuff
alert.start();
}
Here is my alarm class:
import sun.audio.*;
import java.io.*;
import java.awt.*;
import java.lang.*;
public class Alarm implements Runnable{
Thread t;
InputStream inAudio;
AudioStream alert1;
public void init(){
t = new Thread(this);
t.start();
inAudio = getClass( ).getResourceAsStream("alert1.wav");
try{
alert1 = new AudioStream(inAudio);
}
catch(IOException ex){
System.out.println("could not declare alert as a new AudioStream");
}
}
public void run(){
while (true){
AudioPlayer.player.start(alert1);
try{
t.sleep(500);
}
catch (InterruptedException ex){}
}
}
public void stop(){
t.stop();
}
}
Could someone please help me understand what I am doing wrong?
Thanks