oldwatch.java

来自「java21pro_source 21天学通java2全书源代码」· Java 代码 · 共 39 行

JAVA
39
字号
import java.awt.*;
import java.util.*;

public class OldWatch extends java.applet.Applet {
    private Color butterscotch = new Color(255, 204, 102);
    private String lastTime = "";
    Color back;

    public void init() {
        String in = getParameter("background");
        back = Color.black;
        if (in != null) {
            try {
                back = Color.decode(in);
            } catch (NumberFormatException e) {
                showStatus("Bad parameter " + in);
            }
        }
        setBackground(back);
    }

    public void paint(Graphics screen) {
        Font type = new Font("Monospaced", Font.BOLD, 20);
        screen.setFont(type);
        Date day = new Date();
        String time = day.toString();
        screen.setColor(back);
        screen.drawString(lastTime, 5, 25);
        screen.setColor(butterscotch);
        screen.drawString(time, 5, 25);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // do nothing
        }
        lastTime = time;
        repaint();
    }
}

⌨️ 快捷键说明

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