Object-Oriented Programming

Source: Internet
Author: User

First, the purpose of design

The object-oriented program design is a comprehensive comprehensive exercise after the course of Java 6 programming, which is the necessary concentrated practice after studying the theory course. The goal of object-oriented program design is to improve the students ' ability of comprehensive application of the knowledge, which requires us to use the knowledge we learned in the theory course and realize the Java application of certain scale. This course design also lays a solid foundation for our future graduation design and concrete work practice.

Ii. Design Tasks

The Java calendar designs a Java calendar that requires a simple calendar written in Java, which only needs to be entered in the year and month to print out the corresponding month's calendar. Requires a simple user interface.

Third, conceptual design

1, when the user needs to query the calendar for the specified year and year, the user will select the box within the month change, the system to obtain information and set a monthly calendar.

2, the user click on the mouse to select a date, the system can be used to the Blue square box that date, indicating that the system has chosen that day.

Demand analysis

For the perpetual calendar system, its main function is to view the date of the day (year, month, day), view the time, view the calendar of other years, and identify the selected date. The main use process is to view the perpetual calendar system, view other month or year calendars, check other dates to view the date of the day. The use cases for the main features are described below:

(1) View perpetual calendar

1, enter the million calendar system;

2, the system gets the date of the day and set the calendar for the current month, the blue box selected the day date;

(2) query other year of the month

There are two ways to change the year, one is to select the year, and the other is to press the key to select the previous or next year.

Drop-down menu select year:

1. Click the drop-down menu to select the year;

2, the system to obtain the selected year;

3. The system is set to the month calendar of the selected year and is displayed in the interface.

Press to select previous year (or next year):

1, click Select "Year-" (or "Year +") button;

2, the system gets the year in the selection box;

3, the system obtains the year number minus 1 (or plus 1);

4. Set the year in the selection box to the year that has changed;

5. The system is set to the month calendar for the changed year and is displayed in the interface.

(3) Search for other months of the year

There are two ways to change the month, one is to select the month, the other is to press the key to select the last month or the next month.

Drop-down menu select Month:

1. Click the drop-down menu to select the month and select the year;

2, the system to obtain the selected month;

3, the system set the selected month for the current year's calendar and displayed in the interface.

Press to select last month (or next January):

1. Click the button to select "Month-" (or "month +");

2, the system gets the month in the selection box;

3, the system to obtain the number of months minus 1 (or plus 1);

4. Set the month in the selection box to the changed month;

5. The system is set to the month calendar of the year that has changed and is displayed on the interface.

(4) Select a different date to view

1, click on other dates;

2, the system for all the date of the label to listen to determine the click of the label;

3. Returns the array subscript of the clicked label;

4. Set a blue border on the subscript label to indicate that it is selected.

(5) View date of day

1, click "Today" button;

2, the system to obtain today's date;

3. Set the year and month selection box to the date of day;

4, the system is set for the day month calendar and display in the interface;

5, Judge the date on which label on the day;

6. Returns the array subscript of the clicked label;

7. Set a blue border on the subscript label to indicate that it is selected.

Design ideas

The interface of this course is composed of two modules, which consists of two parts: the table Head module and the Calendar module.

(1) The table header module has the query input part and the time display part:

1, two drop-down lists are used to select the year and month, such as the year after the change of the system with getshowyear () to obtain the Chinese year in the combo box, Getcombyear () converted to English format, the user selected year, At the same time use Getmonthdays () and Getinitweek () to get the interface settings, and finally, with Setdays () set up the user requirements of the calendar, change month similarly;

2. Four button buttons are used to implement year-, year +, month-, month +, if "Year +" is selected, the system uses Getshowyear () and getcombyear () to obtain the year in the combo box, add 1 to its year, and display the changed year in the combo box. Calculate the calendar arrangement, and use Setdays () set out the user's required calendar, the other buttons the same;

3, a button buttons for the implementation of today's date of the search, when the user selected "Today", the system with Getnowyear () and Getnowmonth () to get the date of the day, and call Setnowday () Set the system combo box month to date, display month calendar, At the same time, the system uses Getnowday () to obtain the date of the day, with the Labelday[i].setborder (BORDER1) statement will be the date of the day with a blue border to indicate the selection;

4. Create a label to display the time, monitor the system time and display.

(2) Add the result display part of the system on the Calendar module:

1, the part originally displayed as the day and month of the month calendar, after changing the year, get need to display the number of months m and the month 1th is from Labelday[n] start after the order from add to labelday[m+n], experience the weekend with Setforeground (color.red) Set the font to appear in red;

2, the labelday tag to listen, if the mouse click on a label, determine the number of the label, with SetBorder () for the label set a blue border and setbordr (null) to clear the previous border.

Class design

This program creates a Aidycalender class that includes a change in the month-to-month display of the calendar interface and the display of time, mainly including the function as shown in table 1:

Table -1 Aidycalender

Interface design

Interface This interface is composed of the input selection part and the central result display part of the upper table header module. Input section Create two drop-down list select year and 5 function buttons to implement the basic operation of the calendar; The results show that the month calendar interface is set up based on the day of the month and the number of days of the month.

The main interface Setup code is as follows:

———————————— added on Sunday to six —————————————

for (int i=0;i<7;i++)

{

Labelweek[i] = new JLabel ();

Labelweek[i].sethorizontalalignment (0);

if (i==0| | I==6)

{

Labelweek[i].setforeground (color.red); Set the weekend to red

Labelweek[i].setfont (New Font ("Neo-Arial", font.bold,18));

}

Else

{

Labelweek[i].setforeground (Color.Black);

Labelweek[i].setfont (New Font ("Neo-Arial", font.plain,18));

}

Labelweek[i].settext (Stringweekcn[i]); Panel2.add (Labelweek[i]);

}

Label ———————————— plus date —————————————

for (int i= 0;i<42;i++)

{

Labelday[i] = new JLabel ();

Labelday[i].sethorizontalalignment (0); Set the horizontal alignment of text

Labelday[i].settext ("");

Panel2.add (Labelday[i]);

Labelday[i].addmouselistener (listener); To listen for a label

}

———————————— set up a monthly calendar ————————————————

public void Setdays (Int. monthdays,int Initweek,int Day)

{

Setdatenull ();

for (int i=initweek;i<initweek+monthdays+1;i++)//initweek Initial Week

{

Labelday[i].setfont (New Font ("Blackbody", font.bold,18)); Set the font for the date

if ((i-initweek+1) ==day)//If the date is today

{

for (int j=0;j<42;j++)

Labelday[j].setborder (NULL);

Labelday[i].setborder (Border1); Select date of day

}

if ((i%7==0) | | | (i%7==6))

Labelday[i].setforeground (color.red);

else Labelday[i].setforeground (Color.Black);

Labelday[i].settext (string.valueof (i-initweek+1));

}

for (int i=initweek+monthdays;i<42;i++)

Labelday[i].settext ("");

}

4.2.3 Function implementation

1, the implementation of the main code of the month query is as follows:

——————————— gets the year and month in the combo box —————————

public int getcomboyear ()

{

Return Combo1.getselectedindex () +1;

}

public int Getcombomonth ()

{

return Combo2.getselectedindex ();

}

————————— returns 1th in the current month, starting from the day of the week ————————

public int Getinitweek (String initweek)

{

int nowweek = 0; Nowweek Day of the week in the system date

for (int i = 0;i<7;i++)

{

if (Initweek.equalsignorecase (Stringweeken[i]))

{

Nowweek = i; Break

}

}

return nowweek;

}

—————————————— returns the number of days of the selected month ——————————————

public int getmonthdays (int year, int month)

{

Switch (month)

{

Case 3:

Case 5:

Case 8:

Case 10:return 30;//Xiao Yue returns 30 days

Case 1:

if (Gregoriancalendar.isleapyear (year))

Isleapyear (year) determines whether the specified years in the current era are leap.

return 29;

else return 28; Leap year February returns 29 days, common year returns 28 days

Default:return 31; Otsuki return 31 days

}

}

——————————————— set up a monthly calendar —————————————————

public void Setdays (Int. monthdays,int Initweek,int Day)

{

Setdatenull ();

for (int i=initweek;i<initweek+monthdays+1;i++)

Initweek Initial Week

{

Labelday[i].setfont (New Font ("Blackbody", font.bold,18));

Set the font for the date

if ((i-initweek+1) ==day)//If the date is today

{

for (int j=0;j<42;j++);

Labelday[j].setborder (NULL);

Labelday[i].setborder (Border1); Select date of day

}

if ((i%7==0) | | | (i%7==6))

Labelday[i].setforeground (color.red);

else Labelday[i].setforeground (Color.Black);

Labelday[i].settext (string.valueof (i-initweek+1));

}

for (int i=initweek+monthdays;i<42;i++)

Labelday[i].settext ("");

}

2. The main code to implement the Select Date function is as follows:

————————————— set the blue border —————————————

Private Border Border = Borderfactory.createraisedbevelborder ();

Private Border Border1 = Borderfactory.createlineborder (color.cyan,8);

Blue selection Border

———————— determine which label was clicked and respond accordingly ——————

MouseListener listener = new Mouseadapter ()

{

public void mouseclicked (MouseEvent e)

{

for (int j=0;j<42;j++)

{

Labelday[j].setborder (NULL);

if ((JLabel) E.getsource () ==labelday[j])

Labelday[j].setborder (Border1);

}

}

};

Object-Oriented Programming

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.