-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimer.java
53 lines (43 loc) · 900 Bytes
/
Timer.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
import java.util.ArrayList;
import javax.swing.JOptionPane;
class Timer implements Runnable{
private int time=0;
private ArrayList<String> users;
private int shutdown;
public Timer(ArrayList<String> users)
{
this.users = users;
try{
shutdown=Integer.parseInt(JOptionPane.showInputDialog("Enter auto-shutdown time (sec):"));
}
catch(NumberFormatException e){
JOptionPane.showMessageDialog(null, "Wrong format, auto-shutdown set to 10sec of inactivity.");
shutdown=10;
}
}
@Override
public void run() {
while(true)
{
try {
Thread.sleep(1000);
time++;
} catch (InterruptedException e) {
e.printStackTrace();
}
if(users.size()==0 && time>shutdown)
{
JOptionPane.showMessageDialog(null,"Server auto-shuttdown.");
System.exit(0);
}
}
}
public int getTime()
{
return time;
}
public void reset()
{
time=0;
}
}