import javax.swing.*;
import java.awt.*;
class Anuncio extends JLabel
{
String texto;
String link;
public Anuncio(String _texto)
{
this(_texto, "");
}
public Anuncio(String _texto, String _link)
{
super(_texto);
texto = _texto;
link = _link;
setForeground(Color.white);
setPreferredSize(new Dimension (120, 30));
ControlAnuncio controlador = new ControlAnuncio(this);
controlador.start();
}
}
class ControlAnuncio extends Thread
{
Anuncio anuncio;
public ControlAnuncio(Anuncio _anuncio)
{
anuncio = _anuncio;
}
public void run()
{
int tamTotal = anuncio.texto.length();
byte[] letras = anuncio.texto.getBytes();
int inicio=0;
String cabecera, cola;
do {
try {
sleep(300);
} catch(InterruptedException ie) {
System.err.println("Capturada InterruptedException en run de Anuncio: "+ie);
}
cabecera = new String(letras, inicio, tamTotal-inicio);
cola = new String(letras, 0, inicio);
anuncio.setText(cabecera + cola);
inicio++;
if (inicio > tamTotal)
{
inicio = 0;
try {
sleep(4000);
} catch(InterruptedException ie) {
System.err.println("Capturada InterruptedException en run de Anuncio: "+ie);
}
}
}while (true);
}
}