Boa tarde, alguém poderia me tirar uma dúvida em Swing. Veja o código abaixo:
[code]import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
public class AppletTest extends JApplet implements ActionListener {
private static final long serialVersionUID = 1L;
private JButton button;
private JLabel label;
@Override
public void start() {
super.start();
this.button = new JButton("Testar");
this.label = new JLabel("Clique no botao");
this.button.addActionListener(this);
this.setLayout(new FlowLayout());
this.add(this.button);
this.add(this.label);
}
public void actionPerformed(final ActionEvent e) {
this.label.setText("Executando a acao");
try {
Thread.sleep(10000);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
this.label.setText("Ação executada");
}
}[/code]
Como fazer para que quando clicar no botão o texto seja atualizado e depois que o processamento for feito, nesse exemplo o Thread.sleed(), o texto seja modificado novamente?.
Nesse exemplo o texto só é modificado na tela ao final da operação.
Grato.