有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在swing之外使用swing计时器可以吗?

正如标题所说,在非swing应用程序中使用swing定时器是否可以接受

还是我最好用一个单独的线程来写我自己的

我不知道swing timer可能有什么缺点,但我倾向于使用已经存在的东西


共 (2) 个答案

  1. # 1 楼答案

    In general, we recommend using Swing timers rather than general-purpose timers for GUI-related tasks because Swing timers all share the same, pre-existing timer thread and the GUI-related task automatically executes on the event-dispatch thread. However, you might use a general-purpose timer if you don't plan on touching the GUI from the timer, or need to perform lengthy processing.

    文件:http://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html

    我建议使用util.Timer

  2. # 2 楼答案

    不,仅当您正在处理EDT时才使用Swing计时器。 除此之外,您还可以使用java.util.Timer

    而且,Swing定时器比util定时器慢,因为它们是为在GUI上工作而设计的