i would like to manipulate the date and time in java. Im currently studying how to create an alarm clock windowed application. Can you give me any leads or info on how to go about this.
thank you all.
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
> Im currently studying how to create an alarm clock windowed application.
a Swing application?
if so, add a JLabel to display the clock add a timer to change the label's text the label's text is a SimpleDateFormat() of 'new Date()'
Cyrus Serrano
Ranch Hand
Joined: Sep 29, 2003
Posts: 137
posted
0
how about the time.. is there a built in class that i can use. is it the java.sql.time ??
thanks
vijaya bacina
Ranch Hand
Joined: Aug 23, 2005
Posts: 155
posted
0
java.uti.Date() will hold both date and time
Cyrus Serrano
Ranch Hand
Joined: Sep 29, 2003
Posts: 137
posted
0
how will i display the time on a JLabel for example, i mean every second. like a clock. when i was using vb there was a timer control, and it had this timer event. any help.. thanks guys for being prompt.
im starting to create my alarm clock object, hope you can check what im doing. just asking for your opinion.
This is what i have so far:
Alarm_Clock Object Properties - Hour, Minute, Second, Month, Day, Year Methods - get and set methods for the properties above - getTime (returns hh:mm:ss) - getDate (returns mm/dd/yy) - setAlarm (sets the date, time and message to be shown) - setAlarmSound (mp3 sound, ^^ )
Am i correct?
Now i was thinking of using a Calendar object to represent the time and date of the alarm clock instead, i dont know if this is correct. Since it has some properties and methods that deals the same thing.
Thanks [ October 31, 2006: Message edited by: Cyrus Serrano ]
I wouldn't call it "Alarm_Clock" with an underscore in it; just "AlarmClock". You can call it whatever you want ofcourse, but there is a defacto coding standard / style that almost every Java programmer uses, in which class names are written in CamelCase, just like all the classes and interfaces in the standard Java API. See: Code Conventions for the Java Programming Language.
Class Calendar and class Date are both useful for storing dates and times; you could use either. Class Calendar contains a number of useful methods for doing date arithmetic.
Instead of the AlarmClock class having separate properties for hour, minute, second etc. you could also just give it one Date property:
Cyrus Serrano
Ranch Hand
Joined: Sep 29, 2003
Posts: 137
posted
0
this is what i have in mind so far:
public class AlarmClock extends JPanel{
private Calendar currentSetting;
public AlarmClock() { currentSetting = Calendar.getInstance(); }
//Sets the values for the calendar fields YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY, and MINUTE. public void setDateAndTime(int yr,int mn,int dom, int hod, int min) { currentSetting.set(yr, mn, dom, hod, min); }
}
---
I've used the Calendar class instead of the Date class since some of the methods of the date class are deprecated and requires the use of the Calendar class instead. Any comments guys.
@Jesper, thanks for the naming convention.. noted.