G
gast
Gast
Wieso funktioniert sowas eigentlich nicht, und wieso tuz das doch mit normalen Labels?
Code:
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Test
{
public static void main(String args[])
{
final JLabel text = new JLabel();
JButton knopf = new JButton("drück mich");
JFrame fenster = new JFrame();
fenster.setDefaultCloseOperation(3);
fenster.setSize(100, 100);
fenster.add(text);
fenster.add(knopf);
fenster.setLayout(new GridLayout(2, 1));
fenster.setVisible(true);
ActionListener al = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
for(int c=0; c<10; c++)
{
try{Thread.sleep(500);}
catch(InterruptedException ignore){}
text.setText(String.valueOf(c));
}
}
};
knopf.addActionListener(al);
}
}