Error method : mouseClicked();

Exception in thread"AWT-EventQueue-0" java.lang.NullPointerException

at PnlSimulacion.mouseClicked(PnlSimulacion.java:816)

at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:21

1)

at java.awt.Component.processMouseEvent(Component.java:5491)

at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)

at java.awt.Component.processEvent(Component.java:5253)

at java.awt.Container.processEvent(Container.java:1966)

at java.awt.Component.dispatchEventImpl(Component.java:3955)

at java.awt.Container.dispatchEventImpl(Container.java:2024)

at java.awt.Component.dispatchEvent(Component.java:3803)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212

)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3901)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)

at java.awt.Container.dispatchEventImpl(Container.java:2010)

at java.awt.Window.dispatchEventImpl(Window.java:1774)

at java.awt.Component.dispatchEvent(Component.java:3803)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh

read.java:242)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre

ad.java:163)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Here is my class Simulacion:

import java.awt.event.*;

import java.awt.*;

import javax.swing.*;

import java.util.Locale;

import java.util.ArrayList;

import java.util.Date;

import java.text.SimpleDateFormat;

//import java.applet.*;

import sun.audio.*;

import java.io.*;

publicclass PnlSimulacionextends JInternalFrameimplements ActionListener,MouseListener{

// Declaraci髇 de variables

JPanel pnlTragam,

pnlTxtCredito,pnlTxtCoins,pnlTxtGanancia;

JLabel lblTragamonedas,

lblGirar, lblApostUno, lblApostMax,lblAceptar,

//Labels que contendr鄋 las im醙enes de los rodillos

lblRod1,lblRod2,lblRod3,

lblGirando,

//arreglo de labels(para los numeros

lbl[]=new JLabel[10],lbl1[]=new JLabel[3],lbl2[]=new JLabel[10];

JButton btnAceptar;

//-

ImageIcongirarIn,girarOut,girarPush,apuestaMaximaIn,apuestaMaximaOut,

apuestaMaximaPush,apostarUnoIn,apostarUnoOut,apostarUnoPush;

JTextArea txtS;

//ArrayList de imagenes

ArrayList<ImageIcon> arrImagenes =new ArrayList<ImageIcon>();

//SOLO para la prueba, cambie la variable de moneda

double moneda=50.0;

//variable global de coins

double coins=0;

Timer timer;

//cuenta cuantas veces a giado el rodillo

int girosRod1,girosRod2,girosRod3;

//indice de la imagen que se ve en cada rodillo

int indRodillo1, indRodillo2, indRodillo3;

SimpleDateFormat sdf;

//AudioClip sonido1,betOne,betMax,winBig; esto es para JApplets

////Creacion del Imput para sonido en JFrame o aplicaciones no Applet

//InputStream in = new FileInputStream("Spin.wav");

//

//InputStream sonido1 = new FileInputStream("Spin.wav");

//InputStream betOne = new FileInputStream("BetOne.wav");

//InputStream betMax = new FileInputStream("BetMax.wav");

//InputStream winBig = new FileInputStream("WinBig.wav");

//InputStream csonido1 = new FileInputStream("Spin.wav");

//

//

//referencia al frame

private MnuPanel m;

public Sonido s;// <-- THIS COULD BE THE ERROR?

//--

// Crea la interfaz gr醘ica de usuario

public PnlSimulacion(MnuPanel m){

//

//

//AudioStream as = new AudioStream(in);

//AudioData data = as.getData();

//ContinuousAudioDataStream cas = new ContinuousAudioDataStream (data);

//

//AudioStream betOne = new AudioStream(betOne);

//AudioStream betMax = new AudioStream(betMax);

//AudioStream winBig = new AudioStream(winBig);

getContentPane().setLayout(null);

//sonido1=getAudioClip(getDocumentBase(),);

//betOne=getAudioClip(getDocumentBase(),"BetOne.wav");

//betMax=getAudioClip(getDocumentBase(),"BetMax.wav");

//winBig=getAudioClip(getDocumentBase(),"WinBig.wav");

Date d =new Date();

//para fomratear adecuadamente

//SimpleDateFormat sdf=new SimpleDateFormat("dd/MM/yy");

sdf=new SimpleDateFormat("dd/MM/yy hh:mm:ss");

//crea el timer, ajustarlo segun se kiera

timer=new Timer(40,this);

//PANEL TRAGAMONEDAS

//Panel del tragamonedas

pnlTragam=new JPanel();

pnlTragam.setLayout(null);

pnlTragam.setBounds(0,0,800,640);

pnlTragam.setVisible(true);

getContentPane().add(pnlTragam);

// textArea para el ticket

txtS=new JTextArea();

txtS.setBounds(635,240,152,230);

txtS.setEditable(false);

pnlTragam.add(txtS);

//crea un label que es el que contendr?la imag閚 del simulador

lblTragamonedas=new JLabel(

new ImageIcon(getClass().getResource("FondoTragamonedas.png")));

lblTragamonedas.setBounds(0,0,800,640);

pnlTragam.add(lblTragamonedas);

//BOTON aceptar del ticket

btnAceptar=new JButton(

new ImageIcon(getClass().getResource("aceptar.jpg")));

btnAceptar.setBounds(682,483,72,21);

btnAceptar.addActionListener(this);

pnlTragam.add(btnAceptar);

//imagenes de los botones para cargar

girarIn =new ImageIcon(

getClass().getResource("girarIn.jpg"));

girarOut =new ImageIcon(

getClass().getResource("girarOut.jpg"));

girarPush =new ImageIcon(

getClass().getResource("girarPush.jpg"));

apuestaMaximaIn =new ImageIcon(

getClass().getResource("apuestaMaximaIn.jpg"));

apuestaMaximaOut =new ImageIcon(

getClass().getResource("apuestaMaximaOut.jpg"));

apuestaMaximaPush =new ImageIcon(

getClass().getResource("apuestaMaximaPush.jpg"));

apostarUnoIn =new ImageIcon(

getClass().getResource("apostarUnoIn.jpg"));

apostarUnoOut =new ImageIcon(

getClass().getResource("apostarUnoOut.jpg"));

apostarUnoPush =new ImageIcon(

getClass().getResource("apostarUnoPush.jpg"));

//lblGirar

lblGirar=new JLabel(girarOut);

lblGirar.setBounds(451,517,66,42);

lblGirar.addMouseListener(this);

lblGirar.setToolTipText("presione para girar los rodillos");

lblGirar.setCursor(new Cursor(Cursor.HAND_CURSOR));

pnlTragam.add(lblGirar);

//lbl de apuesta "uno por uno"

lblApostUno=new JLabel(apostarUnoOut);

lblApostUno.setBounds(375,518,61,41);

lblApostUno.addMouseListener(this);

lblApostUno.setCursor(new Cursor(Cursor.HAND_CURSOR));

lblApostUno.setToolTipText("presione para apostar solo una moneda");

pnlTragam.add(lblApostUno);

//BOTON de apuesta "maxima" (2 soles)

lblApostMax=new JLabel(apuestaMaximaOut);

lblApostMax.setBounds(528,518,67,41);

lblApostMax.addMouseListener(this);

lblApostMax.setCursor(new Cursor(Cursor.HAND_CURSOR));

lblApostMax.setToolTipText("presione para reaizar la maxima apuesta");

pnlTragam.add(lblApostMax);

//gif GIRANDO...

lblGirando =new JLabel(new ImageIcon(

getClass().getResource("girando.gif")));

lblGirando.setBounds(400,598,69,17);

lblGirando.setVisible(false);

lblTragamonedas.add(lblGirando);

//PANEL MUESTRA_CREDITO

//este es un peque駉 panel que contiene imagenes de mumeros

pnlTxtCredito=new JPanel();

pnlTxtCredito.setLayout(null);

pnlTxtCredito.setBounds(408,470,102,19);

pnlTxtCredito.setVisible(true);

lblTragamonedas.add(pnlTxtCredito);

//PANEL MUESTRA_MONEDAS_INSERTADAS(COINS)

//este es un peque駉 panel que contiene imagenes de mumeros

pnlTxtCoins=new JPanel();

pnlTxtCoins.setLayout(null);

pnlTxtCoins.setBounds(539,427,25,19);

pnlTxtCoins.setVisible(true);

lblTragamonedas.add(pnlTxtCoins);

//PANEL MUESTRA_GANANCIA

//este es un peque駉 panel que contiene imagenes de mumeros

pnlTxtGanancia=new JPanel();

pnlTxtGanancia.setLayout(null);

pnlTxtGanancia.setBounds(272,470,102,19);

pnlTxtGanancia.setVisible(true);

lblTragamonedas.add(pnlTxtGanancia);

//labels que muestran las imagenes de los rodillos-

lblRod1=new JLabel();

lblRod1.setBounds(255,343,80,110);

pnlTragam.add(lblRod1);

lblRod2=new JLabel();

lblRod2.setBounds(342,343,80,110);

pnlTragam.add(lblRod2);

lblRod3=new JLabel();

lblRod3.setBounds(429,343,80,110);

pnlTragam.add(lblRod3);

//-

//metodos a mostrar cuando inicia el programa

mostrarNada();

mostrarNada1();

mostrarNada2();

procesarCredito(moneda);

cargaImagenes();

lblRod1.setIcon(arrImagenes.get(0));

lblRod2.setIcon(arrImagenes.get(0));

lblRod3.setIcon(arrImagenes.get(0));

//muestra la imagen

}

//

// Procesa eventos de tipo ActionEvent

publicvoid actionPerformed( ActionEvent e ){

//cuando el timer esta activo

if(e.getSource()==timer){

//esto suceder?cada 100milisegundos

girar();

//desactiva las acciones de los Botones (labels)

if(e.getSource()==lblApostUno){//no hace nada

}

if(e.getSource()==lblApostMax){//no hace nada

}

if(e.getSource()==lblGirar){//no hace nada

}

}

if(e.getSource()==btnAceptar){

txtS.setText("");

}

}//fin de action performed

//METODOS PROPIOS

int aleatorio(int min,int max){

return (int)((max-min+1)*Math.random()+min);

}

//PANEL MUESTRA_CREDITO

void procesarCredito(double numero){

String num=numero +"0";

limpiar();

int pos=0;

char caracter;

for(int i=num.length()-1;i>=0;i--){

caracter=num.charAt(i);

if(caracter=='.'){

lbl[pos].setIcon(new ImageIcon(getClass().getResource(

"im10.jpg")));

pos++;

}else{

lbl[pos].setIcon(new ImageIcon(getClass().getResource(

"im"+caracter+".jpg")));

pos++;

}

}//fin del for

}//fin de muestraCredito

//--

void limpiar(){

for(int i=0;i<10;i++){

lbl[i].setIcon(new ImageIcon(getClass().getResource(

"imSin.jpg")));

}

}

//--

void mostrarNada(){

for(int i=0;i<2;i++){

lbl[i]=new JLabel(new ImageIcon(getClass().getResource(

"im0.jpg")));

lbl[i].setBounds(91-i*11,0,11,19);

pnlTxtCredito.add(lbl[i]);

}

lbl[2]=new JLabel(new ImageIcon(getClass().getResource(

"im10.jpg")));//rep el punto

lbl[2].setBounds(77,0,3,19);

pnlTxtCredito.add(lbl[2]);

for(int i=3;i<10;i++){

lbl[i]=new JLabel(new ImageIcon(getClass().getResource(

"imSin.jpg")));

lbl[i].setBounds(99-i*11,0,11,19);

pnlTxtCredito.add(lbl[i]);

}

}//fin de mostarNada

//

//MUESTRA COINS

void procesarCoins(double numero){

String num=""+numero;

limpiar1();

int pos=0;

char caracter;

for(int i=num.length()-1;i>=0;i--){

caracter=num.charAt(i);

if(caracter=='.'){

lbl1[pos].setIcon(new ImageIcon(getClass().getResource(

"im10.jpg")));

pos++;

}else{

lbl1[pos].setIcon(new ImageIcon(getClass().getResource(

"im"+caracter+".jpg")));

pos++;

}

}//fin del for

}//fin de procesarCoins

//--

void limpiar1(){

for(int i=0;i<3;i++){

lbl1[i].setIcon(new ImageIcon(getClass().getResource(

"imSin.jpg")));

}

}

//--

void mostrarNada1(){

lbl1[0]=new JLabel(new ImageIcon(getClass().getResource("im0.jpg")));

lbl1[0].setBounds(14,0,11,19);

pnlTxtCoins.add(lbl1[0]);

lbl1[1]=new JLabel(new ImageIcon(getClass().getResource("im10.jpg")));

lbl1[1].setBounds(11,0,3,19);

pnlTxtCoins.add(lbl1[1]);

lbl1[2]=new JLabel(new ImageIcon(getClass().getResource("im0.jpg")));

lbl1[2].setBounds(0,0,11,19);

pnlTxtCoins.add(lbl1[2]);

}

//--

//MUESTRA_GANANCIA

void procesarGanancia(double numero){

String num=numero+"0";

limpiar2();

int pos=0;

char caracter;

for(int i=num.length()-1;i>=0;i--){

caracter=num.charAt(i);

if(caracter=='.'){

lbl2[pos].setIcon(new ImageIcon(getClass().getResource(

"im10.jpg")));

pos++;

}else{

lbl2[pos].setIcon(new ImageIcon(getClass().getResource(

"im"+caracter+".jpg")));

pos++;

}

}//fin del for

}//fin de procesarGanancia

//-

void limpiar2(){

for(int i=0;i<10;i++){

lbl2[i].setIcon(new ImageIcon(getClass().getResource(

"imSin.jpg")));

}//fin de for

}

//-

void mostrarNada2(){

for(int i=0;i<2;i++){

lbl2[i]=new JLabel(new ImageIcon(getClass().getResource(

"im0.jpg")));

lbl2[i].setBounds(91-i*11,0,11,19);

pnlTxtGanancia.add(lbl2[i]);

}

lbl2[2]=new JLabel(new ImageIcon(getClass().getResource(

"im10.jpg")));

lbl2[2].setBounds(77,0,3,19);

pnlTxtGanancia.add(lbl2[2]);

for(int i=3;i<10;i++){

lbl2[i]=new JLabel(new ImageIcon(getClass().getResource(

"imSin.jpg")));

lbl2[i].setBounds(99-i*11,0,11,19);

pnlTxtGanancia.add(lbl2[i]);

}

}

//--

void pasarCredito(){

//restamos 0.50 a moneda por cada presionada de boton "Apostar Uno"

moneda-=0.5;

//aumentamos 0.5 a la apuesta

coins+=0.5;

//solo puede apostarse 2.00 como m醲imo.validamos:

//Si la apuesta llega a 2.5

if(coins==2.5){

//entonces devolvemos los 2.5 a moneda

moneda+=2.50;

//y cambiamos cois a cero

coins=0.0;

}//fin de if

}//fin de pasarCredito

void pasarMaximoMonedas(){

for(double i=coins;i<2.0;i+=0.5){

coins+=0.5;

moneda-=0.5;

}

}

//--

void girar(){

//limpia el panel de ganancia

procesarGanancia(0);

//si los rodillos dejaron de girar

if( (girosRod1+girosRod2+girosRod3)==0){

//detiene el timer

lblGirando.setVisible(false);

timer.stop();

//AudioPlayer.player.stop(sonido1);

//String spin = "spin.wav";

//try {

//URL clipUrl = new URL("file:" + spin);

//AudioClip audioClip = Applet.newAudioClip("spin.wav");

//audioClip.play();

//Thread.currentThread().sleep(3000);

//} catch (Exception e) {

//e.printStackTrace();

//}

//comprueba los resultados

comprovarResultados(indRodillo1,indRodillo2,indRodillo3 );

}else{

//sonido1.loop();

//AudioPlayer.player.start (csonido1);

lblGirando.setVisible(true);

//Giran los rodillos seg鷑 la cantidad de rotaciones aleatorias

//verifica si falta rodar un rodillo

if(girosRod1>0){

//cambiar la imagen y almacenar el indice de la que se encuentra

indRodillo1=girarImagen(lblRod1,indRodillo1);

//decrementar el numero de rotaciones del rodillo

girosRod1--;

}

if(girosRod2>0){

//cambiar la imagen y almacenar el indice de la que se encuentra

indRodillo2=girarImagen(lblRod2,indRodillo2);

//decrementar el numero de rotaciones del rodillo

girosRod2--;

}

if(girosRod3>0){

//cambiar la imagen y almacenar el indice de la que se encuentra

indRodillo3=girarImagen(lblRod3,indRodillo3);

//decrementar el numero de rotaciones del rodillo

girosRod3--;

}

}//fin de else

}//fin del m閠odo girar

//-

void comprovarResultados(int var1,int var2,int var3 ){

String result=""+ var1+ var2+ var3;

//si sali?las tres imagenes bar*1

if(result.equals("222")){

//AudioPlayer.player.start(winBig);

//winBig.play();

moneda=moneda +coins*20;

procesarCredito(moneda);

procesarGanancia(coins*20);

imprimirTicket(20);

mensaje("ud. a ganado :"+coins*20);

coins=0;

procesarCoins(coins);

//si sali?las tres imagenes bar*2

}elseif(result.equals("444")){

//AudioPlayer.player.start(winBig);

//winBig.play();

moneda=moneda +coins*40;

procesarCredito(moneda);

procesarGanancia(coins*40);

imprimirTicket(40);

mensaje("ud. a ganado :"+coins*40);

coins=0;

procesarCoins(coins);

//si sali?las tres imagenes bar*3

}elseif(result.equals("888")){

//AudioPlayer.player.start(winBig);

//winBig.play();

moneda=moneda +coins*80;

procesarCredito(moneda);

procesarGanancia(coins*80);

imprimirTicket(80);

mensaje("ud. a ganado :"+coins*80);

coins=0;

procesarCoins(coins);

//si sali?las tres imagenes dolar

}elseif(result.equals("000")){

//AudioPlayer.player.start(winBig);

//winBig.play();

moneda=moneda +coins*1000;

procesarCredito(moneda);

procesarGanancia(coins*1000);

imprimirTicket(1000);

mensaje("ud. a ganado :"+coins*1000);

coins=0;

procesarCoins(coins);

//si sali?las tres imagenes cereza

}elseif(result.equals("666")){

//AudioPlayer.player.start(winBig);

//winBig.play();

moneda=moneda +coins*160;

procesarCredito(moneda);

procesarGanancia(coins*160);

imprimirTicket(106);

mensaje("ud. a ganado :"+coins*160);

coins=0;

procesarCoins(coins);

//si salieron 3 bares cualquiera

}elseif(

result.equals("224") || result.equals("228") ||

result.equals("242") || result.equals("244") ||

result.equals("248") ||result.equals("282") ||

result.equals("284") || result.equals("288") ||

result.equals("422") || result.equals("424") ||

result.equals("428") || result.equals("442") ||

result.equals("448") ||result.equals("482") ||

result.equals("484") || result.equals("488") ||

result.equals("822") || result.equals("824") ||

result.equals("828") ||result.equals("842") ||

result.equals("844") || result.equals("848") ||

result.equals("882") || result.equals("884")

){

//AudioPlayer.player.start(winBig);

//winBig.play();

moneda=moneda + coins*10;

procesarCredito(moneda);

procesarGanancia(coins*10);

mensaje("ud. a ganado :"+coins*10);

imprimirTicket(10);

coins=0;

procesarCoins(coins);

//si sale dos cerezas

}elseif(

result.matches("[6][6][0-9]")||

result.matches("[0-9][6][6]")||

result.matches("[6][0-9][6]")

){

//AudioPlayer.player.start(winBig);

//winBig.play();

moneda=moneda + coins*5;

procesarCredito(moneda);

procesarGanancia(coins*5);

imprimirTicket(5);

mensaje("ud. a ganado :"+coins*5);

coins=0;

procesarCoins(coins);

//si sale una cereza

}elseif( result.matches("[6][0-9][0-9]")||

result.matches("[0-9][6][0-9]")||

result.matches("[0-9][0-9][6]")

){

//AudioPlayer.player.start(winBig);

//winBig.play();

moneda=moneda + coins*2;

procesarCredito(moneda);

procesarGanancia(coins*2);

imprimirTicket(2);

mensaje("ud. a ganado :"+coins*2);

coins=0;

procesarCoins(coins);

}else{

coins=0;

procesarCoins(coins);

procesarGanancia(0);

}

}

//

int girarImagen(JLabel lblImagen,int indiceImagenActual){

// Si la imagen que se ve actualmente es la 鷏tima se

// debe mostrar la primera (0)

if( indiceImagenActual == 9){

indiceImagenActual = -1;

}

// Mostrar la siguiente imagen seg鷑 el indice actual

lblImagen.setIcon(arrImagenes.get(indiceImagenActual+1));

return indiceImagenActual+1;

}

//

void cargaImagenes(){

//Carga las im醙enes de los rodillos

for(int i=0; i<10; i++){

arrImagenes.add(new ImageIcon(

getClass().getResource("imag"+i+".png")

));

}

}

//

void imprimirTicket(int producto){

Date d =new Date();

txtS.setText("TRAGAMONEDAS \n");

txtS.append("CIBERTEC\n ");

txtS.append("******************************\n");

txtS.append("Gan?\t: S/. "+coins*producto +"\n");

txtS.append("Credito actual\t: S/. "+moneda +"\n");

txtS.append("****************************** \n");

txtS.append("Gracias por jugar \n ");

txtS.append(""+ sdf.format(d));

}

//--

void mensaje(String text1){

JOptionPane.showMessageDialog(this,text1,"Mensaje",1);

}

//

//METODOS PARA EVENTOS DE MOUSE-

//

publicvoid mousePressed(MouseEvent e){

if(e.getSource()==lblGirar){

lblGirar.setIcon(girarPush);

}

if(e.getSource()==lblApostUno){

lblApostUno.setIcon(apostarUnoPush);

}

if(e.getSource()==lblApostMax){

lblApostMax.setIcon(apuestaMaximaPush);

}

}

//

publicvoid mouseReleased(MouseEvent e){

if(e.getSource()==lblGirar){

lblGirar.setIcon(girarIn);

}

if(e.getSource()==lblApostUno){

lblApostUno.setIcon(apostarUnoIn);

}

if(e.getSource()==lblApostMax){

lblApostMax.setIcon(apuestaMaximaIn);

}

}

//

publicvoid mouseEntered(MouseEvent e){

if(e.getSource()==lblGirar){

lblGirar.setIcon(girarIn);

}

if(e.getSource()==lblApostMax){

lblApostMax.setIcon(apuestaMaximaIn);

}

if(e.getSource()==lblApostUno){

lblApostUno.setIcon(apostarUnoIn);

}

}

publicvoid mouseExited(MouseEvent e){

if(e.getSource()==lblGirar){

lblGirar.setIcon(girarOut);

}

if(e.getSource()==lblApostMax){

lblApostMax.setIcon(apuestaMaximaOut);

}

if(e.getSource()==lblApostUno){

lblApostUno.setIcon(apostarUnoOut);

//AudioPlayer.player.stop(betOne);

}

}

//

publicvoid mouseClicked(MouseEvent e){

//Se ejecuta al darle click al JLabel lblGirar

if(e.getSource()==lblGirar){

if(coins==0){

JOptionPane.showMessageDialog(this,"ingrese una moneda",

"Mensaje",1);

}elseif(moneda<0){

JOptionPane.showMessageDialog(this,"Recargue su tarjeta",

"Mensaje",1);

}else{

//mediante los numeros aleatorios generamos el n鷐ero de giros

//que dara cada rodillo

girosRod1=aleatorio(10,40);

girosRod2=aleatorio(girosRod1+10,girosRod1+40);

girosRod3=aleatorio(girosRod2+10,girosRod2+40);

//inicia el Timer

timer.start();

}

}//fin de btn girar

//boton Apostar Uno

if(e.getSource()==lblApostUno){

//AudioPlayer.player.start(betOne);

//betOne.play();

//si no se tiene credito muestra un mensaje

if(moneda<=0){

JOptionPane.showMessageDialog(this,"Recargue su tarjeta",

"Mensaje",1);

//si se tiene credito

}else{

pasarCredito();

procesarCoins(coins);

procesarCredito(moneda);

}

}//fin de apostar uno

//si se presiona el boton de apuesta m醲ima

if(e.getSource()==lblApostMax){

s.playBetMax();

//AudioPlayer.player.start(betMax);

//betMax.play();

//si tiene 2 o mas soles se puede efectuar la apuesta maxima

if(moneda>=2){

pasarMaximoMonedas();

procesarCoins(coins);

procesarCredito(moneda);

}//sino se muestra un mensaje

else{

JOptionPane.showMessageDialog(this,

"No cuenta con cr閐ito suficiente para efectuar una"+

"apuesta m醲ima ","Mensaje",1);

}

}//fin de apuesta m鄕ima

}//fin de public

}//fin de la clase

and my class Sonido:

import java.net.URL;

import java.io.FileInputStream;

import sun.audio.*;

publicclass Sonido{

public AudioData spinData,betOneData,betMaxData,winBigData;

public AudioDataStream spinStream, betOneStream, betMaxStream, winBigStream ;

public ContinuousAudioDataStream continuousSpinStream,continuousBetOneStream,continuousBetMaxStream,continuousWinBigStream;

staticint length;

public Sonido (URL url)throws java.io.IOException{//ITS ALL CORRECTLY? WHERE I HAVE TO PUT THE URL CLASSES/"FILE.WAV"

spinData =new AudioStream (url.openStream()).getData();

betOneData =new AudioStream (url.openStream()).getData();

betMaxData =new AudioStream (url.openStream()).getData();

winBigData =new AudioStream (url.openStream()).getData();

spinStream =null;

betOneStream =null;

betMaxStream =null;

winBigStream =null;

continuousSpinStream =null;

continuousBetOneStream =null;

continuousBetMaxStream =null;

continuousWinBigStream =null;

}

public Sonido (String Spin,String WinBig,String BetOne,String BetMax )throws java.io.IOException{

FileInputStream spin =new FileInputStream (Spin);

FileInputStream winBig =new FileInputStream (WinBig);

FileInputStream betOne =new FileInputStream (BetOne);

FileInputStream betMax =new FileInputStream (BetMax);

AudioStream spinStream =new AudioStream (spin);

AudioStream betOneStream =new AudioStream (winBig);

AudioStream betMaxStream =new AudioStream (betOne);

AudioStream winBigStream =new AudioStream (betMax);

spinData = spinStream.getData();

betOneData = betOneStream.getData();

betMaxData = betMaxStream.getData();

winBigData = winBigStream.getData();

spinStream =null;

betOneStream =null;

betMaxStream =null;

winBigStream =null;

continuousSpinStream =null;

continuousBetOneStream =null;

continuousBetMaxStream =null;

continuousWinBigStream =null;

}

publicvoid playSpin(){

spinStream =new AudioDataStream (spinData);

AudioPlayer.player.start (spinStream);

}

publicvoid loopSpin(){

continuousSpinStream =new ContinuousAudioDataStream (spinData);

AudioPlayer.player.start (continuousSpinStream);

}

publicvoid stopSpin(){

if (spinStream !=null)

AudioPlayer.player.stop (spinStream);

if (continuousSpinStream !=null)

AudioPlayer.player.stop (continuousSpinStream);

}

publicvoid playBetOne(){

betOneStream =new AudioDataStream (betOneData);

AudioPlayer.player.start (betOneStream);

}

publicvoid loopBetOne(){

continuousBetOneStream =new ContinuousAudioDataStream (betOneData);

AudioPlayer.player.start (continuousBetOneStream);

}

publicvoid stopBetOne(){

if (betOneStream !=null)

AudioPlayer.player.stop (betOneStream);

if (continuousBetOneStream !=null)

AudioPlayer.player.stop (continuousBetOneStream);

}

publicvoid playBetMax(){

betMaxStream =new AudioDataStream (betMaxData);

AudioPlayer.player.start (betMaxStream);

}

publicvoid loopBetMax(){

continuousSpinStream =new ContinuousAudioDataStream (spinData);

AudioPlayer.player.start (continuousSpinStream);

}

publicvoid stopBetMax(){

if (betMaxStream !=null)

AudioPlayer.player.stop (betMaxStream);

if (continuousBetMaxStream !=null)

AudioPlayer.player.stop (continuousBetMaxStream);

}

publicvoid playWinBig (){

winBigStream =new AudioDataStream (winBigData);

AudioPlayer.player.start (winBigStream);

}

publicvoid loopWinBig (){

continuousWinBigStream =new ContinuousAudioDataStream (spinData);

AudioPlayer.player.start (continuousWinBigStream);

}

publicvoid stopWinBig (){

if (winBigStream !=null)

AudioPlayer.player.stop (winBigStream);

if (continuousWinBigStream !=null)

AudioPlayer.player.stop (continuousWinBigStream);

}

//public static void main (String args[]) throws Exception {

//URL url1 = new URL ("http://localhost:8080/audio/1.au");

//URL url2 = new URL ("http://localhost:8080/audio/2.au");

//PruebaSonido sac1 = new PruebaSonido (url1);

//PruebaSonido sac2 = new PruebaSonido (url2);

//PruebaSonido sac3 = new PruebaSonido ("1.au");

//sac1.play ();

//sac2.loop ();

//sac3.play ();

//try {// Delay for loop

//Thread.sleep (2000);

//} catch (InterruptedException ie) {}

//sac2.stop();

//}

}

uhmmmmmm that's all someone know why dont play my .wav files? thanks a lot

[54166 byte] By [iTzAngela] at [2007-11-26 18:08:05]
# 1
Go to line 816 in your PnlSimulacion.java and see what happens there. Some object reference is null there and you're trying to invoke a method on it.
-Kayaman-a at 2007-7-9 5:39:39 > top of Java-index,Java Essentials,Java Programming...
# 2

> Exception in thread "AWT-EventQueue-0"

> java.lang.NullPointerException

> at

> PnlSimulacion.mouseClicked(PnlSimulacion.java:816)

The above line of the stack trace shows where the error is. That line relates to the following line of source code in the mouseClicked method.:

> s.playBetMax();

This usually means that a valid value has never been assigned to variable s. Unassigned Member variables which refer to objects default to null and you are therefore calling playBetMax on a null reference. This is what causes your NPE. I scanned your code quickly and couldn't find anywhere where s is assigned to.

Graeme

GraemeHooka at 2007-7-9 5:39:39 > top of Java-index,Java Essentials,Java Programming...
# 3

> > Exception in thread "AWT-EventQueue-0"

> > java.lang.NullPointerException

> > at

> > PnlSimulacion.mouseClicked(PnlSimulacion.java:816)

>

> The above line of the stack trace shows where the

> error is. That line relates to the following line of

> source code in the mouseClicked method.:

>

> > s.playBetMax();

>

> This usually means that a valid value has never been

> assigned to variable s. Unassigned Member variables

> which refer to objects default to null and you are

> therefore calling playBetMax on a null reference.

> This is what causes your NPE. I scanned your code

> quickly and couldn't find anywhere where s is

> assigned to.

>

>

> Graeme

I think that is assigned up like this:

//referencia al frame

Public Sonido s;

Message was edited by:

iTzAngel

iTzAngela at 2007-7-9 5:39:39 > top of Java-index,Java Essentials,Java Programming...
# 4
public Sonido s; // <-- THIS COULD BE THE ERROR?yes, maybe it should be like thispublic Sonido s = new Sonido();
sjs1985a at 2007-7-9 5:39:39 > top of Java-index,Java Essentials,Java Programming...
# 5
Cannot find Constructor Sonido ... could be because the constructor of the class Sonido is not like this?
iTzAngela at 2007-7-9 5:39:39 > top of Java-index,Java Essentials,Java Programming...
# 6

> I think that is assigned up like this:

> //referencia al frame

> Public Sonido s;

Nope, that's where it is declared, somewhere you need to do either:

s = new Sonido();

Or as sjs1985 said:

public Sonido s = new Sonido();

Graeme

GraemeHooka at 2007-7-9 5:39:39 > top of Java-index,Java Essentials,Java Programming...
# 7
> Cannot find Constructor Sonido ... could be because> the constructor of the class Sonido is not like this?Sorry, missed that, then you need to either use one of the existing constructors or add a new one.Graeme
GraemeHooka at 2007-7-9 5:39:39 > top of Java-index,Java Essentials,Java Programming...
# 8

> > I think that is assigned up like this:

> > //referencia al frame

> > Public Sonido s;

>

> Nope, that's where it is declared, somewhere you need

> to do either:

> > s = new Sonido();

>

> Or as sjs1985 said:

> > public Sonido s = new Sonido();

>

>

> Graeme

I put equals you say me, but the BuildOutput says:

cannot find symbol constructor Sonido();

maybe it have something in class Sonido?

iTzAngela at 2007-7-9 5:39:39 > top of Java-index,Java Essentials,Java Programming...
# 9
are you very new to Java? Maybe you should go through the tutorials first. Of course you need to somehow properly construct your Sonido object. Whether it be with a correct constructor or a factory method.
-Kayaman-a at 2007-7-9 5:39:39 > top of Java-index,Java Essentials,Java Programming...
# 10

in the tutorial the code of the class Sonido is like this:, i cant find a constructor, you can?

import java.net.URL;

import java.io.FileInputStream;

import sun.audio.*;

public class SunAudioClip {

private AudioData audiodata;

private AudioDataStream audiostream;

private ContinuousAudioDataStream continuousaudiostream;

static int length;

public SunAudioClip (URL url) throws java.io.IOException {

audiodata = new AudioStream (url.openStream()).getData();

audiostream = null;

continuousaudiostream = null;

}

public SunAudioClip (String Spin) throws java.io.IOException {

FileInputStream fis = new FileInputStream (Spin);

AudioStream audioStream = new AudioStream (fis);

audiodata = audioStream.getData();

audiostream = null;

continuousaudiostream = null;

}

public void play () {

audiostream = new AudioDataStream (audiodata);

AudioPlayer.player.start (audiostream);

}

public void loop () {

continuousaudiostream = new ContinuousAudioDataStream (audiodata);

AudioPlayer.player.start (continuousaudiostream);

}

public void stop () {

if (audiostream != null)

AudioPlayer.player.stop (audiostream);

if (continuousaudiostream != null)

AudioPlayer.player.stop (continuousaudiostream);

}

public static void main (String args[]) throws Exception {

URL url1 = new URL ("http://localhost:8080/audio/1.au");

URL url2 = new URL ("http://localhost:8080/audio/2.au");

SunAudioClip sac1 = new SunAudioClip (url1);

SunAudioClip sac2 = new SunAudioClip (url2);

SunAudioClip sac3 = new SunAudioClip ("1.au");

sac1.play ();

sac2.loop ();

sac3.play ();

try {// Delay for loop

Thread.sleep (2000);

} catch (InterruptedException ie) {}

sac2.stop();

}

}

iTzAngela at 2007-7-9 5:39:39 > top of Java-index,Java Essentials,Java Programming...
# 11

> in the tutorial the code of the class Sonido is like

> this:, i cant find a constructor, you can?

public SunAudioClip (URL url) throws java.io.IOException

// ... and

public SunAudioClip (String Spin) throws java.io.IOException

Are both constructors.

GraemeHooka at 2007-7-9 5:39:39 > top of Java-index,Java Essentials,Java Programming...
# 12
uhm well, I'm learning, i supose that i have to references with both?, sorry but if i have to references both constructors, how can i call the method playBetOne, or playSpin, ? pls help meMessage was edited by: iTzAngel
iTzAngela at 2007-7-9 5:39:39 > top of Java-index,Java Essentials,Java Programming...
# 13
anybody know?
iTzAngela at 2007-7-9 5:39:39 > top of Java-index,Java Essentials,Java Programming...
# 14
No, you use any one of the constructors to create your object and then call those methods on it.You need to choose the most suitable constructor for you.Seriously, you should read some of the more basic tutorials first to understand what a constructor is.
-Kayaman-a at 2007-7-9 5:39:39 > top of Java-index,Java Essentials,Java Programming...
# 15

I know that a constructor is the part of the class where the variables declared are asigned, but i never seen a constructor like this :s

well I try it and this the consecuense:

URL url1 = new URL ("http://recursos.cnice.mec.es/bancoimagenes/contenidos/sonidos01/CD02/wav/eb00281.wav");

s = new Sonido(url1);

BuildOut says : unreported exception, i think that it needs a IO.Exception and a Malformed URL Exception like a try catch, but how to put it in another out class thats not is the main Sonido.java

Some here one know how validate or manage an IO.Exception and a MalFormedUrl?

Message was edited by:

iTzAngel

iTzAngela at 2007-7-21 17:15:42 > top of Java-index,Java Essentials,Java Programming...
# 16

try {

URL url1 = new URL("http://recursos.cnice.mec.es/bancoimagenes/contenidos/sonidos01/CD02/wav/eb00281.wav");

s = new Sonido(url1);

} catch(IOException e) {

e.printStackTrace();

} catch(MalformedURLException e) {

e.printStackTrace();

}

When are you gonna read the basics? You can't start learning Java from the middle.

-Kayaman-a at 2007-7-21 17:15:42 > top of Java-index,Java Essentials,Java Programming...
# 17

sorry for all? can u help me a little more?

java.net.MalformedURLException: unknown protocol: c

at java.net.URL.<init>(URL.java:574)

at java.net.URL.<init>(URL.java:464)

at java.net.URL.<init>(URL.java:413)

at PnlSimulacion.mouseClicked(PnlSimulacion.java:816)

at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:21

1)

at java.awt.Component.processMouseEvent(Component.java:5491)

at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)

at java.awt.Component.processEvent(Component.java:5253)

at java.awt.Container.processEvent(Container.java:1966)

at java.awt.Component.dispatchEventImpl(Component.java:3955)

at java.awt.Container.dispatchEventImpl(Container.java:2024)

at java.awt.Component.dispatchEvent(Component.java:3803)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212

)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3901)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)

at java.awt.Container.dispatchEventImpl(Container.java:2010)

at java.awt.Window.dispatchEventImpl(Window.java:1774)

at java.awt.Component.dispatchEvent(Component.java:3803)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh

read.java:242)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre

ad.java:163)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

at PnlSimulacion.mouseClicked(PnlSimulacion.java:824)

at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:21

1)

at java.awt.Component.processMouseEvent(Component.java:5491)

at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)

at java.awt.Component.processEvent(Component.java:5253)

at java.awt.Container.processEvent(Container.java:1966)

at java.awt.Component.dispatchEventImpl(Component.java:3955)

at java.awt.Container.dispatchEventImpl(Container.java:2024)

at java.awt.Component.dispatchEvent(Component.java:3803)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212

)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3901)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)

at java.awt.Container.dispatchEventImpl(Container.java:2010)

at java.awt.Window.dispatchEventImpl(Window.java:1774)

at java.awt.Component.dispatchEvent(Component.java:3803)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh

read.java:242)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre

ad.java:163)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

I this it need a protocol specified in the class URL?

because with a URL from Internet works : ) , but with a local not , like this:

"C:/Documents and Settings/angel/Escritorio/Tragamoneda V1.0/Tragamoneda V1.0/BetMax.wav"

Message was edited by:

iTzAngel

Message was edited by:

iTzAngel

iTzAngela at 2007-7-21 17:15:42 > top of Java-index,Java Essentials,Java Programming...
# 18
Yes, you need to put the file:/// protocol for local files.Or check out the other constructor, didn't that take a String instead of an URL?
-Kayaman-a at 2007-7-21 17:15:42 > top of Java-index,Java Essentials,Java Programming...
# 19

like this right? : )

if(e.getSource()==lblApostMax){

try {

URL url1 = new URL("file:C:/Documents and Settings/angel/Escritorio/Tragamoneda V1.0/Tragamoneda V1.0/Tragamoneda/classes/BetMax.wav");

s = new Sonido(url1);

} catch(IOException a) {

a.printStackTrace();

}

//catch(MalformedURLException a) {

//a.printStackTrace();

//}

s.playBetMax ();

try {// Delay for loop

Thread.sleep (2000);

} catch (InterruptedException ie) {}

//AudioPlayer.player.start(betMax);

//betMax.play();

//si tiene 2 o mas soles se puede efectuar la apuesta maxima

if(moneda>=2){

pasarMaximoMonedas();

procesarCoins(coins);

procesarCredito(moneda);

}//sino se muestra un mensaje

else{

JOptionPane.showMessageDialog(this,

"No cuenta con crdito suficiente para efectuar una"+

"apuesta mxima ", "Mensaje",1);

}

}//fin de apuesta mxima

thanks for all these days I will read the tutorials i need it, thanks again!.

iTzAngela at 2007-7-21 17:15:42 > top of Java-index,Java Essentials,Java Programming...