Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / May 2004

Tip: Looking for answers? Try searching our database.

GregorianCalendar

Thread view: 
JamesY - 24 May 2004 06:48 GMT
Hi, I am a newbie.Can anyone tells me what's wrong with my code. I am trying
to populate a choice for the days in 1900, January.

There are only a 1 in the c4 choice, but it should have been a list from 1
to 31.

Choice c4 = new Choice();

calendar = new GregorianCalendar();

//set original date

calendar.set(Calendar.YEAR, 1900);

calendar.set(Calendar.MONTH, 0); //0 for January

calendar.set(Calendar.DAY_OF_MONTH, 1); //1 for day 1

//store original date

int temp1 = calendar.get(Calendar.YEAR);

int temp2 = calendar.get(Calendar.MONTH);

int temp3 = calendar.get(Calendar.DAY_OF_MONTH);

do{

c4.addItem(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));

calendar.add(Calendar.DAY_OF_MONTH,1);

}while (temp2 != calendar.get(Calendar.MONTH));

c4.addItemListener(this);

add(c4);

//set back to original date

calendar.set(Calendar.YEAR, temp1);

calendar.set(Calendar.MONTH, temp2);

calendar.set(Calendar.DAY_OF_MONTH, temp3);

Thanks in advance,

mr newbie
Roedy Green - 24 May 2004 09:37 GMT
>Hi, I am a newbie.Can anyone tells me what's wrong with my code. I am trying
>to populate a choice for the days in 1900, January.

see http://mindprod.com/jgloss/calendar.html
and http://mindprod.com/jgloss/gotchas.html#DATE

for the usual gotchas.

Signature

Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Murray - 24 May 2004 10:44 GMT
> }while (temp2 != calendar.get(Calendar.MONTH));

Shouldn't this be == instead of != ?
JamesY - 24 May 2004 11:31 GMT
Yes, you are right. I have got it working. Thanks.

> > }while (temp2 != calendar.get(Calendar.MONTH));
>
> Shouldn't this be == instead of != ?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.