求助,帮忙修改个JAVA日历代码
http://blog.csdn.net/jxzhoumin/archive/2007/12/04/1917137.aspx汗,代码太长了。各位大大辛苦点,地址在上面,帮...
http://blog.csdn.net/jxzhoumin/archive/2007/12/04/1917137.aspx
汗,代码太长了。各位大大辛苦点,地址在上面,帮帮忙啊。第一次弄这东西。具体问题就是:显示可以,没有问题,但是不知道为什么有什么选择年月查看时,显示的就不对了,有的对,有的不对。
那位仁兄 你哪来的代码,里面一堆错。 展开
汗,代码太长了。各位大大辛苦点,地址在上面,帮帮忙啊。第一次弄这东西。具体问题就是:显示可以,没有问题,但是不知道为什么有什么选择年月查看时,显示的就不对了,有的对,有的不对。
那位仁兄 你哪来的代码,里面一堆错。 展开
1个回答
展开全部
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
class DateWin extends JFrame implements ItemListener {
private static final long serialVersionUID = 1L;
Calendar cd = null;
int years;
int months;
int dates;
JTable table;
Object date[][];
Object name[] = { "日", "一", "二", "三", "四", "五", "六" };
JComboBox year, month;
JLabel label1, label2;
JPanel panel;
DateWin(String s) {
super(s);
setSize(400, 300);
setLocation(120, 120);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
year = new JComboBox();
for (int i = 0; i < 30; i++) {
int years = 1990 + i;
year.addItem(years);
}
month = new JComboBox();
for (int i = 1; i < 13; i++) {
month.addItem(i);
}
label1 = new JLabel("请选择年份:");
label2 = new JLabel("请选择月份:");
panel = new JPanel();
panel.add(label1);
panel.add(year);
panel.add(label2);
panel.add(month);
Container con = getContentPane();
con.setLayout(new BorderLayout());
con.add(panel, BorderLayout.NORTH);
cd = new GregorianCalendar();
years = cd.get(Calendar.YEAR);
year.setSelectedItem(years);
months = cd.get(Calendar.MONTH) + 1;
month.setSelectedItem(months);
cd.set(Calendar.DATE, 1);
int dateNumber = cd.getActualMaximum(Calendar.DATE);
int firstDay = cd.get(Calendar.DAY_OF_WEEK) - 1;
int count = 1;
date = new Object[6][7];
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 7; j++) {
if (count > dateNumber)
break;
else {
if ((i * 7 + j) < firstDay)
continue;
else {
date[i][j] = count;
count++;
}
}
}
}
table = new JTable(date, name);
table.setRowHeight(15);
con.add(new JScrollPane(table), BorderLayout.CENTER);
con.validate();
validate();
year.addItemListener(this);
month.addItemListener(this);
}
public void itemStateChanged(ItemEvent e) {
years = Integer.parseInt(year.getSelectedItem().toString());
months = Integer.parseInt(month.getSelectedItem().toString()) - 1;
cd = new GregorianCalendar(years, months, 1);
int dateNumber = cd.getActualMaximum(Calendar.DATE);
int firstDay = cd.get(Calendar.DAY_OF_WEEK) - 1;
int count = 1;
date = new Object[6][7];
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 7; j++) {
if (count > dateNumber)
break;
else {
if ((i * 7 + j) < firstDay)
continue;
else {
date[i][j] = count;
count++;
}
}
}
}
table = new JTable(date, name);
table.setRowHeight(15);
getContentPane().removeAll();
getContentPane().setLayout(new BorderLayout());
getContentPane().add(panel, BorderLayout.NORTH);
getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
validate();
}
}
public class TestCalendar {
public static void main(String[] args) {
new DateWin("Java日历");
}
}
楼主也不要改了,,,有这么好用的。日历不用。。图什么呢。。
就上面那个了。。。我做项目的时候用的就是这个。。。
不错,,,共享给你了。。
好运!
import java.awt.*;
import java.awt.event.*;
import java.util.*;
class DateWin extends JFrame implements ItemListener {
private static final long serialVersionUID = 1L;
Calendar cd = null;
int years;
int months;
int dates;
JTable table;
Object date[][];
Object name[] = { "日", "一", "二", "三", "四", "五", "六" };
JComboBox year, month;
JLabel label1, label2;
JPanel panel;
DateWin(String s) {
super(s);
setSize(400, 300);
setLocation(120, 120);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
year = new JComboBox();
for (int i = 0; i < 30; i++) {
int years = 1990 + i;
year.addItem(years);
}
month = new JComboBox();
for (int i = 1; i < 13; i++) {
month.addItem(i);
}
label1 = new JLabel("请选择年份:");
label2 = new JLabel("请选择月份:");
panel = new JPanel();
panel.add(label1);
panel.add(year);
panel.add(label2);
panel.add(month);
Container con = getContentPane();
con.setLayout(new BorderLayout());
con.add(panel, BorderLayout.NORTH);
cd = new GregorianCalendar();
years = cd.get(Calendar.YEAR);
year.setSelectedItem(years);
months = cd.get(Calendar.MONTH) + 1;
month.setSelectedItem(months);
cd.set(Calendar.DATE, 1);
int dateNumber = cd.getActualMaximum(Calendar.DATE);
int firstDay = cd.get(Calendar.DAY_OF_WEEK) - 1;
int count = 1;
date = new Object[6][7];
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 7; j++) {
if (count > dateNumber)
break;
else {
if ((i * 7 + j) < firstDay)
continue;
else {
date[i][j] = count;
count++;
}
}
}
}
table = new JTable(date, name);
table.setRowHeight(15);
con.add(new JScrollPane(table), BorderLayout.CENTER);
con.validate();
validate();
year.addItemListener(this);
month.addItemListener(this);
}
public void itemStateChanged(ItemEvent e) {
years = Integer.parseInt(year.getSelectedItem().toString());
months = Integer.parseInt(month.getSelectedItem().toString()) - 1;
cd = new GregorianCalendar(years, months, 1);
int dateNumber = cd.getActualMaximum(Calendar.DATE);
int firstDay = cd.get(Calendar.DAY_OF_WEEK) - 1;
int count = 1;
date = new Object[6][7];
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 7; j++) {
if (count > dateNumber)
break;
else {
if ((i * 7 + j) < firstDay)
continue;
else {
date[i][j] = count;
count++;
}
}
}
}
table = new JTable(date, name);
table.setRowHeight(15);
getContentPane().removeAll();
getContentPane().setLayout(new BorderLayout());
getContentPane().add(panel, BorderLayout.NORTH);
getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
validate();
}
}
public class TestCalendar {
public static void main(String[] args) {
new DateWin("Java日历");
}
}
楼主也不要改了,,,有这么好用的。日历不用。。图什么呢。。
就上面那个了。。。我做项目的时候用的就是这个。。。
不错,,,共享给你了。。
好运!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询