📄 ex_20a.java
字号:
// 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -