|  | # Lightweight Example: DayTable |

`

    class DayTable extends Component implements MouseListener
    {
      Date            CurDate;
      int[][]         DayArray;
      FontMetrics     Fm;
      DatePane        Master;
      static int[]    MonthLen = { 31,28,31,30,31,30,31,31,30,31,30,31 };
      static String[] DayShorts = {"Mo","Tu","We","Th","Fr","Sa","Su" };

      public DayTable ( DatePane master ) {
        Font font = new Font( "Helvetica", Font.BOLD, 12);
        setFont( font);
        Fm = getToolkit().getFontMetrics( font);
        Master = master;
        addMouseListener( this);
      }

      public void mousePressed ( MouseEvent e ) {
        Dimension size = getSize();
        int x = e.getX();
        int y = e.getY();
        int cw  = 2*Fm.charWidth( '0');
        int cd  = (size.width-7*cw)/8;
        int rh  = Fm.getHeight();
        int rd  = (size.height-7*rh)/8;
        int xIdx = Math.min( x / (cw+cd), 6);
        int yIdx = Math.min( (y-rh-rd) / (rh+rd), 5 );
        int dn;
        Graphics g;

        if ( (dn=DayArray[xIdx][yIdx]) != 0) {
          CurDate.setDate( dn);
          if ( (g = getGraphics()) != null ) {
            redraw( g);
            g.dispose();
          }
        }

        Master.notifyClients();
      }

      public void redraw ( Graphics g) {
        if ( CurDate == null ) return;

        Dimension size = getSize();
        int zw  = Fm.charWidth( '0');
        int cw  = 2*zw;
        int cd  = (size.width-7*cw)/8;
        int dc  = Fm.getDescent();
        int rh  = Fm.getHeight();
        int rd  = (size.height-7*rh)/8;
        int dn, dof, dim = CurDate.getDate();

        g.setColor( Color.blue);
        g.setFont( getFont() );
        for ( int dy=0; dy<7; dy++)
          g.drawString( DayShorts[dy], cd+dy*(cw+cd), rd+rh-dc);

        for ( int dy=0; dy<7; dy++) {
          for ( int wk=0; wk<6; wk++) {
            if ( (dn=DayArray[dy][wk]) != 0 ){
              if ( dn<10) dof=zw;
              else        dof = 0;
              if (dn==dim) g.setColor( Color.green);
              else if ( dy==6) g.setColor( Color.red);
              else g.setColor( Color.black);
              g.drawString( Integer.toString(dn),
                            dof+cd+dy*(cd+cw), (wk+2)*(rd+rh)-dc );
            }
          }
        }
      }

      public void paint ( Graphics g ) {
        Dimension size = getSize();
        g.setColor( getBackground());
        g.fillRect( 0, 0, size.width, size.height);

        redraw( g);
      }

      public static int[][] getDayArray ( int mn, int ye) {
        int[][] darr = new int[7][6];
        int sd = (new Date( ye, mn-1, 1)).getDay();
        int maxd = MonthLen[mn-1];

        if ( (mn==2) && (isLeapYear( ye)) ) maxd++;
        if ( sd == 0) sd = 7;

        for( int day=sd-1; day < maxd+sd-1; day++)
          darr[day%7][day/7] = day-sd+2;

        return darr;
      }

      public Date getDate () {
        return CurDate;
      }

      void setDate ( Date dt ) {
        CurDate = dt;
        DayArray = getDayArray( dt.getMonth()+1, dt.getYear() );
        repaint();
      }

      public void mouseClicked ( MouseEvent e ) {}
      public void mouseReleased ( MouseEvent e ) {}
      public void mouseEntered ( MouseEvent e ) {}
      public void mouseExited ( MouseEvent e ) {}

      public static boolean isLeapYear ( int year) {
        if ( year % 400 == 0 )      return true;
        if ( year % 100 == 0 )      return false;
        return (year % 4) == 0;
      }
    }

`