Java 程序:若干秒后显示帧
使用 Timer() 设置延迟秒数,例如:在若干秒后显示帧 -
Timer tm = new Timer(2000, new ActionListener() { // }
以下是一个在若干秒后显示帧的示例 -
package my; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.Timer; public class SwingDemo extends JFrame { private JFrame frame = new JFrame(); public SwingDemo() { frame.setSize(550, 300); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.setVisible(true); frame.setExtendedState(JFrame.ICONIFIED); Timer tm = new Timer(2000, new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { frame.setExtendedState(JFrame.NORMAL); } }); } }); tm.setRepeats(false); tm.start(); } public static void main(String[] args) { new SwingDemo(); } }
输出如下所示,显示 2 秒后出现帧 -
输出
广告