rob22888
asked on
Problem with java.util.calendar import
Hi,
I have used the import:
import java.util.Calendar;
in my java applet, but there appears to be some methods missing? When I try and use methods such as set() or get() i get an error saying 'cannot find symbol'.
Does anyone have any ideas?
I have used the import:
import java.util.Calendar;
in my java applet, but there appears to be some methods missing? When I try and use methods such as set() or get() i get an error saying 'cannot find symbol'.
Does anyone have any ideas?
ASKER
well this is what i am trying to make work...
cal.set(Calendar.YEAR, 1990);
and
cal.get(Calendar.DAY_OF_YE AR):
but the set() and get() methods aren't being recognised??
cal.set(Calendar.YEAR, 1990);
and
cal.get(Calendar.DAY_OF_YE
but the set() and get() methods aren't being recognised??
can u post the code?
also make sure cal is an instance of Calendar!
also make sure cal is an instance of Calendar!
ASKER
import java.util.Calendar;
...
...
...
private void submitbtnActionPerformed(j ava.awt.ev ent.Action Event evt) {
int theday = Integer.parseInt(dayfield. getText()) ;
int themonth = Integer.parseInt(monthfiel d.getText( ));
int theyear = Integer.parseInt(yearfield .getText() );
cal.set(Calendar.YEAR, theyear);
int calculation = (theday + themonth + theyear);
String result = Integer.toString(calculati on);
answerfield.setText(result );
}
and there is a cal class with:
import java.util.Calendar;
class cal {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
}
}
...
...
...
private void submitbtnActionPerformed(j
int theday = Integer.parseInt(dayfield.
int themonth = Integer.parseInt(monthfiel
int theyear = Integer.parseInt(yearfield
cal.set(Calendar.YEAR, theyear);
int calculation = (theday + themonth + theyear);
String result = Integer.toString(calculati
answerfield.setText(result
}
and there is a cal class with:
import java.util.Calendar;
class cal {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
}
}
ASKER
sorry, ignore
int calculation = (theday + themonth + theyear);
String result = Integer.toString(calculati on);
int calculation = (theday + themonth + theyear);
String result = Integer.toString(calculati
ASKER
....
screeny.gif
screeny.gif
>>and there is a cal class with:
import java.util.Calendar;
class cal {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance(); //if this is what u refer in the method, u have to move it as instance variable rather inside main method!
}
}
>>
I think the above is the problem!
and where have initialized the cal var?
>>cal.set(Calendar.YEAR, theyear);
I think, the above cal refers to ur cal class rather an instance of Calendar!
why do you have a class with cal?
import java.util.Calendar;
class cal {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance(); //if this is what u refer in the method, u have to move it as instance variable rather inside main method!
}
}
>>
I think the above is the problem!
and where have initialized the cal var?
>>cal.set(Calendar.YEAR, theyear);
I think, the above cal refers to ur cal class rather an instance of Calendar!
why do you have a class with cal?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, that has sorted the problem.
I am trying to make an applet that will figure out the day number of the year, for eg. the 2nd February would be day 33 and so on, but taking into account leap years and that.... can you see any issues with the code now which isn't right?
private void submitbtnActionPerformed(j ava.awt.ev ent.Action Event evt) {
Calendar cal = Calendar.getInstance();
int theday = Integer.parseInt(dayfield. getText()) ;
int themonth = Integer.parseInt(monthfiel d.getText( ));
int theyear = Integer.parseInt(yearfield .getText() );
cal.set(Calendar.YEAR, theyear);
cal.set(Calendar.MONTH, themonth);
cal.set(Calendar.DAY_OF_MO NTH, theday);
int calculation = cal.get(Calendar.DAY_OF_YE AR);
String result = Integer.toString(calculati on);
answerfield.setText(result );
}
When I input 1 for the day, 1 for the month and 2000 for the year I am getting the day of year as 32???
I am trying to make an applet that will figure out the day number of the year, for eg. the 2nd February would be day 33 and so on, but taking into account leap years and that.... can you see any issues with the code now which isn't right?
private void submitbtnActionPerformed(j
Calendar cal = Calendar.getInstance();
int theday = Integer.parseInt(dayfield.
int themonth = Integer.parseInt(monthfiel
int theyear = Integer.parseInt(yearfield
cal.set(Calendar.YEAR, theyear);
cal.set(Calendar.MONTH, themonth);
cal.set(Calendar.DAY_OF_MO
int calculation = cal.get(Calendar.DAY_OF_YE
String result = Integer.toString(calculati
answerfield.setText(result
}
When I input 1 for the day, 1 for the month and 2000 for the year I am getting the day of year as 32???
>>When I input 1 for the day, 1 for the month and 2000 for the year I am getting the day of year as 32???
I think, this is right!
jan - 31days
1 day - 1 day
so totally 32 days!
I think, this is right!
jan - 31days
1 day - 1 day
so totally 32 days!
ASKER
Well no because I am trying to say that the date is 1st January 2000, which should be day number 1 of the year?
then you have to give the month as 0!
ASKER
ah right i see.
i have just done this to the code:
int month = Integer.parseInt(monthfiel d.getText( ));
int themonth = month - 1;
as a work around for this little technicality, so now when the user inputs 1st Jan, they get day number 1 as it should be :-)
Thank you for your help.
i have just done this to the code:
int month = Integer.parseInt(monthfiel
int themonth = month - 1;
as a work around for this little technicality, so now when the user inputs 1st Jan, they get day number 1 as it should be :-)
Thank you for your help.
for e.g., it can be
cal.get( Calendar.YEAR ) ; //or any int constant defined
cal.set( Calendar.MONTH, 2 ) ;