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 package com.drazzib.netpisteur.ui;
28
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31
32 /**
33 * Create a clock that count or decount time
34 *
35 * @author NetPisteur team
36 */
37 public class Clock implements ActionListener {
38
39
40 private int sec, min, heure;
41
42 private String secToString, minToString, heureToString;
43
44 private boolean decomptage;
45
46 private MainFrame window;
47
48
49
50 /**
51 * Create an Horloge on a mainWindow that count time
52 *
53 * @param main :
54 * the window where the clock is applicated
55 */
56 public Clock(MainFrame main) {
57 this.sec = 0;
58 this.min = 0;
59 this.heure = 0;
60 this.decomptage = false;
61 this.window = main;
62 }
63
64 /**
65 * Create an Horloge on a mainWindow that decount time
66 *
67 * @param ss :
68 * seconds that will be decounted
69 * @param mm :
70 * minutes that will be decounted
71 * @param hh :
72 * hours that will be decounted
73 * @param main :
74 * the window where the clock is applicated
75 */
76 public Clock(int ss, int mm, int hh, MainFrame main) {
77 this.sec = ss;
78 this.min = mm;
79 this.heure = hh;
80 this.decomptage = true;
81 this.window = main;
82 }
83
84 /**
85 * Functionning of the Horloge
86 */
87 public void actionPerformed(ActionEvent event) {
88
89 if (this.decomptage == false) {
90 this.sec++;
91
92 if (this.sec == 60) {
93 this.sec = 0;
94 this.min++;
95 }
96 if (this.min == 60) {
97 this.min = 0;
98 this.heure++;
99 }
100 if (this.sec > -1 && this.sec < 10) {
101 this.secToString = "0" + this.sec;
102 } else {
103 this.secToString = Integer.toString(this.sec);
104 }
105 if (this.min > -1 && this.min < 10) {
106 this.minToString = "0" + this.min;
107 } else {
108 this.minToString = Integer.toString(this.min);
109 }
110 if (this.heure > -1 && this.heure < 10) {
111 this.heureToString = "0" + this.heure;
112 } else {
113 this.heureToString = Integer.toString(this.heure);
114 }
115 this.window.setDuree(this.heureToString
116 + ":" + this.minToString + ":"
117 + this.secToString);
118 } else {
119 this.sec--;
120
121 if (this.sec == -1) {
122 this.sec = 59;
123 this.min--;
124 }
125 if (this.min == -1) {
126 this.min = 59;
127 this.heure--;
128 }
129 if (this.sec == 0 && this.min == 0 && this.heure == 0) {
130 this.window.saveDatas();
131 }
132 if (this.sec > -1 && this.sec < 10) {
133 this.secToString = "0" + this.sec;
134 } else {
135 this.secToString = Integer.toString(this.sec);
136 }
137 if (this.min > -1 && this.min < 10) {
138 this.minToString = "0" + this.min;
139 } else {
140 this.minToString = Integer.toString(this.min);
141 }
142 if (this.heure > -1 && this.heure < 10) {
143 this.heureToString = "0" + this.heure;
144 } else {
145 this.heureToString = Integer.toString(this.heure);
146 }
147 this.window.setDuree(this.heureToString
148 + ":" + this.minToString + ":"
149 + this.secToString);
150 }
151 }
152
153 }
154