Search
Tutorial 2: Creating Recurrent Items

This tutorial shows how to programmatically create recurring items using JPlanner.

1. Create and initialize a new Java project

Follow steps 1 and 2 from the previous tutorial.

Set CurrentView to WeekRange, Date to Jan 1, 2015 and EndDate to Mar 1, 2015, respectively.

2. Create an appointment

Create a new appointment in the window's constructor by adding the following lines of code to the constructor:

Java  Copy Code

Appointment app = new Appointment();
app.setHeaderText("Meet George");
app.setDescriptionText("This is a sample appointment");
app.setStartTime(new DateTime(2015, 1, 10, 14, 0, 0));
app.setEndTime(new DateTime(2015, 1, 10, 16, 30, 0));

calendar.getSchedule().getItems().add(app);

The code above creates a new appointment on 10th of January, 2015, starting at 2:00 PM and ending at 4:30 PM.

3. Create the recurrence

Now that the appointment is added to the schedule, create a Recurrence object that defines how the appointment recurs. The following code creates and initializes a new Recurrence object and associates it with the item. Add these lines to the window's constructor.

Java  Copy Code

Recurrence rec = new Recurrence();
rec.setPattern(RecurrencePattern.Weekly);
rec.setDaysOfWeek(DaysOfWeek.Monday | DaysOfWeek.Wednesday);
rec.setWeeks(2);
rec.setStartDate(new DateTime(2006, 1, 10));
rec.setRecurrenceEnd(RecurrenceEnd.Never);

app.setRecurrence(rec);

This fragment creates a new recurrence object that continues infinitely and repeats the appointment on Monday and Wednesday every two weeks.

4. Build and run

Compile and run the application. The image below depicts what the application output would look like.