primero creamos una Jframe y luego importamos las siguientes librerias:
import java.util.Timer;
import java.util.TimerTask;
luego declaramos 4 variables
private Timer tiempo;
private TimerTask task;
private int indice = 0;
private int speed = 80;
luego ponemos los siguientes metodos:
public String texto() {
return "mensaje en la barra...";
}
void settexto(int i) {
this.setTitle(texto().substring(0, i));
}
public void startAnimation() {
tiempo = new Timer();
task = new TimerTask() {
public void run() {
if (indice == texto().length()) {
indice = 1;
} else {
indice++;
}
settexto(indice);
}
};
tiempo.schedule(task, 0, speed);
}
por ultimo llamos al metodo startAnimation() desde el construtor por defecto por ejemplo si tenemos que el iframe lo llamos vista
podemos llamar al metodo asi:
public vista() {
initComponents();
startAnimation();
}
y eso es todo al final quedara asi:
0 Comments