Cześć poradziłem sobie z wątkami i już elegancko przerywa mi wykonanie utworu i wszystko ładnie działa jednak wkradł mi się jakiś prosty błąd i znów zawiesił mnie na kilka dni. Mianowicie ostatni nawias ,,}.. ciągle świeci się na czerwono i pokazuje błąd ( reached of the while persing). Co zrobiłem w tym kodzie źle? Dopiero zaczynam przygodę dlatego proszę o wyrozumiałość ;)
package wordsy;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JFrame;
import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.Player;
public class Clear2 implements Runnable {
public Thread gameThread;
public static boolean running = false;
public synchronized void start() {
if (running) {
return;
}
running = true;
gameThread = new Thread(this);
gameThread.start();
}
public synchronized void stop() {
if (!running) {
return;
}
running = false;
try {
gameThread.join();
} catch (InterruptedException ex) {
Logger.getLogger(Clear2.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
public void run() {
{
try {
File file = new File("C:\\Efekty dzwiekowe\\test\\approach.mp3");
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
try {
Player player = new Player(bis);
player.play();
} catch (JavaLayerException ex) {
}
} catch (IOException e) {
}
}
}
public static void main(String[] args) {
Runnable zadanieWatku = new NewMp3();
Thread mojWatek = new Thread(zadanieWatku);
mojWatek.start();
JFrame ramka = new JFrame();
ramka.setSize(500, 500);
ramka.setVisible(true);
JButton button = new JButton();
button.setText("stop");
button.setVisible(true);
ramka.add(button);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mojWatek.stop();
} -------------------------------------------- **// - tutaj jest problem opisany ( reached of the while persing )**