ex_20a.java

来自「JAVA分布式程序学习的课件(全英文)」· Java 代码 · 共 41 行

JAVA
41
字号
// Based on Holmes
// chap_11\Ex_8.java
// applet to demonstrate the need for threads when
// continuously repainting a window

import java.applet.*;
import java.awt.*;
import java.util.*;

public class Ex_20a extends Applet
{
	Font font = new Font("Monospaced",Font.BOLD,16);

	int hours, mins, secs;
	
	// override the start method, to calculate the time of day
	// and call the repaint() method to display the time
	public void start()
	{
		while (true)
		{
			Calendar time=Calendar.getInstance();

			hours = time.get(Calendar.HOUR);
			mins = time.get(Calendar.MINUTE);
			secs = time.get(Calendar.SECOND);	

			repaint();
		}
	}
	
	// display the time of day on the screen
	public void paint(Graphics g)
	{
		g.setFont(font);
		g.drawString(String.valueOf(hours)+":"+
			          String.valueOf(mins)+":"+
					    String.valueOf(secs),50,50);
	}
}

⌨️ 快捷键说明

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