Galera,
Preciso implementar em minha app. swing uma área capaz de visualizar banners. Consegui uma classe que implementa um browser e resolvi parcialmente meu problema. O q acontece é q preciso trocar de página de 20 em 20 segundos e para isso estou usando SwingWorker:// Implementa a troca e atualização de notícias
SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// Se não houver notícias, seta uma default
if (listaNoticias.size() == 0) {
webBrowser.setURL("http://www.xxxxxxx.com.br");
} else {
while (true) {
trocaNoticias();
}
}
}
});
return null;
}
@Override
public void done() {
webBrowserPanel.validate();
webBrowserPanel.repaint();
}
};
/*
* Efetua a troca de tempos em tempos entre as notícias da listaNoticias
*/
private synchronized void trocaNoticias() {
final int timeTrocaNot = 5000; // Tempo de troca das notícias
long timeAtualizNot = 0; // Tempo para atualização das noticias
for (int i = 0; i < listaNoticias.size(); i++) {
try {
System.out.println("******> Entrou");
webBrowser.setURL("http://" + listaNoticias.get(i).getUrl());
System.out.println("******> Conte 20 seg");
Thread.sleep(timeTrocaNot);
System.out.println("******> Atualiza");
System.out.println("********************************************");
} catch (Exception e) {
e.printStackTrace();
break;
}
}
}