-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClockSave.java
54 lines (48 loc) · 1.24 KB
/
ClockSave.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* @(#)ClockSave.java
*
*
* @author
* @version 1.00 2019/12/1
*/
package clock;
import java.io.IOException;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
public class ClockSave {
public static void main(String[] args){
if(args.length <3 || args.length >4){
System.out.println("Bad usage: Should be clock.clockSave filename width height [HH:mm:ss]");
return;
}
int h, w;
try{
w = Integer.parseInt(args[1]);
h = Integer.parseInt(args[2]);
}
catch(NumberFormatException e){
System.out.println("Bad usage: Should be clock.clockSave filename width height [HH:mm:ss]");
return;
}
LocalTime time;
if(args.length == 4){
try{
DateTimeFormatter df = DateTimeFormatter.ofPattern("HH:mm:ss");
time = LocalTime.parse(args[3],df);
}
catch(DateTimeParseException e){
System.out.println("Bad usage: Should be clock.clockSave filename width height [HH:mm:ss]");
return;
}
}
else{
time = LocalTime.now();
}
try{
new CoolPaint().saveClock(w,h,time,args[0]);
}catch (IOException e){
System.out.println("Error on image output: " + e.getMessage());
}
}
}