Ae pessoal precisando de ajuda pra fazer um trabalho
preciso colocar o volume em um JSpinner
e tenhu encontrado dificuldade com issu pelo fato
de não saber qual evento usar e como implementar a classe pelo javazoom.
obg
vo manda o codigo pra vc6 terem uma noção
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
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;
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();
spvolume.setModel(new SpinnerNumberModel(3,0,10,1));
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();
}
}
}