Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. import java.awt.event.ActionEvent;
  2. import java.awt.event.ActionListener;
  3.  
  4.  
  5. public class DisplayTimeState implements State {
  6.  
  7. private ClockUI clock;
  8.  
  9. public DisplayTimeState(ClockUI clock){
  10. this.clock = clock;
  11. action();
  12. }
  13.  
  14. public void action(){
  15. int delay = 500; // milliseconds
  16. ActionListener task = new ActionListener() {
  17. public void actionPerformed(ActionEvent evt) {
  18. clock.updateTime();
  19. }
  20. };
  21. javax.swing.Timer timer = new javax.swing.Timer(delay, task);
  22. timer.start();
  23. }
  24.  
  25. public void changeState(State newState){
  26. action();
  27. clock.setState(newState);
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement