|
-
Nov 4th, 2003, 12:19 PM
#1
Thread Starter
New Member
Difficulty grabbing info from a JList.
Hi everyone, this is my first post here!
I have a JListBox which is getting its contents from an Array (containing names of months.)
I need to produce an IF statement to determine how many days there are in a month, for example, I need to say something like :
If (contents of selected field in JListBox = "February")
Do this
However, I'm new to Java and any attempt I have made has mucked up.
I thought something like :
String CurrentMonth = JListBox.getSelectedValue();
if CurrentMonth = "February"
Do this (something to only produce 28 boxes etc)
Would work, but it doesnt for some reason. The error is "Incompatible types."
Could someone point me in the right direction?
Also is there an easier way of determining how many days there are in a month within Java?
Thanks!
-
Nov 5th, 2003, 12:31 PM
#2
Dazed Member
As far as i remember getSelectedValue() returns an object. Also in your if statement you would not want to use the = operator. That's for assignments. Use the equals() method instead which has been overridden in the String class to test for String equality.
-
Nov 5th, 2003, 01:02 PM
#3
Dazed Member
Posted by HELLO.JPG
Also is there an easier way of determining how many days there are in a month within Java?
Check the java.util.Calendar or the java.util.GregorianCalendar classes. Remember the Calendar class is abstract so to get a solid instance of this class you would have to use Calendar c = Calendar.getInstance(); I believe GregorianCalendar is a subclass of Calendar so you could just apply this class to the superclass ie. Calendar c = new GregorianCalendar();
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|