Test Foro de elhacker.net SMF 2.1

Programación => Programación General => Java => Mensaje iniciado por: Afsoon en 2 Noviembre 2010, 17:07 PM

Título: Error JProgressBar [SOLUCIONADO]
Publicado por: Afsoon en 2 Noviembre 2010, 17:07 PM
El error es cuando creó la clase para crear el constructor para el incremento de la Bar que el Eclipse me dice que esta mal el <nameclass>.setValue(i) y cuando llamo al constructor y le paso por variable la barra, aquí esta el código:

Código (java) [Seleccionar]

public class SplashWindow extends JFrame{
private JLabel splash;
private threadProgress thread;

public SplashWindow() {
super("");
//
this.WindowDefine();
//Here create the new thread
thread = new threadProgress(bar); //Error al declara la bara
thread.start();
this.setSize(248,300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
//Empty the memory
thread = null;

}
//There Define Window
public void WindowDefine(){
this.setLayout(new BorderLayout());
ImageIcon jpg = new ImageIcon(getClass().getResource("splash/EAL69-copia-copia-248x300.jpg"));
splash = new JLabel(jpg);
//Progress
JProgressBar bar = new JProgressBar();
bar.setBorderPainted(true);
bar.setForeground(new Color(30, 20, 15, 70));
bar.setStringPainted(true);
//Add component in the Layout
this.add(splash, BorderLayout.CENTER);
this.add(bar, BorderLayout.SOUTH);
}
//There create the pausa Thread
public void pausa (int mSeg){
try
{
Thread.sleep(mSeg);
}catch(Exception e)
{
showError(e);
}
}

public void showError(Exception e){
System.err.print(e);
}

//There a create increment in the Progress bar
class threadProgress extends Thread {

JProgressBar bar;

public threadProgress(JProgressBar bar)
{
super();
this.bar = bar;
}

public void run(){

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

threadProgress.setValue(i);//Error cuando declaro con setValue
pausa(10);
}
}


}

}


he probado declarar la barra al principio con

Código (java) [Seleccionar]

private JProgressBar bar;


pero lo de setValue no se como arreglarlo

Título: Re: Error JProgressBar
Publicado por: joelmanx en 2 Noviembre 2010, 17:12 PM

threadProgress.setValue(i);//Error cuando declaro con setValue
pausa(10);


el error esta, en que estas, llamando a un metodo que el thread no tiene.


bar.setValue(i);//Error cuando declaro con setValue
pausa(10);


listo!.
Título: Re: Error JProgressBar
Publicado por: Afsoon en 2 Noviembre 2010, 17:27 PM
Tío Gracias es que no lo veía jeje