⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 monthpanel.java

📁 its a kind of tutorial.
💻 JAVA
字号:
// Filename MonthPanel.java.
// Provides an Panel which can be configured to show
// the pattern of days in any particular month.
//
// Written for JI book, Chapter 3 see text.
// Fintan Culwin, v0.1, August 1997.

package DatePanel;

import java.awt.*;
import java.awt.event.*;
import java.util.*;

import DatePanel.DateUtility;
import DatePanel.DayBox;


class MonthPanel extends    Panel 
                 implements ActionListener {

private static final int MAX_BOXES = 37;

private DayBox           dayBoxes[]  = new DayBox[ MAX_BOXES];
private int              highlighted;
private int              theFirstBox;
private ActionListener   passUpToHere;

private static String dayNames[] = { "Sun", "Mon", "Tue", "Wed", 
                                     "Thu", "Fri", "Sat"  };


   protected MonthPanel( ActionListener listener) {

   int            thisOne; 
   Label          dayLabels[] = new Label[ 7];   
   ResourceBundle resources   = ResourceBundle.getBundle( "DatePanelResources");
   String         dayNames[]  = (String[]) resources.getObject( "dayNames");   
   
      this.setLayout( new GridLayout( 7, 7, 0, 0));
      for ( thisOne = 0; thisOne < 7; thisOne++) { 
         dayLabels[ thisOne] = new Label( dayNames[ thisOne],
                                          Label.CENTER);
         this.add( dayLabels[ thisOne]);                                 
      } // End for.       

      for ( thisOne = 0; thisOne < MAX_BOXES; thisOne++) { 
         dayBoxes[ thisOne] = new DayBox( thisOne, this);
         this.add( dayBoxes[ thisOne] );
      } // End for.
       
      passUpToHere = listener;
   } // End MonthPanel constructor.
   
   
   public void reConfigure( int year, int month, int day) { 
   
   int maxDay   = DateUtility.daysThisMonthIs(   year, month);
   int startDay = DateUtility.firstDayOfMonthIs( year, month);

   int thisOne;
System.out.println( "setting " + year + "/" + month + "/" +  day);  
      theFirstBox = startDay;
      if ( day > maxDay) { 
         day = maxDay;
      } //End if.

      dayBoxes[ highlighted].clearHighlight();

      for ( thisOne = 0; thisOne < MAX_BOXES; thisOne++) { 
         if ( (thisOne <  startDay) ||
              (thisOne >= (startDay + maxDay)) ){     
            dayBoxes[ thisOne].setDayNumber( 0);  
         } else {      
            dayBoxes[ thisOne].setDayNumber( thisOne - startDay +1);
         } // End if    
         dayBoxes[ thisOne].repaint();
      } // End for.
      
      dayBoxes[ theFirstBox + day -1].setHighlight();
      highlighted = theFirstBox + day -1;       
   } // End reConfigure. 


   public void actionPerformed( ActionEvent event)  { 
      ((DayBox) event.getSource()).setHighlight();
      dayBoxes[ highlighted].clearHighlight();
      highlighted = ((DayBox) event.getSource()).getOrdinal(); 
      passUpToHere.actionPerformed( event);
/*      passUpToHere.actionPerformed( new ActionEvent(this, 
                                              ActionEvent.ACTION_PERFORMED,
                                              "Date Selected"));  
                                              */
   } // End actionPerformed.    


   public int dayIs(){ 
      return highlighted - theFirstBox +1;
   } // End dayIs;
} // End class MonthPanel.


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -