Java таймер Swing

Вы должны иметь возможность приводить null к любому из них, так же, как к переменной Func((Class1)null).

9
задан stealthjong 9 October 2014 в 11:02
поделиться

3 ответа

Your task likely only needs to report results on the event thread (EDT) but do the actual work in a background thread at some periodic rate.

ScheduledExecutorService is EXACTLY what you want. Just remember to update the state of your UI on the EDT via SwingUtility.invokeLater(...)

1
ответ дан 4 December 2019 в 09:14
поделиться

У меня работает эта простая программа:

import java.awt.event.*;
import javax.swing.*;

public class Test {
    public static void main(String [] args) throws Exception{
        ActionListener taskPerformer = new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                //...Perform a task...

                System.out.println("Reading SMTP Info.");
            }
        };
        Timer timer = new Timer(100 ,taskPerformer);
        timer.setRepeats(false);
        timer.start();

        Thread.sleep(5000);
    }
}
18
ответ дан 4 December 2019 в 09:14
поделиться

I'm guessing from the log statement that you're doing some sort of SMTP operation. I think I'm right in saying the java.swing.Timer is intended for UI related timed operations, hence why it needs and EDT running. For more general operations you should use java.util.Timer.

This article is linked from the JavaDocs - http://java.sun.com/products/jfc/tsc/articles/timer/

1
ответ дан 4 December 2019 в 09:14
поделиться
Другие вопросы по тегам:

Похожие вопросы: