cs621: proj1: Clock modified to 12-hour format, show AM/PM

git-svn-id: svn://anubis/gvsu@9 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2008-02-03 04:41:25 +00:00
parent 6aad5842fd
commit 2d610b1c83
3 changed files with 32 additions and 12 deletions

View File

@ -4,17 +4,19 @@ import javax.swing.*;
/** /**
* This class provides a graphical view of the current time * This class provides a graphical view of the current time
*/ */
class ClockView extends JFrame public class ClockView extends JFrame
{ {
private JLabel tLabel = new JLabel(); private JLabel tLabel = new JLabel();
/** /**
* Constructor method to make a ClockView object. * Constructor method to make a ClockView object.
*/ */
ClockView() public ClockView()
{ {
super("Clock");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setSize(95, 75); setSize(100, 70);
tLabel.setHorizontalAlignment(SwingConstants.CENTER);
getContentPane().add(tLabel); getContentPane().add(tLabel);
refreshTimeDisplay(); refreshTimeDisplay();
} }
@ -42,9 +44,10 @@ class ClockView extends JFrame
t.fillTimes(); t.fillTimes();
String display = getDigitsAsString(t.hrs) + ":" + String display = getDigitsAsString(t.hrs) + ":" +
getDigitsAsString(t.mins) + ":" + getDigitsAsString(t.mins) + ":" +
getDigitsAsString(t.secs); getDigitsAsString(t.secs) + " " +
tLabel.setText (" " + display); t.am_pm;
tLabel.repaint (); tLabel.setText(" " + display);
tLabel.repaint();
} }
} }

12
cs621/proj1/Makefile Normal file
View File

@ -0,0 +1,12 @@
all:
javac *.java
.PHONY: javadoc
javadoc:
-mkdir doc
javadoc -d doc *.java
clean:
-rm -f *.class
-rm -rf doc

View File

@ -2,24 +2,29 @@
/** /**
* This class holds a time value consisting of hours, minutes, and seconds. * This class holds a time value consisting of hours, minutes, and seconds.
*/ */
class Timestamp public class Timestamp
{ {
// data fields // data fields
int hrs; public int hrs;
int mins; public int mins;
int secs; public int secs;
public java.lang.String am_pm;
/** /**
* This method updates the hours, minutes, and seconds values * This method updates the hours, minutes, and seconds values
* associated with the Timestamp object. * associated with the Timestamp object.
*/ */
void fillTimes() public void fillTimes()
{ {
java.util.Calendar now; java.util.Calendar now;
now = java.util.Calendar.getInstance(); 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); mins = now.get(java.util.Calendar.MINUTE);
secs = now.get(java.util.Calendar.SECOND); secs = now.get(java.util.Calendar.SECOND);
am_pm = now.get(java.util.Calendar.AM_PM) == java.util.Calendar.AM
? "AM"
: "PM";
} }
} }