Estou com um problema criei um aplicativo onde ele mostra as horas e
toca a musica porém, quando eu toco a musica que é rodada em um JSlidder
de 10 posições o relógio e todos os outros itens param.
vo manda o codigo
package trabalho3;
/**
*
* @author Ricardo
*/
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.*;
import javax.swing.event.AncestorListener;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class Interface extends JFrame implements ChangeListener
{
protected Volume volume;
private Color cor;
//---------------------------------------(Radio)---------------------------------------//
protected Musica radio2;
//---------------------------------------(Relogio)-------------------------------------//
protected Relogio digitalr;
//-----------------------------------------(Threads)-----------------------------------//
protected Thread t1;
//private Thread t2;
//------------------------------------------ Painel--------------------------------------//
private JPanel pvolume;
private JPanel pesquerdo;
private JPanel pdireito;
//-----------------------------------------Labels----------------------------------------//
private JLabel lbvolume;
private JLabel lbfreq;
protected JLabel lbdigital;
//-----------------------------------------Barra deslisante------------------------------//
private JSlider slfreq;
//-----------------------------------------Volume----------------------------------------//
private JSpinner spvolume;
//-----------------------------------------Janela----------------------------------------//
JFrame radio;
private Number val = new Integer(3);
private Number min01 = new Integer(0);
private Number max01 = new Integer(10);
private Number step = new Integer(1);
Interface()
{
JFrame.setDefaultLookAndFeelDecorated(true);
radio = new JFrame();
//cor = new Color(100,150,245);
//cor = new Color(0,102,255);
// radio.setBackground(cor);
digitalr = new Relogio(this);
//digitalr.run();
/**************************************(Threads)*******************************************/
// t1 = new Thread();
//t2 = new Thread(radio2);
t1 = new Thread(digitalr);
// t1.start;
t1.start();
/**************************************(Volume)********************************************/
spvolume = new JSpinner();
SpinnerModel mdl = new SpinnerNumberModel(val, (Comparable) min01, (Comparable) max01,step);
spvolume.setModel(mdl);
// spvolume.addChangeListener(this);
/*****************************************(Estação)****************************************/
slfreq = new JSlider(1,10,1);
slfreq.setPaintTicks(true); //pintar os tick
//slfreq.setSnapToTicks(true);
// slfreq.setPaintLabels(true);
//slfreq.setInverted(true); invete a sequencia das musicas
slfreq.setMajorTickSpacing(10);
slfreq.setMinorTickSpacing(1);
slfreq.addChangeListener(this);
/**************************************(Painel)**********************************************************/
pvolume = new JPanel(new GridLayout(2,2));
pdireito = new JPanel();
/**************************************(Label)*********************************************************/
lbvolume = new JLabel("Volume");
lbfreq = new JLabel("Estação");
lbdigital = new JLabel();
/****************************************(Adicionando no Painel)*************************************/
pvolume.add(lbfreq);pvolume.add(lbvolume);
pvolume.add(slfreq);pvolume.add(spvolume);
pdireito.add(lbdigital);
//pvolume.setBackground(cor);
//pdireito.setBackground(cor);
//radio.setBackground(cor);
//.setBackground(cor);
/**************************************(Configurações da Janela)****************************************/
lbdigital.setFont(new Font("Comic Sans MS", Font.BOLD, 40));
radio.add(pvolume,BorderLayout.SOUTH);
radio.add(lbdigital,BorderLayout.EAST);
radio.setTitle(" Radio Relógio ");
radio.setSize(650,500);
radio.setLocationRelativeTo(radio);
radio.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
radio.setVisible(true);
}
public static void main(String args [])
{
//chamando o construtor
new Interface();
}
public void stateChanged(ChangeEvent event)
{
JSlider slider = (JSlider)event.getSource();
int value = slider.getValue();
if(value==4)
{
//String com o caminho do arquivo MP3 a ser tocado
String path = "c:/musica1";
//Instanciação de um objeto File com o arquivo MP3
File mp3File = new File(path);
//Instanciação do Objeto MP3, a qual criamos a classe.
radio2 = new Musica(mp3File);
//Finalmente a chamada do método que toca a música
value=0;
radio2.play();
}
System.out.println(val+"\n"+min01+"\n"+max01+"\n"+step);
}
}
essa é a interface segue abaixo a classe musica
[code]
package trabalho3;
import java.io.*;
import javazoom.jl.player.Player;
public class Musica implements Runnable {
private File mp3;
private Player player;
public Musica(File mp3)
{
this.mp3 = mp3;
}
public void play() {
try {
FileInputStream fis = new FileInputStream(mp3);
BufferedInputStream bis = new BufferedInputStream(fis);
this.player = new Player(bis);
this.player.play();
} catch (Exception e) {
System.out.println("Erro na musica " + mp3);
e.printStackTrace();
}
}
public void stop()
{
this.player.close();
}
public void run() {
throw new UnsupportedOperationException("Not supported yet.");
}
}[/code]
Alguma sugestão ??
obg