用Thread.currentThread().sleep(1000)
试试看
试试看
解决方案 »
- 有谁用Swt Designer的吗?我用的是6.7,新建JFrame总会生成N多代码,大家帮我分析下。
- 帮忙看一句代码,这是向上转型么?怎么样才能向上转型?
- 郁闷的环境变量问题
- 500分求解一个简单的按钮弹出窗口问题!
- JTextField 侦听文本改变时间,出现:java.lang.IllegalStateException: Attempt to mutate in notification异常,帮帮我,急死了!
- 哪位有连接池的源代码,大的小的都无所谓。刚才网上搜了一下,没找到。顺便散点分,呵呵
- 拜求一个统计的SQL
- 在树里加CHECKBOX
- 请问在java应用程序中,如何处理报表问题?(报表同样要求跨平台)
- 各位大佬能不能教教我关于access token方面的知识啊!!!
- 求助 applet为什么找不到class
- 我初始化了两个PANEL(a和b),我想一点a中的按钮,b中就增加一个按钮,可。。。做不到。
public void ShowTime(){
int min=Integer.parseInt(thetime);while(min>0)
{
try{Thread.sleep(6000);}
catch(InterruptedException ee){System.out.println("erro"+ee);}
min=min-1;
Stime.setText(String.valueOf(min));
}
}
这是在init中的(节选)Stime=new JTextField(20); JButton Ok = new JButton("試験開始");
Ok.setBackground(hyel);
Ok.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
if(flg==0)
{
CenterPanel.setVisible(true);
ShowTime();flg=1;
}
else
。
}
}); 运行的时候,在文本理不显示时间,只有全运行完以后才显示为0!郁闷,不知应再怎么写!
是你没有刷新控件的显示
调用整个 CenterPanel.validate()或者CenterPanel.repaint()
方法试试
int min=Integer.parseInt(thetime); while(min>45)
{
try{
Stime.setText(String.valueOf(min));
CenterPanel.repaint();
Thread.currentThread().sleep(1000);
}
catch(InterruptedException ee){System.out.println("erro"+ee);}
min=min-1;
}
}我这么做的,也不好用!
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;public class a extends JFrame{
private JButton btn_start = new JButton("Start");
private JLabel lbl_time = new JLabel("??婍");
private int min = 10;
public a()
{
setSize(400,300);
getContentPane().add(btn_start,BorderLayout.NORTH);
getContentPane().add(lbl_time,BorderLayout.CENTER);
btn_start.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Thread runner = new Thread()
{
public void run()
{
showTime();
}
};
runner.start();
}
});
}
public static void main(String agrs[]){
a test = new a();
test.show();
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void showTime()
{
while(min>0)
{
try
{
Thread.sleep(1000);
}
catch(InterruptedException ee)
{
System.out.println("erro"+ee);
}
min=min-1;
lbl_time.setText(String.valueOf(min));
getContentPane().validate();
}
}
}