用JAVA帮忙编写一个日历查询系统,非常感谢~!

用JAVA帮忙编写一个日历查询系统,非常感谢~!,第1张

import javautilCalendar;

import javautilScanner;

public class CalendarX {

static Calendar c=CalendargetInstance();

static String[] wd={"SAT","SUN","MON","TUE","WED","THU","FRI",};

public static void main(String[] args) {

Scanner sn = new Scanner(Systemin);

Systemoutprint("Input year:");

int year=snnextInt();

Systemoutprint("Input month:");

int month=snnextInt();

printCalendar(year,month);

}

static void printCalendar(int y,int m){

cset(CalendarYEAR, y);

cset(CalendarMONTH, m-1);

cset(CalendarDATE, 1);

int fd=cget(CalendarDAY_OF_WEEK);

int md=cgetActualMaximum(CalendarDATE);

for(int i=0; i<7; i++)Systemoutprintf("%5s",wd[i]);Systemoutprintln();

for(int i=0; i<fd; i++)Systemoutprintf("%5s","");

for(int i=0; i<md; i++){

Systemoutprintf("%5s",i+1);

if(++fd%7==0)Systemoutprintln();

}

}

}

也不知道你具体需求是什么,以前改过一个日历程序,一共四个java类,放在同一个包里。经测试可以运行。

//Startjava

import javaawt;

import javaxswing;

class Start{

public static void main(String [] args){

DateFrame frame=new DateFrame();

framesetLocationRelativeTo(frame);

framesetResizable(false);

framesetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);

framesetVisible(true);

}

}

//DateInfojava

import javautil;

public class DateInfo{

private int mYear, mMonth;

private int mDayOfMonth, mFristWeek;

public DateInfo(int year, int month) throws DateException{

mYear = year;

if (month < 0 || month > 12){

throw (new DateException());

}

mMonth = month;

mDayOfMonth = getDayOfMonth(mYear, mMonth);

mFristWeek = getFristWeek(mYear, mMonth);

}

private int getDayOfMonth(int year, int month){

int[][] ary = {{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},

{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};

return (ary[isLeapYear(year)][month]);

}

private int isLeapYear(int year){

if (year % 4 == 0 && year % 100 != 0 ||year % 400 == 0){

return (1);

}

else{

return (0);

}

}

private int getFristWeek(int year, int month){

javautilCalendar cal = CalendargetInstance();

calset(year, month - 1, 1);

return (calget(CalendarDAY_OF_WEEK) - 1);

}

public String toString(){

String str;

str = "\t\t" + mYear + "年" + mMonth + "月\n";

str += "日\t一\t二\t三\t四\t五\t六\n";

int i;

for (i = 1; i <= mFristWeek; i++){

str += " \t";

}

for (int j = 1; j <= mDayOfMonth; j++, i++){

str +=j+"\t" ;

if (i % 7 == 0){

str += "\n";

}

}

return (str);

}

}

//DateFramejava

import javaawt;

import javaawtevent;

import javaxswing;

import javautilCalendar;

class DateFrame extends JFrame implements Runnable{

Calendar date=CalendargetInstance();

String[] str={"1","2","3","4","5","6","7","8","9","10","11","12"};

JLabel lblYear=new JLabel("年 ");

JLabel lblMonth=new JLabel("月 ");

JLabel lblDate=new JLabel("现在的时间是:");

JLabel lblShowDate=new JLabel();

// javaxswingJTextField trxt =new JTextField(10);

// trxtsetHorizontalAlignment(JTextFieldRIGHT); //设置文本从右边输入

JComboBox cboMonth=new JComboBox(str);

JComboBox cboYear=new JComboBox();

JTextArea txaShow=new JTextArea();

JPanel pnlNorth=new JPanel();

JPanel pnlSOUTH=new JPanel();

JButton btnShow=new JButton("显示");

JButton btnClose=new JButton("关闭");

JScrollPane jsp=new JScrollPane(txaShow);

Container c=thisgetContentPane();

public DateFrame(){

Thread thread=new Thread(this);

threadstart();

thissetTitle("玩玩日历拉!!!");

thissetSize(300,260);

for (int i = 1990; i<=2025; i++) {

cboYearaddItem(""+i);

}

cboYearsetSelectedItem(""+(dateget(CalendarYEAR)));

cboMonthsetSelectedItem(""+(dateget(CalendarMONTH)+1));

pnlNorthadd(cboYear);

txaShowsetTabSize(4); //设置tab键的距离

txaShowsetForeground(ColorGREEN);

pnlNorthadd(lblYear);

pnlNorthadd(cboMonth);

pnlNorthadd(lblMonth);

pnlNorthadd(lblDate);

pnlNorthadd(lblShowDate);

cadd(pnlNorth,BorderLayoutNORTH);

cadd(jsp);

pnlSOUTHadd(btnShow);

pnlSOUTHadd(btnClose);

cadd(pnlSOUTH,BorderLayoutSOUTH);

btnShowaddActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

int year=IntegerparseInt((String)cboYeargetSelectedItem());

int month=IntegerparseInt((String)cboMonthgetSelectedItem());

try {

DateInfo date=new DateInfo(year,month);

txaShowsetText(""+date);

}

catch (DateException ex) {

exprintStackTrace();

}

}

});

btnCloseaddActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

Systemexit(0);

}

});

}

public void run(){

try {

while(true){

Threadsleep(1000);

int hour=dateget(CalendarHOUR);

int minute=dateget(CalendarMINUTE);

int second=dateget(CalendarSECOND);

String str=hour+":"+minute+":"+second;

lblShowDatesetText(str);

//thisrepaint();

}

}

catch (Exception ex) {

exprintStackTrace();

}

}

}

//DateExceptionjava

public class DateException extends Exception{

public DateException(){

super("日期数据不合法");

}

}

package mycalendar;

import javautil;

class ViewMonth {

int month;

int year;

ViewMonth(final int displayMonth, final int displayYear) {

month = displayMonth;

year = displayYear;

}

private String checkMonth() {

String[] months = {

"1 月" , "2 月" , "3 月",

"4 月" , "5 月" , "6 月",

"7 月" , "8 月" , "9 月",

"10 月" , "11 月" , "12 月"

};

return months[month];

}

private int checkDays() {

int[] numofDays = {

31, 28, 31,

30, 31, 30,

31, 31, 30,

31, 30, 31

};

return numofDays[month];

}

/

使用此方法打印该月的日历

/

void printMonth() {

/ 将该月份起始处的天数留空 /

int initialSpaces = 0;

try {

/ 获取月份名称 /

String monthName = checkMonth();

Systemoutprintln();

Systemoutprintln("\t\t\t " + year + " 年 " + monthName );

Systemoutprintln();

} catch (ArrayIndexOutOfBoundsException ae) {

Systemoutprintln("超出范围 ");

Systemexit(0);

}

GregorianCalendar cal = new GregorianCalendar(year, month, 1);

Systemoutprintln("\t日\t一\t二\t三\t四\t五\t六");

initialSpaces = calget(CalendarDAY_OF_WEEK) - 1;

/ 获取天数 /

int daysInMonth = checkDays();

/ 检查是否为闰年并为二月增加一天 /

if (calisLeapYear(calget(CalendarYEAR)) && month == 1) {

++daysInMonth;

}

for (int ctr = 0; ctr < initialSpaces; ctr++) {

Systemoutprint("\t");

}

for (int ctr = 1; ctr <= daysInMonth; ctr++) {

/ 为单个日期添加空格 /

if (ctr <= 9) {

Systemoutprint(" ");

}

Systemoutprint("\t" + ctr);

/ 检查行的末尾 /

if ((initialSpaces + ctr) % 7 == 0) {

Systemoutprintln();

} else {

Systemoutprint(" ");

}

}

Systemoutprintln();

}

}

class J7上机2 {

protected J7上机2() {

}

public static void main(String[] args) {

int month, year;

if (argslength == 2) {

Systemoutprintln("显示日历");

Systemoutprintln();

int mon = IntegerparseInt(args[0]);

month = mon - 1;

year = IntegerparseInt(args[1]);

} else {

Calendar today = CalendargetInstance();

month = todayget(CalendarMONTH);

year = todayget(CalendarYEAR);

}

ViewMonth mv = new ViewMonth(month, year);

mvprintMonth();

}

}

给你

import javautilDate;

import javautilCalendar;

import javatextDateFormat;

import javatextSimpleDateFormat;

import javatextParseException;

import javaawtColor;

import javaawtFont;

import javaawtPoint;

import javaawtDimension;

import javaawtBorderLayout;

import javaawtFlowLayout;

import javaawtGridLayout;

import javaawtCursor;

import javaawteventActionEvent;

import javaawteventActionListener;

import javaxswingJButton;

import javaxswingJDialog;

import javaxswingJPanel;

import javaxswingJLabel;

import javaxswingJSpinner;

import javaxswingSpinnerNumberModel;

import javaxswingSwingUtilities;

import javaxswingSwingConstants;

import javaxswingeventChangeListener;

import javaxswingeventChangeEvent;

import javaxswingborderLineBorder;

/

@company:NEUSOFT

@Title:日期选择控件

@Description:在原有基础上修改了以下内容:

1 将容器由Frame改为了Dialog,以便在基于对话框的程序中也能够使用

2 将最小日期由1980改为了1950,考虑到目前球员的出生日期可能早于1980年

3 将初始显示格式设置为 yyyy年MM月dd日 格式,原有的小时去掉了,不适合于出生日期字段

/

public class DateChooserJButton extends JButton {

private DateChooser dateChooser = null;

private String preLabel = "";

public DateChooserJButton() {

this(getNowDate());

}

public DateChooserJButton(SimpleDateFormat df, String dateString) {

this();

setText(df, dateString);

}

public DateChooserJButton(Date date) {

this("", date);

}

public DateChooserJButton(String preLabel, Date date) {

if (preLabel != null)

thispreLabel = preLabel;

setDate(date);

setBorder(null);

setCursor(new Cursor(CursorHAND_CURSOR));

addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

if (dateChooser == null)

dateChooser = new DateChooser();

Point p = getLocationOnScreen();

py = py + 30;

dateChoosershowDateChooser(p);

}

});

}

private static Date getNowDate() {

return CalendargetInstance()getTime();

}

private static SimpleDateFormat getDefaultDateFormat() {

return new SimpleDateFormat("yyyy年MM月dd日");

}

// 覆盖父类的方法

public void setText(String s) {

Date date;

try {

date = getDefaultDateFormat()parse(s);

} catch (ParseException e) {

date = getNowDate();

}

setDate(date);

}

public void setText(SimpleDateFormat df, String s) {

Date date;

try {

date = dfparse(s);

} catch (ParseException e) {

date = getNowDate();

}

setDate(date);

}

public void setDate(Date date) {

supersetText(preLabel + getDefaultDateFormat()format(date));

}

public Date getDate() {

String dateString = thisgetText()substring(preLabellength());

try {

return getDefaultDateFormat()parse(dateString);

} catch (ParseException e) {

return getNowDate();

}

}

public String getDateString()

{

Date birth =getDate();

DateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");

return formatDateformat(birth)toString();

//return thisgetText()substring(preLabellength());

}

// 覆盖父类的方法使之无效

//public void addActionListener(ActionListener listener) {

//}

private class DateChooser extends JPanel implements ActionListener,

ChangeListener {

int startYear = 1950; // 默认最小显示年份

int lastYear = 2050; // 默认最大显示年份

int width = 200; // 界面宽度

int height = 200; // 界面高度

Color backGroundColor = Colorgray; // 底色

// 月历表格配色----------------//

Color palletTableColor = Colorwhite; // 日历表底色

Color todayBackColor = Colororange; // 今天背景色

Color weekFontColor = Colorblue; // 星期文字色

Color dateFontColor = Colorblack; // 日期文字色

Color weekendFontColor = Colorred; // 周末文字色

// 控制条配色------------------//

Color controlLineColor = Colorpink; // 控制条底色

Color controlTextColor = Colorwhite; // 控制条标签文字色

Color rbFontColor = Colorwhite; // RoundBox文字色

Color rbBorderColor = Colorred; // RoundBox边框色

Color rbButtonColor = Colorpink; // RoundBox按钮色

Color rbBtFontColor = Colorred; // RoundBox按钮文字色

JDialog dialog;

JSpinner yearSpin;

JSpinner monthSpin;

JSpinner hourSpin;

JButton[][] daysButton = new JButton[6][7];

DateChooser() {

setLayout(new BorderLayout());

setBorder(new LineBorder(backGroundColor, 2));

setBackground(backGroundColor);

JPanel topYearAndMonth = createYearAndMonthPanal();

add(topYearAndMonth, BorderLayoutNORTH);

JPanel centerWeekAndDay = createWeekAndDayPanal();

add(centerWeekAndDay, BorderLayoutCENTER);

}

private JPanel createYearAndMonthPanal() {

Calendar c = getCalendar();

int currentYear = cget(CalendarYEAR);

int currentMonth = cget(CalendarMONTH) + 1;

int currentHour = cget(CalendarHOUR_OF_DAY);

JPanel result = new JPanel();

resultsetLayout(new FlowLayout());

resultsetBackground(controlLineColor);

yearSpin = new JSpinner(new SpinnerNumberModel(currentYear,

startYear, lastYear, 1));

yearSpinsetPreferredSize(new Dimension(48, 20));

yearSpinsetName("Year");

yearSpinsetEditor(new JSpinnerNumberEditor(yearSpin, "####"));

yearSpinaddChangeListener(this);

resultadd(yearSpin);

JLabel yearLabel = new JLabel("年");

yearLabelsetForeground(controlTextColor);

resultadd(yearLabel);

monthSpin = new JSpinner(new SpinnerNumberModel(currentMonth, 1,

12, 1));

monthSpinsetPreferredSize(new Dimension(35, 20));

monthSpinsetName("Month");

monthSpinaddChangeListener(this);

resultadd(monthSpin);

JLabel monthLabel = new JLabel("月");

monthLabelsetForeground(controlTextColor);

resultadd(monthLabel);

hourSpin = new JSpinner(new SpinnerNumberModel(currentHour, 0, 23,

1));

hourSpinsetPreferredSize(new Dimension(35, 20));

hourSpinsetName("Hour");

hourSpinaddChangeListener(this);

resultadd(hourSpin);

JLabel hourLabel = new JLabel("时");

hourLabelsetForeground(controlTextColor);

resultadd(hourLabel);

return result;

}

private JPanel createWeekAndDayPanal() {

String colname[] = { "日", "一", "二", "三", "四", "五", "六" };

JPanel result = new JPanel();

// 设置固定字体,以免调用环境改变影响界面美观

resultsetFont(new Font("宋体", FontPLAIN, 12));

resultsetLayout(new GridLayout(7, 7));

resultsetBackground(Colorwhite);

JLabel cell;

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

cell = new JLabel(colname[i]);

cellsetHorizontalAlignment(JLabelRIGHT);

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

cellsetForeground(weekendFontColor);

else

cellsetForeground(weekFontColor);

resultadd(cell);

}

int actionCommandId = 0;

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

for (int j = 0; j < 7; j++) {

JButton numberButton = new JButton();

numberButtonsetBorder(null);

numberButtonsetHorizontalAlignment(SwingConstantsRIGHT);

numberButtonsetActionCommand(String

valueOf(actionCommandId));

numberButtonaddActionListener(this);

numberButtonsetBackground(palletTableColor);

numberButtonsetForeground(dateFontColor);

if (j == 0 || j == 6)

numberButtonsetForeground(weekendFontColor);

else

numberButtonsetForeground(dateFontColor);

daysButton[i][j] = numberButton;

resultadd(numberButton);

actionCommandId++;

}

return result;

}

private JDialog createDialog(JDialog owner) {

JDialog result = new JDialog(owner, "日期时间选择", true);

resultsetDefaultCloseOperation(JDialogHIDE_ON_CLOSE);

resultgetContentPane()add(this, BorderLayoutCENTER);

resultpack();

resultsetSize(width, height);

return result;

}

void showDateChooser(Point position) {

JDialog owner = (JDialog) SwingUtilities

getWindowAncestor(DateChooserJButtonthis);

if (dialog == null || dialoggetOwner() != owner)

dialog = createDialog(owner);

dialogsetLocation(getAppropriateLocation(owner, position));

flushWeekAndDay();

dialogsetVisible(true);

}

Point getAppropriateLocation(JDialog owner, Point position) {

Point result = new Point(position);

Point p = ownergetLocation();

int offsetX = (positionx + width) - (px + ownergetWidth());

int offsetY = (positiony + height) - (py + ownergetHeight());

if (offsetX > 0) {

resultx -= offsetX;

}

if (offsetY > 0) {

resulty -= offsetY;

}

return result;

}

private Calendar getCalendar() {

Calendar result = CalendargetInstance();

resultsetTime(getDate());

return result;

}

private int getSelectedYear() {

return ((Integer) yearSpingetValue())intValue();

}

private int getSelectedMonth() {

return ((Integer) monthSpingetValue())intValue();

}

private int getSelectedHour() {

return ((Integer) hourSpingetValue())intValue();

}

private void dayColorUpdate(boolean isOldDay) {

Calendar c = getCalendar();

int day = cget(CalendarDAY_OF_MONTH);

cset(CalendarDAY_OF_MONTH, 1);

int actionCommandId = day - 2 + cget(CalendarDAY_OF_WEEK);

int i = actionCommandId / 7;

int j = actionCommandId % 7;

if (isOldDay)

daysButton[i][j]setForeground(dateFontColor);

else

daysButton[i][j]setForeground(todayBackColor);

}

private void flushWeekAndDay() {

Calendar c = getCalendar();

cset(CalendarDAY_OF_MONTH, 1);

int maxDayNo = cgetActualMaximum(CalendarDAY_OF_MONTH);

int dayNo = 2 - cget(CalendarDAY_OF_WEEK);

for (int i = 0; i < 6; i++) {

for (int j = 0; j < 7; j++) {

String s = "";

if (dayNo >= 1 && dayNo <= maxDayNo)

s = StringvalueOf(dayNo);

daysButton[i][j]setText(s);

dayNo++;

}

}

dayColorUpdate(false);

}

public void stateChanged(ChangeEvent e) {

JSpinner source = (JSpinner) egetSource();

Calendar c = getCalendar();

if (sourcegetName()equals("Hour")) {

cset(CalendarHOUR_OF_DAY, getSelectedHour());

setDate(cgetTime());

return;

}

dayColorUpdate(true);

if (sourcegetName()equals("Year"))

cset(CalendarYEAR, getSelectedYear());

else

// (sourcegetName()equals("Month"))

cset(CalendarMONTH, getSelectedMonth() - 1);

setDate(cgetTime());

flushWeekAndDay();

}

public void actionPerformed(ActionEvent e) {

JButton source = (JButton) egetSource();

if (sourcegetText()length() == 0)

return;

dayColorUpdate(true);

sourcesetForeground(todayBackColor);

int newDay = IntegerparseInt(sourcegetText());

Calendar c = getCalendar();

cset(CalendarDAY_OF_MONTH, newDay);

setDate(cgetTime());

}

}

}

这是一个专门的选日期的类 ,你看看完了调用就行了

输入本年的某个月后,屏幕输出这个月的月历,每星期一行,从星期日开始,到星期六结束。

import javautil;

public class Year{

/

判断是否为闰年

/

public boolean getIsRun(int year){

if((year%4==0 && year %100 !=0)||(year%400==0)){

return true;

}

return false;

}

/

返回某年某月有多少天。

/

public int getDay(int year ,int month){

int[] day={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};//闰年月份

int[] day1={31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};//普通月份

if(thisgetIsRun(year)){

return day[month+1];

}else{

return day1[month+1];

}

}

/

返回这个月的1号是星期几

/

public int getWeek(int year,int month){

Date date=new Date();

datesetYear(year);

datesetMonth(month);

Calendar calendar=CalendargetInstance();

calendarsetTime(date);

return calendarget(calendarDAY_OF_WEEK);

}

/

打印出来,嘎嘎

/

public void showPrint(int year,int month){

int day=thisgetDay(year,month);

int week=thisgetWeek(year,month);

Systemoutprintln("日\t一\t二\t三\t四\t五\t六\n");

for(int i=0;i<=week;i++){//

Systemoutprint (" \t");

}

for(int j=1;j<=day;j++){

if((j+week)%7==0){

Systemoutprintln ();

}

Systemoutprint (j+"\t");

}

// Systemoutprintln(week);

}

public static void main(String[] args){

Year y=new Year();

yshowPrint(2008,3);

}

}

import javaawtBorderLayout;

import javaawtColor;

import javaawtDimension;

import javaawtGridLayout;

import javaawtSystemColor;

import javaawteventActionEvent;

import javaawteventKeyEvent;

import javaawteventMouseEvent;

import javautilCalendar;

import javautilGregorianCalendar;

import javautilLocale;

import javautilDate;

import javautilStringTokenizer;

import javaxswingBorderFactory;

import javaxswingJButton;

import javaxswingJFrame;

import javaxswingJLabel;

import javaxswingJPanel;

import javaxswingJTextField;

import javaxswingJToggleButton;

import javaxswingSwingConstants;

import javaxswingUIManager;

/

<p>Title: Swing日历</p>

<p>Description: *** 作日期</p>

@author duxu2004

@version 101

/

class JCalendar extends JPanel{

//动态表示年月日

private int year=0;

private int month=0;

private int day=0;

//主面板

private JPanel Main = new JPanel();

//日面板

private JPanel jPanelDay = new JPanel();

//月面板

private JPanel jPanelMonth = new JPanel();

//年的输入位置

private JTextField Year = new JTextField();

//月的输入位置

private JTextField Month = new JTextField();

//减少月份

private JButton MonthDown = new JButton();

//增加月份

private JButton MonthUp = new JButton();

private JPanel jPanelButton = new JPanel();

//减少年份

private JButton YearDown = new JButton();

//增加年份

private JButton YearUp = new JButton();

//显示日期的位置

private JLabel Out = new JLabel();

//中国时区,以后可以从这里扩展可以设置时区的功能

private Locale l=LocaleCHINESE;

//主日历

private GregorianCalendar cal=new GregorianCalendar(l);

//星期面板

private JPanel weekPanel=new JPanel();

//天按钮组

private JToggleButton[] days=new JToggleButton[42];

//天面板

private JPanel Days = new JPanel();

//标示

private JLabel jLabel1 = new JLabel();

private JLabel jLabel2 = new JLabel();

private JLabel jLabel3 = new JLabel();

private JLabel jLabel4 = new JLabel();

private JLabel jLabel5 = new JLabel();

private JLabel jLabel6 = new JLabel();

private JLabel jLabel7 = new JLabel();

//当前选择的天数按钮

private JToggleButton cur=null;

//月份天数数组,用来取得当月有多少天

// 1 2 3 4 5 6 7 8 9 10 11 12

private int[] mm={31,28,31,30,31,30,31,31,30,31,30,31};

//空日期构造函数

public JCalendar() {

try {

jbInit();

}

catch(Exception e) {

eprintStackTrace();

}

}

//带日期设置的构造函数

public JCalendar(int year, int month, int day) {

calset(year, month, day);

try {

jbInit();

}

catch (Exception e) {

eprintStackTrace();

}

}

//带日历输入的构造函数

public JCalendar(GregorianCalendar calendar) {

cal=calendar;

try {

jbInit();

}

catch (Exception e) {

eprintStackTrace();

}

}

//带日期输入的构造函数

public JCalendar(Date date) {

calsetTime(date);

try {

jbInit();

}

catch (Exception e) {

eprintStackTrace();

}

}

//初始化组件

private void jbInit() throws Exception {

//初始化年、月、日

iniCalender();

thissetLayout(new BorderLayout());

thissetBorder(BorderFactorycreateRaisedBevelBorder());

thissetMaximumSize(new Dimension(200, 200));

thissetMinimumSize(new Dimension(200, 200));

thissetPreferredSize(new Dimension(200, 200));

MainsetLayout(new BorderLayout());

MainsetBackground(SystemColorinfo);

MainsetBorder(null);

OutsetBackground(ColorlightGray);

OutsetHorizontalAlignment(SwingConstantsCENTER);

OutsetMaximumSize(new Dimension(100, 19));

OutsetMinimumSize(new Dimension(100, 19));

OutsetPreferredSize(new Dimension(100, 19));

jLabel1setForeground(Colorred);

jLabel1setHorizontalAlignment(SwingConstantsCENTER);

jLabel1setHorizontalTextPosition(SwingConstantsCENTER);

jLabel1setText("日");

jLabel2setForeground(Colorblue);

jLabel2setHorizontalAlignment(SwingConstantsCENTER);

jLabel2setHorizontalTextPosition(SwingConstantsCENTER);

jLabel2setText("六");

jLabel3setHorizontalAlignment(SwingConstantsCENTER);

jLabel3setHorizontalTextPosition(SwingConstantsCENTER);

jLabel3setText("五");

jLabel4setHorizontalAlignment(SwingConstantsCENTER);

jLabel4setHorizontalTextPosition(SwingConstantsCENTER);

jLabel4setText("四");

jLabel5setHorizontalAlignment(SwingConstantsCENTER);

jLabel5setHorizontalTextPosition(SwingConstantsCENTER);

jLabel5setText("三");

jLabel6setBorder(null);

jLabel6setHorizontalAlignment(SwingConstantsCENTER);

jLabel6setHorizontalTextPosition(SwingConstantsCENTER);

jLabel6setText("二");

jLabel7setBackground(ColorlightGray);

jLabel7setForeground(Colorblack);

jLabel7setBorder(null);

jLabel7setHorizontalAlignment(SwingConstantsCENTER);

jLabel7setHorizontalTextPosition(SwingConstantsCENTER);

jLabel7setText("一");

weekPanelsetBackground(UIManagergetColor("InternalFrameactiveTitleGradient"));

weekPanelsetBorder(BorderFactorycreateEtchedBorder());

weekPanelsetLayout(new GridLayout(1,7));

weekPaneladd(jLabel1, null);

weekPaneladd(jLabel7, null);

weekPaneladd(jLabel6, null);

weekPaneladd(jLabel5, null);

weekPaneladd(jLabel4, null);

weekPaneladd(jLabel3, null);

weekPaneladd(jLabel2, null);

MonthUpsetAlignmentX((float) 00);

MonthUpsetActionMap(null);

jPanelMonthsetBackground(SystemColorinfo);

jPanelMonthsetLayout(new BorderLayout());

jPanelMonthsetBorder(BorderFactorycreateEtchedBorder());

MonthsetBorder(null);

MonthsetHorizontalAlignment(SwingConstantsCENTER);

MonthaddMouseListener(new javaawteventMouseAdapter() {

public void mouseClicked(MouseEvent e) {

Month_mouseClicked(e);

}

});

MonthaddKeyListener(new javaawteventKeyAdapter() {

public void keyPressed(KeyEvent e) {

Month_keyPressed(e);

}

});

MonthDownsetBorder(null);

MonthDownsetText("\u25C4");

MonthDownaddActionListener(new javaawteventActionListener() {

public void actionPerformed(ActionEvent e) {

MonthDown_actionPerformed(e);

}

});

MonthUpsetBorder(null);

MonthUpsetText("\u25BA");

MonthUpaddActionListener(new javaawteventActionListener() {

public void actionPerformed(ActionEvent e) {

MonthUp_actionPerformed(e);

}

});

jPanelButtonsetLayout(null);

jPanelButtonsetBorder(null);

jPanelButtonaddComponentListener(new javaawteventComponentAdapter() {

public void componentResized(javaawteventComponentEvent evt) {

jPanelButtonComponentResized(evt);

}

});

YearsetBorder(BorderFactorycreateEtchedBorder());

YearsetMaximumSize(new Dimension(80, 25));

YearsetMinimumSize(new Dimension(80, 25));

YearsetPreferredSize(new Dimension(80, 25));

YearsetHorizontalAlignment(SwingConstantsCENTER);

YearaddMouseListener(new javaawteventMouseAdapter() {

public void mouseClicked(MouseEvent e) {

Year_mouseClicked(e);

}

});

YearaddKeyListener(new javaawteventKeyAdapter() {

public void keyPressed(KeyEvent e) {

Year_keyPressed(e);

}

});

YearDownsetBorder(null);

YearDownsetMaximumSize(new Dimension(16, 16));

YearDownsetMinimumSize(new Dimension(16, 16));

YearDownsetPreferredSize(new Dimension(16, 16));

YearDownsetSize(new Dimension(16, 16));

YearDownsetText("▼");

YearDownaddActionListener(new javaawteventActionListener() {

public void actionPerformed(ActionEvent e) {

YearDown_actionPerformed(e);

}

});

YearUpsetBorder(null);

YearUpsetMaximumSize(new Dimension(16, 16));

YearUpsetMinimumSize(new Dimension(16, 16));

YearUpsetPreferredSize(new Dimension(16, 16));

YearUpsetSize(new Dimension(16, 16));

YearUpsetText("▲");

YearUpaddActionListener(new javaawteventActionListener() {

public void actionPerformed(ActionEvent e) {

YearUp_actionPerformed(e);

}

});

jPanelDaysetLayout(new BorderLayout());

DayssetLayout(new GridLayout(6,7));

DayssetBackground(SystemColorinfo);

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

days[i]=new JToggleButton();

days[i]setBorder(null);

days[i]setBackground(SystemColorinfo);

days[i]setHorizontalAlignment(SwingConstantsCENTER);

days[i]setHorizontalTextPosition(SwingConstantsCENTER);

//days[i]setSize(l,l);

days[i]addActionListener(new javaawteventActionListener(){

public void actionPerformed(ActionEvent e) {

day=IntegerparseInt(((JToggleButton)egetSource())getText());

showDate();

showDays();

}

});

Daysadd(days[i]);

}

thisadd(Main, BorderLayoutNORTH);

thisadd(jPanelDay, BorderLayoutCENTER);

thisadd(jPanelMonth, BorderLayoutSOUTH);

Mainadd(Year, BorderLayoutCENTER);

Mainadd(Out, BorderLayoutWEST);

Mainadd(jPanelButton, BorderLayoutEAST);

jPanelButtonadd(YearUp);

jPanelButtonadd(YearDown);

jPanelDayadd(weekPanel,BorderLayoutNORTH);

jPanelDayadd(Days, BorderLayoutCENTER);

jPanelMonthadd(Month, BorderLayoutCENTER);

jPanelMonthadd(MonthDown, BorderLayoutWEST);

jPanelMonthadd(MonthUp, BorderLayoutEAST);

showMonth();

showYear();

showDate();

showDays();

}

//自定义重画年选择面板

void jPanelButtonComponentResized(javaawteventComponentEvent evt){

YearUpsetLocation(0,0);

YearDownsetLocation(0,YearUpgetHeight());

jPanelButtonsetSize(YearUpgetWidth(),YearUpgetHeight()2);

jPanelButtonsetPreferredSize(new Dimension(YearUpgetWidth(),YearUpgetHeight()2));

jPanelButtonupdateUI();

}

//测试用

public static void main(String[] args){

JFrame f=new JFrame();

fsetContentPane(new JCalendar());

fpack();

//fsetResizable(false);

fshow();

}

//增加年份

void YearUp_actionPerformed(ActionEvent e) {

year++;

showYear();

showDate();

showDays();

}

//减少年份

void YearDown_actionPerformed(ActionEvent e) {

year--;

showYear();

showDate();

showDays();

}

//减少月份

void MonthDown_actionPerformed(ActionEvent e) {

month--;

if(month<0) {

month = 11;

year--;

showYear();

}

showMonth();

showDate();

showDays();

}

//增加月份

void MonthUp_actionPerformed(ActionEvent e) {

month++;

if(month==12) {

month=0;

year++;

showYear();

}

showMonth();

showDate();

showDays();

}

//初始化年月日

void iniCalender(){

year=calget(CalendarYEAR);

month=calget(CalendarMONTH);

day=calget(CalendarDAY_OF_MONTH);

}

//刷新月份

void showMonth(){

MonthsetText(IntegertoString(month+1)+"月");

}

//刷新年份

void showYear(){

YearsetText(IntegertoString(year)+"年");

}

//刷新日期

void showDate(){

OutsetText(IntegertoString(year)+"-"+IntegertoString(month+1)+"-"+IntegertoString(day));

}

//重画天数选择面板

void showDays() {

calset(year,month,1);

int firstDayOfWeek = calget(CalendarDAY_OF_WEEK);

int n=mm[month];

if(calisLeapYear(year)&&month==1) n++;

int i=0;

for(;i<firstDayOfWeek-1;i++){

days[i]setEnabled(false);

days[i]setSelected(false);

days[i]setText("");

}

int d=1;

for(;d<=n;d++){

days[i]setText(IntegertoString(d));

days[i]setEnabled(true);

if(d==day) days[i]setSelected(true);

else days[i]setSelected(false);;

i++;

}

for(;i<42;i++){

days[i]setEnabled(false);

days[i]setSelected(false);

days[i]setText("");

}

}

//单击年份面板选择整个年份字符串

void SelectionYear(){

YearsetSelectionStart(0);

YearsetSelectionEnd(YeargetText()length());

}

//单击月份面板选择整个月份字符串

void SelectionMonth(){

MonthsetSelectionStart(0);

MonthsetSelectionEnd(MonthgetText()length());

}

//月份面板响应鼠标单击事件

void Month_mouseClicked(MouseEvent e) {

//SelectionMonth();

inputMonth();

}

//检验输入的月份

void inputMonth(){

String s;

if(MonthgetText()endsWith("月"))

{

s=MonthgetText()substring(0,MonthgetText()length()-1);

}

else s=MonthgetText();

month=IntegerparseInt(s)-1;

thisshowMe();

}

//月份面板键盘敲击事件响应

void Month_keyPressed(KeyEvent e) {

if(egetKeyChar()==10)

inputMonth();

}

//年份面板响应鼠标单击事件

void Year_mouseClicked(MouseEvent e) {

//SelectionYear();

inputYear();

}

//年份键盘敲击事件响应

void Year_keyPressed(KeyEvent e) {

//Systemoutprint(new Integer(egetKeyChar())byteValue());

if(egetKeyChar()==10)

inputYear();

}

//检验输入的年份字符串

void inputYear() {

String s;

if(YeargetText()endsWith("年"))

{

s=YeargetText()substring(0,YeargetText()length()-1);

}

else s=YeargetText();

year=IntegerparseInt(s);

thisshowMe();

}

//以字符串形式返回日期,yyyy-mm-dd

public String getDate(){return OutgetText();}

//以字符串形式输入日期,yyyy-mm-dd

public void setDate(String date){

if(date!=null){

StringTokenizer f = new StringTokenizer(date, "-");

if(fhasMoreTokens())

year = IntegerparseInt(fnextToken());

if(fhasMoreTokens())

month = IntegerparseInt(fnextToken());

if(fhasMoreTokens())

day = IntegerparseInt(fnextToken());

calset(year,month,day);

}

thisshowMe();

}

//以日期对象形式输入日期

public void setTime(Date date){

calsetTime(date);

thisiniCalender();

thisshowMe();

}

//返回日期对象

public Date getTime(){return calgetTime();}

//返回当前的日

public int getDay() {

return day;

}

//设置当前的日

public void setDay(int day) {

thisday = day;

calset(thisyear,thismonth,thisday);

thisshowMe();

}

//设置当前的年

public void setYear(int year) {

thisyear = year;

calset(thisyear,thismonth,thisday);

thisshowMe();

}

//返回当前的年

public int getYear() {

return year;

}

//返回当前的月

public int getMonth() {

return month;

}

//设置当前的月

public void setMonth(int month) {

thismonth = month;

calset(thisyear,thismonth,thisday);

thisshowMe();

}

//刷新

public void showMe(){

thisshowDays();

thisshowMonth();

thisshowYear();

thisshowDate();

}

}

public class TestJCalendar {

public static void main(String[] args) {

JFrame f=new JFrame();

fsetContentPane(new JCalendar());

fpack();

//fsetResizable(false);

fshow();

}

}

以上就是关于用JAVA帮忙编写一个日历查询系统,非常感谢~!全部的内容,包括:用JAVA帮忙编写一个日历查询系统,非常感谢~!、求Java 日历的小程序的源代码、用java程序编一个某年某月的日历等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9807272.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-02
下一篇 2023-05-02

发表评论

登录后才能评论

评论列表(0条)

保存