📄 wilson.java
字号:
/*
* @(#)Wilson.java 1.0 04/06/28
*
* You can modify the template of this file in the
* directory ..\JCreator\Templates\Template_1\Project_Name.java
*
* You can also create your own project template by making a new
* folder in the directory ..\JCreator\Template\. Use the other
* templates as examples.
*
*/
package myprojects.wilson;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class Wilson extends JFrame implements ActionListener {
JComboBox Month = new JComboBox();
JComboBox Year = new JComboBox();
JLabel l1 = new JLabel("年份");
JLabel l2 = new JLabel("月份");
Date now = new Date();
JLabel[] label_day = new JLabel[49];
JButton b1 = new JButton("确定");
JButton b2 = new JButton("现在");
int now1 = now.getYear() + 1900;
int now2 = now.getMonth();
boolean bool = false;
String year_int = null;
int month_int;
JPanel pane1 = new JPanel();
JPanel pane2 = new JPanel();
JPanel pane3 = new JPanel();
public Wilson() {
super("2005年日历");
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClose(WindowEvent e) {
System.out.print("CLOSING THE WIN");
System.exit(0);
}
});
setResizable(false);
for (int i = now1 + 1 ; i <= now1 + 1; i++) {
Year.addItem(i + "");
}
for (int i = 1; i < 13; i++) {
Month.addItem(i + "");
}
Year.setSelectedIndex(0);
pane1.add(l1);
pane1.add(Year);
Month.setSelectedIndex(now2);
pane1.add(l2);
pane1.add(Month);
pane1.add(b1);
pane1.add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
pane1.setBackground(Color.white);
pane2.setLayout(new GridLayout(7, 7, 10, 10));
pane2.setBackground(Color.white);
for (int i = 0; i < 49; i++) {
label_day[i] = new JLabel(" ");
pane2.add(label_day[i]);
}
this.setDay();
pane3.setLayout(new BorderLayout());
setContentPane(pane2);
setContentPane(pane1);
pane3.add(pane2, BorderLayout.SOUTH);
pane3.add(pane1, BorderLayout.NORTH);
setContentPane(pane3);
pack();
show();
}
void setDay() {
if (bool) {
year_int = now1 + "";
month_int = now2;
} else {
year_int = Year.getSelectedItem().toString();
month_int = Month.getSelectedIndex();
}
int year_sel = Integer.parseInt(year_int) - 1900;
Date dt = new Date(year_sel, month_int, 1);
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(dt);
String week[] = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
int day = 0;
int day_week = 0;
for (int i = 0; i < 7; i++) {
label_day[i].setText(week[i]);
}
if (month_int == 0 || month_int == 2 || month_int == 4 || month_int == 6 || month_int == 7 || month_int == 9 || month_int == 11) {
day = 31;
} else if (
month_int == 3
|| month_int == 5
|| month_int == 8
|| month_int == 10) {
day = 30;
} else {
if (cal.isLeapYear(year_sel)) {
day = 29;
} else {
day = 28;
}
}
day_week = 7 + dt.getDay();
int count = 1;
for (int i = day_week; i < day_week + day; count++, i++) {
if (i % 7 == 0 || i == 13 || i == 20 || i == 27 || i == 48 || i == 34 || i == 41) {
if (i == day_week + now.getDate() - 1) {
label_day[i].setForeground(Color.blue);
label_day[i].setText(count + "");
} else {
label_day[i].setForeground(Color.red);
label_day[i].setText(count + "");
}
} else {
if (i == day_week + now.getDate() - 1) {
label_day[i].setForeground(Color.blue);
label_day[i].setText(count + "");
} else {
label_day[i].setForeground(Color.black);
label_day[i].setText(count + "");
}
}
}
if (day_week == 0) {
for (int i = day; i < 49; i++) {
label_day[i].setText(" ");
}
} else {
for (int i = 7; i < day_week; i++) {
label_day[i].setText(" ");
}
for (int i = day_week + day; i < 49; i++) {
label_day[i].setText(" ");
}
}
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == b1) {
bool = false;
this.setDay();
} else if (e.getSource() == b2) {
bool = true;
Year.setSelectedIndex(10);
Month.setSelectedIndex(now2);
this.setDay();
}
}
public static void main(String[] args) {
Wilson ct = new Wilson();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -