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:
parent
6aad5842fd
commit
2d610b1c83
@ -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,7 +44,8 @@ class ClockView extends JFrame
|
||||
t.fillTimes();
|
||||
String display = getDigitsAsString(t.hrs) + ":" +
|
||||
getDigitsAsString(t.mins) + ":" +
|
||||
getDigitsAsString(t.secs);
|
||||
getDigitsAsString(t.secs) + " " +
|
||||
t.am_pm;
|
||||
tLabel.setText(" " + display);
|
||||
tLabel.repaint();
|
||||
}
|
||||
|
12
cs621/proj1/Makefile
Normal file
12
cs621/proj1/Makefile
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
all:
|
||||
javac *.java
|
||||
|
||||
.PHONY: javadoc
|
||||
javadoc:
|
||||
-mkdir doc
|
||||
javadoc -d doc *.java
|
||||
|
||||
clean:
|
||||
-rm -f *.class
|
||||
-rm -rf doc
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user