home *** CD-ROM | disk | FTP | other *** search
- DEF_COMPONENTNAME
- Calender
- DEF_SUPERCLASS
- Panel
- DEF_PACKAGE
- plugins
- calender
- DEF_ENDLIST
- DEF_VISUAL
- DEF_TOOL
- DEF_CATEGORY
- Calender
- DEF_IMPORTS
- java.util.*
- DEF_ENDLIST
- DEF_THUMBNAIL_UP
- but1.bmp
- DEF_THUMBNAIL_DOWN
- d-but1.bmp
- DEF_BITMAP
- clock.bmp
- DEF_SUBCOMPONENTLIST
- DEF_ENDLIST
- DEF_DECLARATION
- //variable declarations
- private Date mDisplayedDate = new Date();
- private Label mMonth;
- private Label mYear;
- private Label mDayName[];
- private Button mCell[][];
-
- private Button mDayDown;
- private Button mWeekDown;
- private Button mMonthDown;
- private Button mYearDown;
- private Button mToday;
- private Button mDayUp;
- private Button mWeekUp;
- private Button mMonthUp;
- private Button mYearUp;
-
- public static final int YEAR_DOWN = -4;
- public static final int MONTH_DOWN = -3;
- public static final int WEEK_DOWN = -2;
- public static final int DAY_DOWN = -1;
- public static final int TODAY = 0;
- public static final int DAY_UP = 1;
- public static final int WEEK_UP = 2;
- public static final int MONTH_UP = 3;
- public static final int YEAR_UP = 4;
- DEF_ENDLIST
- DEF_METHOD
- public Calender()
- {
- int i;
- int j;
-
- setLayout(new BorderLayout());
- resize(400,400);
-
- Panel lTopPanel = new Panel();
- lTopPanel.setLayout(new GridLayout(1,2));
-
- mMonth = new Label("March", Label.CENTER);
- lTopPanel.add(mMonth);
- mYear = new Label("1996", Label.CENTER);
- lTopPanel.add(mYear);
-
- add("North", lTopPanel);
-
- Panel lMainPanel = new Panel();
- lMainPanel.setLayout(new BorderLayout());
-
- Panel lMainTopPanel = new Panel();
- lMainTopPanel.setLayout(new GridLayout(1, 7));
-
- mDayName = new Label[7];
- for (i = 0; i < 7; i++)
- {
- switch (i)
- {
- case 0 :
- mDayName[i] = new Label("Sun", Label.CENTER);
- break;
- case 1 :
- mDayName[i] = new Label("Mon", Label.CENTER);
- break;
- case 2 :
- mDayName[i] = new Label("Tue", Label.CENTER);
- break;
- case 3 :
- mDayName[i] = new Label("Wed", Label.CENTER);
- break;
- case 4 :
- mDayName[i] = new Label("Thu", Label.CENTER);
- break;
- case 5 :
- mDayName[i] = new Label("Fri", Label.CENTER);
- break;
- case 6 :
- mDayName[i] = new Label("Sat", Label.CENTER);
- break;
- }
- lMainTopPanel.add(mDayName[i]);
- }
- lMainPanel.add("North", lMainTopPanel);
-
- Panel lMainMainPanel = new Panel();
- lMainMainPanel.setLayout(new GridLayout(6, 7));
- mCell = new Button[6][7];
- for (i = 0; i < 6; i++)
- {
- for (j = 0; j < 7; j++)
- {
- mCell[i][j] = new Button("0");
- lMainMainPanel.add(mCell[i][j]);
- }
- }
- lMainPanel.add("Center", lMainMainPanel);
-
-
- add("Center", lMainPanel);
-
-
- Panel lBottomPanel = new Panel();
- lBottomPanel.setLayout(new GridLayout(1,9));
-
- mYearDown = new Button("-Y");
- lBottomPanel.add(mYearDown);
- mMonthDown = new Button("-M");
- lBottomPanel.add(mMonthDown);
- mWeekDown = new Button("-W");
- lBottomPanel.add(mWeekDown);
- mDayDown = new Button("-D");
- lBottomPanel.add(mDayDown);
-
- mToday = new Button(".");
- lBottomPanel.add(mToday);
-
- mDayUp = new Button("+D");
- lBottomPanel.add(mDayUp);
- mWeekUp = new Button("+W");
- lBottomPanel.add(mWeekUp);
- mMonthUp = new Button("+M");
- lBottomPanel.add(mMonthUp);
- mYearUp = new Button("+Y");
- lBottomPanel.add(mYearUp);
-
- add("South", lBottomPanel);
-
- mDisplayedDate = new Date();
- setDate();
-
- show();
- }
- DEF_ENDLIST
- DEF_EVENT
- public boolean handleEvent(Event pe)
- {
- if (pe.id == Event.ACTION_EVENT)
- {
- if (pe.target == mYearDown) {setDate(YEAR_DOWN); return true;}
- if (pe.target == mMonthDown) {setDate(MONTH_DOWN); return true; }
- if (pe.target == mWeekDown) {setDate(WEEK_DOWN); return true; }
- if (pe.target == mDayDown) {setDate(DAY_DOWN); return true; }
- if (pe.target == mToday) {setDate(); return true; }
- if (pe.target == mDayUp) {setDate(DAY_UP); return true; }
- if (pe.target == mWeekUp) {setDate(WEEK_UP); return true; }
- if (pe.target == mMonthUp) {setDate(MONTH_UP); return true; }
- if (pe.target == mYearUp) {setDate(YEAR_UP); return true; }
- for (int i = 0; i < 6*7; i++)
- {
- if (pe.target == mCell[i/7][i%7])
- {
- try
- {
- int theDate = (new Integer(mCell[i/7][i%7].getLabel())).intValue();
- mDisplayedDate = new Date(mDisplayedDate.getYear()
- ,mDisplayedDate.getMonth()
- ,theDate
- );
- showDate();
- }
- catch(NumberFormatException nfe)
- {
- ;
- }
- break;
- }
- }
- }
- return(super.handleEvent(pe));
- }
- DEF_ENDLIST
- DEF_METHOD
- public void setDate()
- {
- setDate(TODAY);
- }
- DEF_ENDLIST
- DEF_METHOD
- public void setDate(int pSet)
- {
- switch (pSet)
- {
- case YEAR_DOWN:
- mDisplayedDate = new Date(mDisplayedDate.getYear() - 1
- ,mDisplayedDate.getMonth()
- ,mDisplayedDate.getDate()
- );
- break;
- case MONTH_DOWN:
-
- if ((mDisplayedDate.getMonth() - 1) < 0)
- {
- mDisplayedDate = new Date(mDisplayedDate.getYear() - 1
- ,11
- ,mDisplayedDate.getDate()
- );
- }
- else
- {
- mDisplayedDate = new Date(mDisplayedDate.getYear()
- ,mDisplayedDate.getMonth() - 1
- ,mDisplayedDate.getDate()
- );
- }
- break;
- case WEEK_DOWN:
- mDisplayedDate = new Date(mDisplayedDate.getYear()
- ,mDisplayedDate.getMonth()
- ,mDisplayedDate.getDate() - 7
- );
- break;
- case DAY_DOWN:
- mDisplayedDate = new Date(mDisplayedDate.getYear()
- ,mDisplayedDate.getMonth()
- ,mDisplayedDate.getDate() - 1
- );
- break;
- case TODAY:
- mDisplayedDate = new Date();
- case DAY_UP:
- mDisplayedDate = new Date(mDisplayedDate.getYear()
- ,mDisplayedDate.getMonth()
- ,mDisplayedDate.getDate() + 1
- );
- break;
- case WEEK_UP:
- mDisplayedDate = new Date(mDisplayedDate.getYear()
- ,mDisplayedDate.getMonth()
- ,mDisplayedDate.getDate() + 7
- );
- break;
- case MONTH_UP:
- mDisplayedDate = new Date(mDisplayedDate.getYear()
- ,mDisplayedDate.getMonth() + 1
- ,mDisplayedDate.getDate()
- );
- break;
- case YEAR_UP:
- mDisplayedDate = new Date(mDisplayedDate.getYear() + 1
- ,mDisplayedDate.getMonth()
- ,mDisplayedDate.getDate()
- );
- break;
- }
- showDate();
- }
- DEF_ENDLIST
- DEF_METHOD
- public void showDate()
- {
- switch (mDisplayedDate.getMonth())
- {
- case 0:
- mMonth.setText("January");
- break;
- case 1:
- mMonth.setText("Feburary");
- break;
- case 2:
- mMonth.setText("March");
- break;
- case 3:
- mMonth.setText("April");
- break;
- case 4:
- mMonth.setText("May");
- break;
- case 5:
- mMonth.setText("June");
- break;
- case 6:
- mMonth.setText("July");
- break;
- case 7:
- mMonth.setText("August");
- break;
- case 8:
- mMonth.setText("September");
- break;
- case 9:
- mMonth.setText("October");
- break;
- case 10:
- mMonth.setText("November");
- break;
- case 11:
- mMonth.setText("December");
- break;
- }
-
- mYear.setText("" + mDisplayedDate.getYear());
-
- Date lDate = new Date(mDisplayedDate.getYear()
- ,mDisplayedDate.getMonth()
- ,1);
-
- int thisMonth = mDisplayedDate.getMonth();
-
- int i;
- for ( i = 0; i < lDate.getDay(); i++)
- {
- mCell[i/7][i%7].setLabel("");
- mCell[i/7][i%7].disable();
- }
-
- int j;
- for (j = 1; i < 6*7 ; i++, j++)
- {
- lDate = new Date(mDisplayedDate.getYear()
- ,mDisplayedDate.getMonth()
- ,j);
-
- if (thisMonth != lDate.getMonth())
- {
- break;
- }
-
- mCell[i/7][i%7].setLabel("" + j);
- mCell[i/7][i%7].enable(!mDisplayedDate.equals(lDate));
- }
-
- for (; i < 6*7 ; i++)
- {
- mCell[i/7][i%7].setLabel("");
- mCell[i/7][i%7].disable();
- }
- invalidate();
- resize(size());
- }
- DEF_ENDLIST
- DEF_METHOD
- public static void main(String args[])
- {
- new Calender();
- }
- DEF_ENDLIST
- DEF_PROPERTY
- Top
- int
- move(bounds().x, AVALUE);
- AVALUE = bounds().y;
- 0
- DEF_ENDLIST
- DEF_PROPERTY
- Left
- int
- move(AVALUE, bounds().y);
- AVALUE = bounds().x;
- 0
- DEF_ENDLIST
- DEF_PROPERTY
- Height
- int
- resize(bounds().width, AVALUE);
- AVALUE = bounds().height;
- 150
- DEF_ENDLIST
- DEF_PROPERTY
- Width
- int
- resize(AVALUE, bounds().height);
- AVALUE = bounds().width;
- 150
- DEF_ENDLIST
- DEF_ENDCOMPONENT
-