gvsu/cs621/proj1/ClockView.java
josh 6aad5842fd cs621: proj1: added javadoc to base Clock .java files
git-svn-id: svn://anubis/gvsu@8 45c1a28c-8058-47b2-ae61-ca45b979098e
2008-02-03 04:11:53 +00:00

52 lines
1.3 KiB
Java

import javax.swing.*;
/**
* This class provides a graphical view of the current time
*/
class ClockView extends JFrame
{
private JLabel tLabel = new JLabel();
/**
* Constructor method to make a ClockView object.
*/
ClockView()
{
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setSize(95, 75);
getContentPane().add(tLabel);
refreshTimeDisplay();
}
/**
* Helper method to convert an integer to a 0-padded string.
* @param i The integer to convert
* @return A string representing the integer, padded on the
* left by a '0' character if the integer was less than 10.
*/
protected String getDigitsAsString(int i)
{
String str = Integer.toString(i);
if (i < 10)
str = "0" + str;
return str;
}
/**
* A method to update the time displayed in the ClockView window.
*/
public void refreshTimeDisplay()
{
Timestamp t = new Timestamp();
t.fillTimes();
String display = getDigitsAsString(t.hrs) + ":" +
getDigitsAsString(t.mins) + ":" +
getDigitsAsString(t.secs);
tLabel.setText (" " + display);
tLabel.repaint ();
}
}