《Java2图形设计卷II:Swing》配套光盘源码

源代码在线查看: test.java

软件大小: 4504 K
上传用户: guigong
关键词: Java2 Swing 图形 光盘
下载地址: 免注册下载 普通下载 VIP

相关代码

				import java.awt.*;
				import java.awt.event.*;
				import javax.swing.*;
				
				public class Test implements ActionListener {
					private int seconds=1;
				
					public Test() {
						Timer oneSecondTimer = new Timer(1000, this);
						Timer timerWithInitialDelay = new Timer(2000, 
												new TimerWithDelayListener());
						Timer oneTimeTimer = new Timer(10000, 
												new OneTimeListener());
				
						timerWithInitialDelay.setInitialDelay(5000);
						oneTimeTimer.setRepeats(false);
				
						oneSecondTimer.start();
						timerWithInitialDelay.start();
						oneTimeTimer.start();
					}
					public void actionPerformed(ActionEvent e) {
						if(seconds == 0)
							System.out.println("Time:  " + seconds + " second");
						else
							System.out.println("Time:  " + seconds + " seconds");
				
						seconds++;
					}
					public static void main(String args[]) {
						new Test();
						while(true);
					}
				}
				class TimerWithDelayListener implements ActionListener { 
					public void actionPerformed(ActionEvent e) {
						System.out.println("Timer with Delay Ringing");
					}
				}
				class OneTimeListener implements ActionListener { 
					public void actionPerformed(ActionEvent e) {
						System.out.println("One Time Timer Ringing");
					}
				}
							

相关资源