Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 自动更新jtextfield_Java_Swing_Concurrency_Jtextfield_Event Dispatch Thread - Fatal编程技术网

Java 自动更新jtextfield

Java 自动更新jtextfield,java,swing,concurrency,jtextfield,event-dispatch-thread,Java,Swing,Concurrency,Jtextfield,Event Dispatch Thread,有人知道如何每5秒钟更新一次jTextfield吗?自动的。因此不需要用户输入。它用于更新文本字段中的时间。这是我尝试过的,但后来我的程序冻结了 while(true){ Thread.sleep(1000); txtCheck.setText(convert.getCheck()); System.out.println("Ja");

有人知道如何每5秒钟更新一次jTextfield吗?自动的。因此不需要用户输入。它用于更新文本字段中的时间。这是我尝试过的,但后来我的程序冻结了

while(true){
                        Thread.sleep(1000);
                        txtCheck.setText(convert.getCheck());
                        System.out.println("Ja");
                        }
convert是一个线程,我试图抛出一个异常,但失败了,因为Eclise说线程不能抛出异常

Convert.getCheck:

    public String getCheck() {
        return check;
    }

您希望使用Swing计时器对象。这是一个

首先,您需要让类实现ActionListener接口。在类内部,还需要实现actionPerformed()方法。最后,应该在main()函数或其他地方启动计时器

timer = new Timer(5000, MyClass);
timer.setInitialDelay(pause);
timer.start();
然后,您将实现您的类,如:

public class MyClass implements ActionListener
{
   ...

   void actionPerformed(ActionEvent e) {
       /*
        This is called every time the timer fires, put your code here
       */
   }
 }

您希望使用Swing计时器对象。这是一个

首先,您需要让类实现ActionListener接口。在类内部,还需要实现actionPerformed()方法。最后,应该在main()函数或其他地方启动计时器

timer = new Timer(5000, MyClass);
timer.setInitialDelay(pause);
timer.start();
然后,您将实现您的类,如:

public class MyClass implements ActionListener
{
   ...

   void actionPerformed(ActionEvent e) {
       /*
        This is called every time the timer fires, put your code here
       */
   }
 }

您正在显示的while循环在哪里?在main()中,在JFrame中,在JPanel中?您正在显示的while循环在哪里?在main()中,在JFrame中,在JPanel中?非常感谢!工作完美!非常感谢你!工作完美!