Results 1 to 3 of 3

Thread: Difficulty grabbing info from a JList.

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2003
    Posts
    3

    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!

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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.

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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
  •  



Click Here to Expand Forum to Full Width