CALENDAR APPLICATION
import [Link].*;
import [Link].*;
import [Link];
import [Link];
import [Link];
import [Link].*;
public class ColorfulCalendarApp {
private JFrame mainFrame;
private JLabel monthLabel;
private JPanel calendarPanel;
private JTextArea notesArea;
private JTextField dateInputField;
private Calendar currentCalendar;
private Map<String, String> dateNotes = new HashMap<>();
private String selectedDateKey = null; // Track the last selected date
public ColorfulCalendarApp() {
prepareGUI();
currentCalendar = [Link]();
updateCalendar();
}
private void prepareGUI() {
mainFrame = new JFrame("Colorful Calendar Application");
[Link](800, 600);
[Link](new BorderLayout());
[Link]().setBackground(new Color(240, 240, 240));
[Link](JFrame.EXIT_ON_CLOSE);
JPanel topPanel = new JPanel(new BorderLayout());
[Link](new Color(70, 130, 180));
[Link]([Link](10, 10, 10, 10));
JButton prevButton = new JButton("←");
[Link]("Go to the previous month");
[Link](e -> {
[Link]([Link], -1);
updateCalendar();
});
[Link](new Color(100, 149, 237));
[Link]([Link]);
monthLabel = new JLabel("", [Link]);
[Link](new Font("SansSerif", [Link], 20));
[Link]([Link]);
JButton nextButton = new JButton("→");
[Link]("Go to the next month");
[Link](e -> {
[Link]([Link], 1);
updateCalendar();
});
[Link](new Color(100, 149, 237));
[Link]([Link]);
[Link](prevButton, [Link]);
[Link](monthLabel, [Link]);
[Link](nextButton, [Link]);
calendarPanel = new JPanel(new GridLayout(0, 7));
[Link]([Link](10, 10, 10, 10));
JPanel bottomPanel = new JPanel(new BorderLayout());
[Link]([Link](10, 10, 10, 10));
JPanel lookupPanel = new JPanel();
[Link](new JLabel("Find day for date (dd/mm/yyyy):"));
dateInputField = new JTextField(10);
[Link](dateInputField);
JButton findButton = new JButton("Find");
[Link]("Find the day of the week for the entered date");
[Link](e -> findDayForDate());
[Link](findButton);
[Link](lookupPanel, [Link]);
notesArea = new JTextArea(5, 20);
[Link](true);
[Link](true);
[Link]([Link]("Notes for selected date"));
JScrollPane notesScrollPane = new JScrollPane(notesArea);
[Link](notesScrollPane, [Link]);
JButton saveNoteButton = new JButton("Save Note");
[Link]("Save a note for the selected date");
[Link](e -> saveNoteForSelectedDate());
[Link](saveNoteButton, [Link]);
[Link](topPanel, [Link]);
[Link](calendarPanel, [Link]);
[Link](bottomPanel, [Link]);
[Link](new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if ([Link]() == KeyEvent.VK_LEFT) {
[Link]([Link], -1);
updateCalendar();
} else if ([Link]() == KeyEvent.VK_RIGHT) {
[Link]([Link], 1);
updateCalendar();
}
}
});
[Link](true);
}
private void updateCalendar() {
[Link]();
String month = [Link]([Link], [Link],
[Link]());
int year = [Link]([Link]);
[Link](month + " " + year);
String[] days = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
for (String day : days) {
JLabel label = new JLabel(day, [Link]);
[Link](new Color(220, 220, 220));
[Link](true);
[Link](label);
}
Calendar tempCalendar = (Calendar) [Link]();
[Link](Calendar.DAY_OF_MONTH, 1);
int firstDayOfWeek = [Link](Calendar.DAY_OF_WEEK);
int daysInMonth = [Link](Calendar.DAY_OF_MONTH);
for (int i = 1; i < firstDayOfWeek; i++) {
[Link](new JLabel(""));
}
for (int day = 1; day <= daysInMonth; day++) {
final int currentDay = day;
JButton dayButton = new JButton([Link](day));
[Link]("Click to view or add notes for this date");
[Link](e -> showDateDetails(currentDay));
String dateKey = currentDay + "/" + ([Link]([Link]) + 1) + "/" + year;
if ([Link](dateKey)) {
[Link]([Link]);
[Link]([Link]); // <-- Always black text
} else {
[Link]([Link]);
[Link]([Link]);
}
if (currentDay == [Link]().get(Calendar.DAY_OF_MONTH) &&
[Link]([Link]) == [Link]().get([Link]) &&
year == [Link]().get([Link])) {
[Link]([Link]([Link], 2));
}
[Link](dayButton);
}
[Link]();
[Link]();
}
// Modified: No popup, just load note for the selected date
private void showDateDetails(int day) {
int month = [Link]([Link]) + 1;
int year = [Link]([Link]);
selectedDateKey = day + "/" + month + "/" + year; // Track selected date
[Link]([Link](selectedDateKey, ""));
}
// Modified: Save note for the last selected date directly
private void saveNoteForSelectedDate() {
String note = [Link]().trim();
if (selectedDateKey == null) {
[Link](mainFrame, "Please select a date first.");
return;
}
if (![Link]()) {
[Link](selectedDateKey, note);
updateCalendar();
[Link](mainFrame, "Note saved for " + selectedDateKey);
} else {
[Link](mainFrame, "Please enter a note to save");
}
}
private void findDayForDate() {
String dateStr = [Link]().trim();
try {
String[] parts = [Link]("/");
if ([Link] != 3) throw new IllegalArgumentException();
int day = [Link](parts[0]);
int month = [Link](parts[1]) - 1;
int year = [Link](parts[2]);
Calendar tempCalendar = [Link]();
[Link](year, month, day);
String dayOfWeek = [Link](Calendar.DAY_OF_WEEK, [Link],
[Link]());
[Link](mainFrame,
"Date: " + dateStr + "\n" +
"Day: " + dayOfWeek,
"Day Finder", JOptionPane.INFORMATION_MESSAGE);
} catch (Exception e) {
[Link](mainFrame,
"Invalid date format. Please use dd/mm/yyyy",
"Error", JOptionPane.ERROR_MESSAGE);
}
}
public static void main(String[] args) {
[Link](() -> {
ColorfulCalendarApp app = new ColorfulCalendarApp();
[Link](true);
});
}
}
OUTPUT :