Hello.
Currently i am creating a small application that works around packets.
The packets are sent every 600ms.
Now my quesition is this:
Currently i have this (An example)
public class Example {
private int exampleInt = 0;
public void setExample(int i) {
exampleInt = i;
}
public void getExample() {
return exampleInt;
}
}
Now here is my other example class
public class OtherExample {
private Example e = new Example();
public void someAction() {
if(e.getExample == 0) {
e.setExample(30);
} else {
System.err.println("Please wait before doing this action again");
}
}
/* Is refreshed every 600ms */
public void process() {
if(e.getExample() > 0) {
e.getExample() -= 1;
}
}
}
Whats happens is every 600ms the system checks to see if the integer is great than 0. if so its subtracts 0 from the total until it is 0 again. So if i wanted 1 second i would set the integer to 1 and a bit :)
Now as you can see this is a poor way of doing a timer. But what i want to achieve is when a certain packet is recieved a timer system is in work to wait until the timer has run out before the packet can be read again.
Please help because as you can see i have a very poor way of doing it :)
Any suggestion would be helpful