Oi pessoal,
A situação é a seguinte: quando clica no botao, cria instancia de uma nova classe q vai criar um laço. Quero q atualize o jframe de acordo com o valor do laço.
package teste;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionListener; // botao
import java.awt.event.ActionEvent;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import teste.global;
public class teste{
/**
* Creates a new instance of <code>tkd2</code>.
*/
JButton contadorBotao;
JLabel rotulo;
String strSoma;
public teste() {
}
public void addComponentToPane(Container pane)
{ // painel principal
pane.setLayout(new BorderLayout());
JPanel painel = new JPanel();
contadorBotao = new JButton("Contador");
rotulo = new JLabel("0");
painel.add(contadorBotao);
painel.add(rotulo);
pane.add(painel,BorderLayout.NORTH);
// AÇÃO BOTAO >
contadorBotao.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{ new soma();
System.out.println("Contador");
strSoma=Integer.toString(global.soma);
rotulo.setText(strSoma);
}
}
);
} // fim da classe addComponentToPane
private static void createAndShowGUI()
{
//Create and set up the window.
JFrame frame = new JFrame("Contador");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
teste demo = new teste();
demo.addComponentToPane(frame.getContentPane());
//Display the window.
frame.pack();
frame.setSize(500,200);
frame.setVisible(true);
}
public static void main(String[] args) {
// TODO code application logic here
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
a classe q cria o contador é essa…
package teste;
import teste.global;
public class soma {
public soma() {
// System.out.println("soma"+global.soma);
// ++global.soma;
// System.out.println("soma"+global.soma);
teste n = new teste();
for (int x=0;x<10;x++)
{
++global.soma;
try {Thread.sleep(1000);}
catch (InterruptedException e) {System.out.println("Erro no Intervalo Inicial"); }
System.out.println("soma"+global.soma);
}
}
}
e uma classe q é utilizada de forma global … de contador…
package teste;
public class global {
public static int soma;
public global() {
}
}
Se alguem puder ajudar… obrigado!