399 * |
399 * |
400 * @param delay the delay in milliseconds |
400 * @param delay the delay in milliseconds |
401 * @see #setInitialDelay |
401 * @see #setInitialDelay |
402 */ |
402 */ |
403 public void setDelay(int delay) { |
403 public void setDelay(int delay) { |
|
404 checkDelay(delay, "Invalid delay: "); |
|
405 this.delay = delay; |
|
406 } |
|
407 |
|
408 private static void checkDelay(int delay, String message) { |
404 if (delay < 0) { |
409 if (delay < 0) { |
405 throw new IllegalArgumentException("Invalid delay: " + delay); |
410 throw new IllegalArgumentException(message + delay); |
406 } |
411 } |
407 else { |
412 } |
408 this.delay = delay; |
|
409 } |
|
410 } |
|
411 |
|
412 |
413 |
413 /** |
414 /** |
414 * Returns the delay, in milliseconds, |
415 * Returns the delay, in milliseconds, |
415 * between firings of action events. |
416 * between firings of action events. |
416 * |
417 * |
433 * |
434 * |
434 * @param initialDelay the initial delay, in milliseconds |
435 * @param initialDelay the initial delay, in milliseconds |
435 * @see #setDelay |
436 * @see #setDelay |
436 */ |
437 */ |
437 public void setInitialDelay(int initialDelay) { |
438 public void setInitialDelay(int initialDelay) { |
438 if (initialDelay < 0) { |
439 checkDelay(initialDelay, "Invalid initial delay: "); |
439 throw new IllegalArgumentException("Invalid initial delay: " + |
|
440 initialDelay); |
|
441 } |
|
442 else { |
|
443 this.initialDelay = initialDelay; |
440 this.initialDelay = initialDelay; |
444 } |
441 } |
445 } |
|
446 |
442 |
447 |
443 |
448 /** |
444 /** |
449 * Returns the {@code Timer}'s initial delay. |
445 * Returns the {@code Timer}'s initial delay. |
450 * |
446 * |
636 |
632 |
637 private void readObject(ObjectInputStream in) |
633 private void readObject(ObjectInputStream in) |
638 throws ClassNotFoundException, IOException |
634 throws ClassNotFoundException, IOException |
639 { |
635 { |
640 this.acc = AccessController.getContext(); |
636 this.acc = AccessController.getContext(); |
641 in.defaultReadObject(); |
637 ObjectInputStream.GetField f = in.readFields(); |
|
638 |
|
639 EventListenerList newListenerList = (EventListenerList) |
|
640 f.get("listenerList", null); |
|
641 if (newListenerList == null) { |
|
642 throw new InvalidObjectException("Null listenerList"); |
|
643 } |
|
644 listenerList = newListenerList; |
|
645 |
|
646 int newInitialDelay = f.get("initialDelay", 0); |
|
647 checkDelay(newInitialDelay, "Invalid initial delay: "); |
|
648 initialDelay = newInitialDelay; |
|
649 |
|
650 int newDelay = f.get("delay", 0); |
|
651 checkDelay(newDelay, "Invalid delay: "); |
|
652 delay = newDelay; |
|
653 |
|
654 repeats = f.get("repeats", false); |
|
655 coalesce = f.get("coalesce", false); |
|
656 actionCommand = (String) f.get("actionCommand", null); |
642 } |
657 } |
643 |
658 |
644 /* |
659 /* |
645 * We have to use readResolve because we can not initialize final |
660 * We have to use readResolve because we can not initialize final |
646 * fields for deserialized object otherwise |
661 * fields for deserialized object otherwise |