0

I have 2 JDateChooser controls and 7 JCheckBox controls. The date choosers will set a range between two dates, and the 7 checkboxes will filter the dates.

The 7 checkboxes are: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday

For example:

  • I select Oct 01, 2021, from the first date chooser.
  • I select Oct 08, 2021, from the second date chooser.
  • I select Monday and Tuesday from the checkboxes.

The output will be all Mondays and Tuesdays in the dates range Oct 01, 2021 - Oct 08, 2021.

I searched everywhere but no answer and I don't even know where to begin.

Abra
  • 19,142
  • 7
  • 29
  • 41
Thevinu
  • 37
  • 8
  • checkboxes allow a more distinctive look in the event there are multiple choices to select. and yes I am referring to JDateChooser. If you have a way to do it with radio buttons I'm happy to know that to – Thevinu Oct 28 '21 at 06:57
  • the output will be all the dates in the format "MMM dd, yyyy" to be written in the console. – Thevinu Oct 28 '21 at 07:22
  • 1
    [Edit] your question and add that the output will be written to the console. Don't add question details in a comment. – Abra Oct 28 '21 at 07:24

1 Answers1

4

Obviously schoolwork, so I’ll be brief, enough to point you in the right direction while letting you actually do your own assignment yourself.

Seems obvious that you would use checkbox widgets for the days of the week, not a combo box.

Use LocalDate class for the date. Use the plusDays method to move from one date to another. Test each using getDayOfWeek to match against DayOfWeek objects. Use EnumSet and its contains method for that check.

Use an ArrayList< LocalDate > to collect the dates you want to remember.

Make the finished list unmodifiable with a call to List.copyOf.

Report the values of the collected LocalDate objects by using DateTimeFormatter. To automatically localize, use .ofLocalizedDate.


In advanced Java, we might do something like this untested code.

List< LocalDate > dates = 
    LocalDate.of( 2021 , 10 , 1 )
    .datesUntil( LocalDate.of( 2021 , 10 , 8 ) )
    .filter( 
        localDate -> EnumSet.of( DayOfWeek.TUESDAY , DayOfWeek.THURSDAY ).contains( localDate.getDayOfWeek() )
    )
    .toList() 
;
Arvind Kumar Avinash
  • 71,965
  • 6
  • 74
  • 110
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
  • *"Obviously schoolwork.."* This is irrelevant. What's relevant is that questions need to demonstrate a level of research & effort, which this question does not. Plus one for your answer. – Andrew Thompson Oct 28 '21 at 06:57
  • hello Mr.basil I understand your approach and I tried to implement it to my project but the following error pops up. cannot find symbol .datesUntil( LocalDate.of( 2021 , 10 , 8 ) ) ^ symbol: method datesUntil(LocalDate) location: class LocalDate – Thevinu Oct 28 '21 at 07:56
  • 1
    @Thevinu method [datesUntil](https://docs.oracle.com/javase/9/docs/api/java/time/LocalDate.html#datesUntil-java.time.LocalDate-) was added to class `java.time.LocalDate` in JDK 9. – Abra Oct 28 '21 at 08:53
  • 1
    "Obviously schoolwork.." *This is irrelevant.* I beg to differ. There’s a reason why we have got [How do I ask and answer homework questions?](https://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions) – Ole V.V. Oct 28 '21 at 14:26
  • it worked, thank you all for your support. – Thevinu Oct 29 '21 at 08:16