package chapter15; /** * Title: Chapter 15, "Multithreading" * Description: Examples for Chapter 15 * Copyright: Copyright (c) 2000 * Company: Armstrong Atlantic State University * @author Y. Daniel Liang * @version 1.0 */ // Clock.java: Show a running clock on the panel import java.util.*; import java.awt.event.*; import javax.swing.Timer; import chapter14.StillClock; public class Clock extends StillClock implements ActionListener { protected Timer timer; /**Default constructor*/ public Clock() { this(Locale.getDefault(), TimeZone.getDefault()); } /**Construct a clock with specified locale and time zone*/ public Clock(Locale locale, TimeZone timeZone) { super(locale, timeZone); // Create a timer with delay 1000 ms and listener Clock timer = new Timer(1000, this); // Start the timer timer.start(); } /**Resume the clock*/ public void resume() { timer.start(); } /**Suspend the clock*/ public void suspend() { timer.stop(); } /**Handle the action event*/ public void actionPerformed(ActionEvent e) { repaint(); } }