📄 timerdemo1.java
字号:
// TimerDemo1.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class TimerDemo1 extends JFrame
{
Timer timer;
int counter;
TimerDemo1 (String title)
{
super (title);
addWindowListener (new WindowAdapter ()
{
public void windowClosing (WindowEvent e)
{
System.exit (0);
}
});
ActionListener a = new ActionListener ()
{
public void actionPerformed (ActionEvent e)
{
System.out.println ("Counter = " +
counter);
if (++counter > 10)
{
timer.stop ();
System.exit (0);
}
}
};
timer = new Timer (300, a);
timer.start ();
pack ();
setVisible (true);
}
public static void main (String [] args)
{
new TimerDemo1 ("Timer Demo1");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -