?? digitalclock.java
字號:
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class DigitalClock extends JFrame {
WatchPanel watch = new WatchPanel();
public DigitalClock() {
super("Digital Clock");
setSize(345, 60);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel();
pane.setLayout(new GridLayout(1, 1, 15, 15));
pane.add(watch);
setContentPane(pane);
show();
}
public static void main(String[] arguments) {
DigitalClock clock = new DigitalClock();
}
}
class WatchPanel extends JPanel implements Runnable {
Thread runner;
WatchPanel() {
if (runner == null) {
runner = new Thread(this);
runner.start();
}
}
public void run() {
while (true) {
repaint();
try {
Thread.sleep(1000);
} catch (InterruptedException e) { }
}
}
public void paintComponent(Graphics comp) {
Graphics2D comp2D = (Graphics2D)comp;
Font type = new Font("Serif", Font.BOLD, 24);
comp2D.setFont(type);
comp2D.setColor(getBackground());
comp2D.fillRect(0, 0, getSize().width, getSize().height);
GregorianCalendar day = new GregorianCalendar();
String time = day.getTime().toString();
comp2D.setColor(Color.black);
comp2D.drawString(time, 5, 25);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -