Disabling checkboxes

Hi,

I have 7 check boxes.

Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday

I have set their names using JCheckBox.setName() to

Sunday = 1

Monday = 2

Tuesday = 3

Wednesday = 4

Thursday = 5

Friday = 6

Saturday = 7

I have gregorianCalender startdate and enddate.

I am trying to disable all the checkboxes that are not between startdate and enddate.

Iam able to get what is StartDay and endDay using

startDate.get(Calendar.DAY_OF_WEEK)

I am not able to proceed from there.

Can anybody help me with the logic.

Thanks.

[630 byte] By [sam_123a] at [2007-11-27 8:19:44]
# 1
You should keep record of the checkboxes by using an array or its equivalent. Then iterate over the array using a loop and call setEnable(false) on the elements that are not in the range of the start and end dates.ICE
icewalker2ga at 2007-7-12 20:07:56 > top of Java-index,Desktop,Core GUI APIs...
# 2

I tried to do the same way.

public static ArrayList<Integer> Days() {

ArrayList<Integer> day = new ArrayList<Integer>();

day.add(1); //sample program direcltly entered valus

day.add(2);

day.add(3);

day.add(4);

day.add(5);

day.add(6);

day.add(7);

return day;

}

public static void main(String[] args) {

// TODO Auto-generated method stub

ArrayList Days = null;

int StDay = 2; //for example

int EdDay = 5;

Days = Days();

for(int i=0;i<Days.size();i++) {

Days.get(i);

System.out.println(Days.get(i));

}

System.out.println("-");

java.util.Iterator it = Days.iterator();

for(int i = (StDay-1);i<Days.size();i++) {

// if(Integer.parseInt(it.next().toString())==2) {

if(Days.contains(StDay)) {

System.out.println(Days.get(StDay-1));

}

}

}

Message was edited by:

sam_123>

sam_123a at 2007-7-12 20:07:56 > top of Java-index,Desktop,Core GUI APIs...
# 3

Your code is rather confusing... First, don't capitalize variable names, follow the java naming convention instead:

int startDay = 2;

int endDay = 5;

Also, I recommend you to assign numbers to weekdays starting from 0.

Then create an array of JCheckboxes as suggested. Here's a starting point:

JCheckBox[] checkboxes = new JCheckBox[7];

for (int i = 0; i < checkboxes.length; i++) {

checkboxes[i].setSelected(false);

// other operations on your checkboxes e.g. set their names

panel.add(checkboxes[i]); // this is your JPanel where to put the checkboxes

}

for (int d = startDay; d <= endDay; d++) {

checkboxes[d].setSelected(true);

}

Cheers,

java_knighta at 2007-7-12 20:07:56 > top of Java-index,Desktop,Core GUI APIs...