test.java

来自「《Java2图形设计卷II:Swing》配套光盘源码」· Java 代码 · 共 42 行

JAVA
42
字号
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Test implements ActionListener {
	private boolean firstRing = true;
	private int ring = 1;

	public Test() {
		Timer.setLogTimers(true);

		Timer oneSecondTimer = new Timer(1000, this);

		// comment out the following line for colaescing
		oneSecondTimer.setCoalesce(false);

		System.out.println("Timer is coalescing: " + 
							oneSecondTimer.isCoalesce());

		oneSecondTimer.start();
	}
	public void actionPerformed(ActionEvent e) {
		System.out.println("ring #" + ring++);

		if(firstRing) {
			// simulate a time consuming operation by sleeping
			// for 10 seconds ...
			try {
				Thread.currentThread().sleep(10000);
			}
			catch(InterruptedException ex) {
				ex.printStackTrace();
			}
			firstRing = false;
		}
	}
	public static void main(String args[]) {
		new Test();
		while(true);
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?