import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.Timer;

public class DigitalClock extends JPanel {
    private Timer clock;
    private JTextArea display;
    private JScrollPane displayPane;
    
    public DigitalClock(Color back, Color digits, Font font) {
        display = new JTextArea(1,20);
        display.setBackground(back);
        display.setForeground(digits);
        display.setFont(font);
        displayPane = new JScrollPane(display);
        add(displayPane);
        clock = new Timer(1000,new TimerAction());
    }
    
    public void start() {
        clock.start();
    }
    
    private class TimerAction implements ActionListener {
        
        public void actionPerformed( ActionEvent e) {
            display.setText(getTime());
        } // end actionPerformed
        
    }
    
    private String getTime() {
        Calendar now = Calendar.getInstance();
        return "   TIME: " +(now.get(now.HOUR)==0?"12":""+now.get(now.HOUR)) +
                ":" + (now.get(now.MINUTE)<10?"0":"") + now.get(now.MINUTE)+
                ":" + (now.get(now.SECOND)<10?"0":"") + now.get(now.SECOND);
        
        
    } // end getTime
    
} // end DigitalClock
