diff --git a/cs621/proj1/ClockView.java b/cs621/proj1/ClockView.java index ecb9a04..554b1ad 100644 --- a/cs621/proj1/ClockView.java +++ b/cs621/proj1/ClockView.java @@ -4,17 +4,19 @@ import javax.swing.*; /** * This class provides a graphical view of the current time */ -class ClockView extends JFrame +public class ClockView extends JFrame { private JLabel tLabel = new JLabel(); /** * Constructor method to make a ClockView object. */ - ClockView() + public ClockView() { + super("Clock"); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - setSize(95, 75); + setSize(100, 70); + tLabel.setHorizontalAlignment(SwingConstants.CENTER); getContentPane().add(tLabel); refreshTimeDisplay(); } @@ -42,9 +44,10 @@ class ClockView extends JFrame t.fillTimes(); String display = getDigitsAsString(t.hrs) + ":" + getDigitsAsString(t.mins) + ":" + - getDigitsAsString(t.secs); - tLabel.setText (" " + display); - tLabel.repaint (); + getDigitsAsString(t.secs) + " " + + t.am_pm; + tLabel.setText(" " + display); + tLabel.repaint(); } } diff --git a/cs621/proj1/Makefile b/cs621/proj1/Makefile new file mode 100644 index 0000000..642ed0f --- /dev/null +++ b/cs621/proj1/Makefile @@ -0,0 +1,12 @@ + +all: + javac *.java + +.PHONY: javadoc +javadoc: + -mkdir doc + javadoc -d doc *.java + +clean: + -rm -f *.class + -rm -rf doc diff --git a/cs621/proj1/Timestamp.java b/cs621/proj1/Timestamp.java index 209f1bc..3299c9a 100644 --- a/cs621/proj1/Timestamp.java +++ b/cs621/proj1/Timestamp.java @@ -2,24 +2,29 @@ /** * This class holds a time value consisting of hours, minutes, and seconds. */ -class Timestamp +public class Timestamp { // data fields - int hrs; - int mins; - int secs; + public int hrs; + public int mins; + public int secs; + public java.lang.String am_pm; /** * This method updates the hours, minutes, and seconds values * associated with the Timestamp object. */ - void fillTimes() + public void fillTimes() { java.util.Calendar now; now = java.util.Calendar.getInstance(); - hrs = now.get(java.util.Calendar.HOUR_OF_DAY); + hrs = now.get(java.util.Calendar.HOUR); + hrs = hrs == 0 ? 12 : hrs; mins = now.get(java.util.Calendar.MINUTE); secs = now.get(java.util.Calendar.SECOND); + am_pm = now.get(java.util.Calendar.AM_PM) == java.util.Calendar.AM + ? "AM" + : "PM"; } }