📄 displayclock.java
字号:
// DisplayClock.java: Display a clock in a panel
import java.awt.*;
import javax.swing.*;
public class DisplayClock extends JFrame
{
// Main method with three auguments:
// args[0]: hour
// args[1]: minute
// args[2]: second
public static void main(String[] args)
{
// Declare hour, minute, and second values
int hour = 0;
int minute = 0;
int second = 0;
// Check usage and get hour, minute, second
if (args.length > 3)
{
System.out.println(
"Usage: java DisplayClock hour minute second");
System.exit(0);
}
else if (args.length == 3)
{
hour = new Integer(args[0]).intValue();
minute = new Integer(args[1]).intValue();
second = new Integer(args[2]).intValue();
}
else if (args.length == 2)
{
hour = new Integer(args[0]).intValue();
minute = new Integer(args[1]).intValue();
}
else if (args.length == 1)
{
hour = new Integer(args[0]).intValue();
}
// Create a frame to hold the clock
DisplayClock frame = new DisplayClock();
frame.setTitle("Display Clock");
frame.getContentPane().add(new DrawClock(hour, minute, second));
// frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 350);
frame.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -