Skip to main content

Enum issues with Java 1.5

1 reply [Last post]
colinm3
Offline
Joined: 2006-06-02
Points: 0

Hi,

I am having some trouble and would like to know if anyone could help.

public enum CISDaysOfWeek {

SUNDAY("Sunday",1),
MONDAY("Monday",2),
TUESDAY("Tuesday",3),
WEDNESDAY("Wednesday",4),
THURSDAY("Thursday",5),
FRIDAY("Friday",6),
SATURDAY("Saturday",7);

String name;
int id;
private CISDaysOfWeek(String name, int id)
{
this.name = name;
this.id = id;
}

Alright thats the code, I have a JComboBox which I populate with those enum values and I do override the toString method so that I get the "DayofWeek" string to display in the ComboBox.

However the problem comes in when I try setSelectedItem on my ComboBox model to the current day of the week.
I use the Calendar class and the DAY_OF_WEEK field to get the correct int value (thats the return type) for the current day of the week.

I am sure you get what I am trying to do and any advice as to how I should go about it would be great.

Thank you
Colin

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
hanshin
Offline
Joined: 2006-05-09
Points: 0

Use CISDaysOfWeek.values() to pick the appropriate weekday.