请教一个Jlabel闪动的问题 本帖最后由 poochuan 于 2011-10-03 16:42:40 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 class SetPercent implements Runnable { private JLabel label = null; private int percent = 0; public SetPercent(JLabel label){ this.label = label; } @Override public void run() { while (percent < 100){ synchronized (this.label){ this.label.setText(String.valueOf(++percent)); } try { Thread.sleep(250); } catch (InterruptedException ex) {} } } }new Thread(new SetPercent(this.jLabel1)).start(); 请问为什么还是不行呢,我改了下应该不影响,,烦请解答,谢谢import javax.swing.JLabel;public class SetPercent implements Runnable { private JLabel label = null; private String value = null; public SetPercent(JLabel label, String value) { this.label = label; this.value = value; } @Override public void run() { synchronized (this.label) { this.label.setText(String.valueOf(value)); } try { Thread.sleep(250); } catch (InterruptedException ex) { } }}我把程序改成了这样,我在调用时这样调用for (N n: ns) { new Thread(new SetPercent(status,"正在生成 :" + n.getName())).start(); }这样是不是我就开了多个实例不同步了 http://lanvis.blog.163.com/blog/static/26982162009798422547/ 只能开一个线程,然后在该线程中循环。如果Label的text不能自增长生成的话,可以从线程中访问外面的源变量的。 请问我能拿到那个线程吗,不好意思,我对线程没有太大的概念, 比如这样:Thread thread = new Thread(new SetPercent(status,"正在生成 :" + n.getName())).start();可以却报错, 请问我在外部需要怎么来调用呢,比如:我的for循环在外部,谢谢for (N n: ns) {//new Thread(new SetPercent(status,"正在生成 :" + n.getName())).start();} 大家在平时的开发中怎么处理四舍五入的问题。 如何通过ObjectInputStream判断由ObjectOutputStream写出的文件有没有对象? JTextArea.setCaretPosition()方法的应用问题? jexcelapi处理Excel的问题!......急! 怪事,谁见过啊 新手请教 数组的问题 寻找java源程序 高手请进!!!!!!!!!!!!!!!! 為什麼編譯程序老是提示goto有錯誤,請打下幫我分析 一个奇怪的问题,…… Swing布局请教,涉及GridBagLayout
private int percent = 0;
public SetPercent(JLabel label){
this.label = label;
}
@Override
public void run() {
while (percent < 100){
synchronized (this.label){
this.label.setText(String.valueOf(++percent));
}
try {
Thread.sleep(250);
} catch (InterruptedException ex) {}
}
}
}
new Thread(new SetPercent(this.jLabel1)).start();
private String value = null; public SetPercent(JLabel label, String value) {
this.label = label;
this.value = value;
} @Override
public void run() {
synchronized (this.label) {
this.label.setText(String.valueOf(value));
}
try {
Thread.sleep(250);
} catch (InterruptedException ex) {
} }}我把程序改成了这样,我在调用时这样调用for (N n: ns) {
new Thread(new SetPercent(status,"正在生成 :" + n.getName())).start();
}这样是不是我就开了多个实例不同步了
如果Label的text不能自增长生成的话,可以从线程中访问外面的源变量的。
请问我能拿到那个线程吗,不好意思,我对线程没有太大的概念, 比如这样:
Thread thread = new Thread(new SetPercent(status,"正在生成 :" + n.getName())).start();
可以却报错,
请问我在外部需要怎么来调用呢,比如:
我的for循环在外部,谢谢
for (N n: ns) {
//new Thread(new SetPercent(status,"正在生成 :" + n.getName())).start();}