Homework 1: Graphics - Output

Objective

In this homework assignment, we want you to become familiar with creating tailorable output using the Java Swing toolkit. We also want you to become familiar with damage management in painting a user interface. Though in many circumstances the speed of a computer and its graphics hardware may allow for "brute force" repainting of an entire interface whenever any portion of the display needs to be update, in this assignment, we want you to disregard that and try to make repainting of damaged areas of the interface as efficient as possible.

Also, future assignments may build on this first output assignment, so it will be important for you to get this assignment right and understand what you have done in order to facilitate later exercises.

Description

You are asked to create a JComponent widget, named JCalendar, that looks like this:

Your JCalendar widget must be built as specified below:

  •  
  • This component should have a dimension of 300 x 160 pixels.
  •  
  • The upper left box shows the year information. It should be of the size 100 x 30 pixels and uses the bold, "Dialog", 32pt font.
  •  
  • Directly below it, the month information is painted in bold, "Dialog", 12pt font.
  •  
  • The circle in the lower left is 90 pixels in diameter; it is divided into twelve smaller parts, labeled 1-12 (using bold, "Dialog", 12pt font). This circle also shows the month information. The part of the circle matching the month shown in the right hand box should be highlighted in gray.
  •  
  • The right box is 170 x 140 pixels in size. This box renders the month selected in the left hand portion of the component. In this box, a particular date can be highlighted in blue. The text in this box are drawn with the 12pt plain "Dialog" font.

  •  
  • The JCalendar component should initially render the current day, month and year.
  •  
  • Additionally, your component must support the following method:
        public void setDate(int year, int month, int day_of_month)
      

    We are providing the file JTestFrame.java which will construct a JCalendar component and adds it to the frame. The JTestFrame will allow us to tell your JCalendar component what month, day, year we would like for it to render. JTestFrame will invoke your JCalendar's setDate() method and your JCalendar component must be able to render the date specified.

    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 a user specifies 2/30/2002 (which is not a valid date because February typically has only 28 days), your component should adjust it to (2/28/2002). If July 31, 2003 is specified: because 7/31/2003 is a valid date, no adjustment is needed.

    Deliverable

    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 () when you have completed the assignment (and remember to CC yourself on the email).

    The due date for this assignment is: September 5, 2003, 1:00 PM EST.