• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

displaying time

 
Cyrus Serrano
Ranch Hand
Posts: 137
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ranchers,

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
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
Posts: 137
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 155
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.uti.Date() will hold both date and time
 
Cyrus Serrano
Ranch Hand
Posts: 137
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Browse through the Java API documentation and see if you can find anything. Hava a look at the class java.util.Timer, for example. Other useful classes might be java.util.Calendar and java.text.SimpleDateFormat.

Google also is very useful, search for "java timer" or "java clock" or something similar.
[ October 31, 2006: Message edited by: Jesper Young ]
 
MV Krishna
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Cyrus Serrano
Ranch Hand
Posts: 137
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Krishna and Jesper,

thanks for the comments and codes.. well appreciated..

im also visiting www.javaalmanac.com for references..
 
Cyrus Serrano
Ranch Hand
Posts: 137
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,

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 ]
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your ideas for your alarm clock class sound OK.

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
Posts: 137
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic