bueno estoy haciendo un reproductor, entonces el metodo que uso para dibujar el reproductor es este:
public void paintAudio(Graphics g){
//int indice = 0;
// Si no se ha podido cargar el audio, mostramos el error
if (error!=null && !error.equals("")){
g.setColor(0, 0, 0); // negro
g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL));
g.drawString("Se ha producido un error: ", getWidth()/2, getHeight()/2, Graphics.TOP | Graphics.HCENTER);
g.drawString(error, 0, (int) (getHeight() * .60), 0);
this.removeCommand(salir);
this.addCommand(atras);
playingAudio = false;
return;
}
g.setColor(0, 92, 255);
g.fillRect(0, PlayPause.getY()-5, getWidth(), getHeight()-PlayPause.getY());
g.fillRect(0, 0,getWidth(), (int) (getHeight() * .2)+Font.SIZE_SMALL+5);
PlayPause.paint(g);
Atras.paint(g);
Adelante.paint(g);
long tiempo = 0;
try {
tiempo = playerThread.player.getMediaTime() / 1000000L /*Constantes.SECS_TO_MICROSECS*/;
} catch (Exception e) {
//e.printStackTrace();
}
///
// Barra de progreso
int tamano = (((int) (getWidth()-((getWidth()*.2)*2))-1));
long longitud = 0;
if (duracion!=0){
longitud = tiempo * (tamano) / duracion;
}
g.setColor(0,112,0);//g.setColor(255,255,0);//amarillo
g.drawRect ((int) (getWidth() * .2), (int) (getHeight() * .2), (int) (getWidth()-((getWidth()*.2)*2)),8 );
g.setColor(255,255,0);//amarillo//g.setColor(0,112,0);//verde
g.fillRect ((int) (getWidth() * .2)+1,(int) (getHeight() * .2)+1 ,(int) longitud , 7);
//fin barra progreso
g.setColor(0, 0, 0); // negro
g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL));
g.drawString(ficheroActual, (int) (getWidth() * .5), (int) (getHeight() * .1), Graphics.TOP | Graphics.HCENTER);
g.drawString(long2time(tiempo), (int) (getWidth() *.1), (int) (getHeight() *.2)-Font.SIZE_SMALL/2, Graphics.TOP | Graphics.HCENTER);
g.drawString(long2time(duracion), (int) (getWidth()*.8)+5, (int) (getHeight() * .2)-Font.SIZE_SMALL/2, 0);
this.removeCommand(salir);
this.addCommand(atras);
}
en la parte
g.drawString(ficheroActual, (int) (getWidth() * .5), (int) (getHeight() * .1), Graphics.TOP | Graphics.HCENTER);
es donde muestro el nombre de la cancion, este metodo esta dentro de un metodo run que tiene un while:
public void run() {
Graphics g = getGraphics();
while (!stopped)
{
controles();
paintAudio(g)
try {
Thread.sleep(10);
} catch (Exception e) {
}
}
}