In this homework assignment, we want you to become familiar with subscribing for input events and interpretting them as commands for controlling the states and behaviors of the JCalendar widget you created in the first homework assignment.
It is important for you to gain an understanding of how input handling is supported by the Swing toolkit to facilitate the next assignment.
You are asked to add the handling of mouse input to the JCalendar component you built from homework 1.
One small modification you may need to add to the paint routine is a line dividing the year box in two smaller regions.
Your JCalendar widget must handle mouse events as specified below:
| When the left mouse button is pressed in the top half of the year box, the year information increases by one. Similarly, when the left mouse button is pressed in the bottom half of the year box, the year information decreases by one. |
![]() (a) The user clicks in the top half of the year box. The year information increases by one. |
![]() (b) The user clicks in the bottom half of the year box. The year information decreases by one. |
| When the left mouse button is pressed inside the month circle, that month is selected. While the mouse is still down, as the user moves between different arc regions, the arc containing the mouse pointer is selected. If the user moves outside of the circle, those mouse events should be ignored. When the user begins by pressing the mouse button outside of the month circle, all subsequent mouse drags are ignored. |
![]() (a) The user clicks inside arc 10. |
![]() (b) The month of October becomes selected. |
![]() (c) With the mouse button still depressed, the mouse is dragged over arc 11. |
![]() (d) The month of November becomes selected. |
![]() (e) With the mouse button still depressed, the mouse moves outside of the month circle. |
![]() (f) No changes are made to the month information. |
![]() (g) With the mouse button still depressed, the mouse moves back inside of the month circle, into arc 1. |
![]() (h) The month of January becomes selected. |
|
![]() (i) The user clicks outside of the month circle. Nothing should happen. |
![]() (j) With the mouse button still depressed, the mouse moves inside the month circle into arc 10. Nothing should happen. |
| When the left mouse button is pressed over a number inside the rectangle displaying the days for the specified month, that day should be the sole number highlighted in blue. While the mouse button remains down, as the user moves over another number, that day should be selected. When the user did not begin by selecting a valid day number, all subsequent mouse drags are ignored. |
![]() (a) The user clicks over the number 1. |
![]() (b) The first day of the month is highlighted. |
![]() (c) With the mouse button still depressed, the mouse is dragged over white space. |
![]() (d) No changes are made to the day information. |
![]() (e) With the mouse button still depressed, the mouse is dragged over the number 6. |
![]() (f) Day 6 of the month is highlighted. |
![]() (i) The user clicks outside of the rectangle displaying the day information and the drags the mouse over the number 26. Nothing should happen. |
![]() (j) The user clicks inside the rectangle displaying the day information, but not over a valid number. With the mouse button still depressed, the mouse moves over the number 25. Nothing should happen. |
| Again, when the date is changed, only the affected portions of the screen should be repainted. For example, do not repaint the box rendering the year information if the year was not changed. Similarly do not repaint the text and circle displaying the month information if it is not affected. Note: The JTestFrame method will automatically print out to the console the arguments to the repaint method to indicate what portions of your JCalendar component is being repainted. This will allow us to determine that you have implemented your component to refresh only those portions that have changed. |
| Finally, your component should be able to adjust a specified date into a valid date. For example, if the calendar currently is rendering 3/30/2002 and the user changes the month to February, your component must recognize that 2/30/2002 is not a valid date. Because February does not have 30 days, your component should adjust it correctly to 2/28/2002. However, if the JCalendar is currently showing July 30, 2003 and the user changes the month to August, it should then show 8/30/2003 with no further adjustments needed. |
Please work on this homework assignment alone; please do not consult others.
This homework assignment should be done in JAVA, and needs to be compiled to run using SUN's JDK 1.4 or higher.
Your JCalendar must work with the JTestFrame.java file provided.
Please zip up source code and mail the zip file to the TA ( The due date for this assignment is: September 12, 2003, 1:00 PM EST.