J
jtl.zheng
I want to set the button's text every second
as: 1 -> 2 -> 3 -> 4 .........
my code is:
------------------------------------
public class Ooop {
public static void doIt() {
JFrame jFrame = new JFrame();
JButton jButton = new JButton("xxx");
jFrame.add(jButton);
jFrame.pack();
jFrame.setVisible(true);
int i=0;
while(true){
try {
Thread.sleep(1000);
}
catch (InterruptedException ex) {
}
jButton.setText(String.valueOf(i++));
}
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
doIt();
}
});
}
}
-------------------------------
I use Thread.sleep() to do it
but it can not work....
It show nothing all the time
just a blank frame, not button at all
why? is it about the Thread the UI using?
how can I reset the text fo button every second?
Thank you very much in advance.
as: 1 -> 2 -> 3 -> 4 .........
my code is:
------------------------------------
public class Ooop {
public static void doIt() {
JFrame jFrame = new JFrame();
JButton jButton = new JButton("xxx");
jFrame.add(jButton);
jFrame.pack();
jFrame.setVisible(true);
int i=0;
while(true){
try {
Thread.sleep(1000);
}
catch (InterruptedException ex) {
}
jButton.setText(String.valueOf(i++));
}
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
doIt();
}
});
}
}
-------------------------------
I use Thread.sleep() to do it
but it can not work....
It show nothing all the time
just a blank frame, not button at all
why? is it about the Thread the UI using?
how can I reset the text fo button every second?
Thank you very much in advance.