请问大神,开始日期结束日期能不能编写成可以选择的,就像平常需要填写日期的时候就会出来日历的效果!
jl0=newJLabel("开始日期:");jl0.setFont(newFont("微软雅黑",Font.BOLD,20));jl0.setForeground(Co...
jl0=new JLabel("开始日期:");
jl0.setFont(new Font("微软雅黑",Font.BOLD,20));
jl0.setForeground(Color.BLACK);
jl0.setBounds(350, 20, 200, 20);
jl1=new JLabel("结束日期:");
jl1.setFont(new Font("微软雅黑",Font.BOLD,20));
jl1.setForeground(Color.BLACK);
jl1.setBounds(550, 20, 200, 20);
我想在点击开始日期和结束日期的时候能显示日历,能够选择,然后能在超出结束日期的时间能自动显示状态为红色
用java编写一个小的程序就可以,不需要用到数据库,
主要要求就是有工作内容,工作的开始日期,结束日期,(能够弹出日历进行选择)是否完成,还有就是完成的状态,点击是显示绿色,点击否显示红色!希望能写的美观一点,能在表格中就好了!大概的样子就和下面的图片差不多,明天要交的面试题目,请各位大神帮帮忙,谢谢了! 展开
jl0.setFont(new Font("微软雅黑",Font.BOLD,20));
jl0.setForeground(Color.BLACK);
jl0.setBounds(350, 20, 200, 20);
jl1=new JLabel("结束日期:");
jl1.setFont(new Font("微软雅黑",Font.BOLD,20));
jl1.setForeground(Color.BLACK);
jl1.setBounds(550, 20, 200, 20);
我想在点击开始日期和结束日期的时候能显示日历,能够选择,然后能在超出结束日期的时间能自动显示状态为红色
用java编写一个小的程序就可以,不需要用到数据库,
主要要求就是有工作内容,工作的开始日期,结束日期,(能够弹出日历进行选择)是否完成,还有就是完成的状态,点击是显示绿色,点击否显示红色!希望能写的美观一点,能在表格中就好了!大概的样子就和下面的图片差不多,明天要交的面试题目,请各位大神帮帮忙,谢谢了! 展开
1个回答
展开全部
你要的Java程序我给你编好了,包括两个.java文件,你看看吧.
//WorkSchedule.java文件
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class WorkSchedule extends JFrame implements ActionListener{
JLabel jl,jl0,jl1,jl2,jl3,jl4;
JRadioButton jrb,jrb1;
ButtonGroup bg;
JTextArea jta;
JTextField jtf,jtf1;
JButton jb1,jb2;
CalendarJFrame cjf;
static int flag;
WorkSchedule(){
jl=new JLabel("工 作 内 容");
jl.setFont(new Font("微软雅黑",Font.BOLD,19));
jl.setForeground(Color.BLACK);
jl.setBounds(100, 20, 200, 20);
jl0=new JLabel("开始日期:");
jl0.setFont(new Font("微软雅黑",Font.BOLD,20));
jl0.setForeground(Color.BLACK);
jl0.setBounds(350, 20, 200, 20);
jl1=new JLabel("结束日期:");
jl1.setFont(new Font("微软雅黑",Font.BOLD,20));
jl1.setForeground(Color.BLACK);
jl1.setBounds(550, 20, 200, 20);
jl2 = new JLabel("是否完成:");
jl2.setFont(new Font("微软雅黑",Font.BOLD,19));
jl2.setForeground(Color.BLACK);
jl2.setBounds(760, 20, 200, 20);
jrb = new JRadioButton(" 是");
jrb.addActionListener(this);
jrb.setBounds(750, 50, 50, 20);
jrb1 = new JRadioButton("否");
jrb1.addActionListener(this);
jrb1.setBounds(800, 50, 50, 20);
bg=new ButtonGroup();
bg.add(jrb);
bg.add(jrb1);
jl3 = new JLabel("完成状态");
jl3.setFont(new Font("微软雅黑",Font.BOLD,20));//这行代码是用来设置按键上的字体大小的!
jl3.setForeground(Color.BLACK);
jl3.setBounds(1000, 5, 120, 50);
jl4=new JLabel();
jl4.setOpaque(true);
jl4.setBounds(970, 50, 160, 20);
jta=new JTextArea(3,5);
jta.setBounds(70, 50, 180, 50);
jtf=new JTextField();
jtf.setBounds(320, 50, 150, 20);
jb1=new JButton("...");
jb1.setBounds(470, 50, 30, 20);
jb1.addActionListener(this);
jtf1=new JTextField();
jtf1.setBounds(530, 50, 150, 20);
jb2=new JButton("...");
jb2.setBounds(680, 50, 30, 20);
jb2.addActionListener(this);
add(jl);add(jl0);add(jl1);add(jl2);add(jl3);add(jl4);
add(jta);add(jtf);add(jb1);add(jtf1);add(jb2);add(jrb);add(jrb1);
setLayout(null);
setSize(1200, 500);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
WorkSchedule ws=new WorkSchedule();
}
public void actionPerformed(ActionEvent ae) {
if(ae.getSource()==jrb){
jl4.setBackground(Color.GREEN);
}
if(ae.getSource()==jrb1){
jl4.setBackground(Color.RED);
}
if(ae.getSource()==jb1){
cjf=new CalendarJFrame(this);
cjf.setVisible(true);
flag=1;
}
if(ae.getSource()==jb2){
cjf=new CalendarJFrame(this);
cjf.setVisible(true);
flag=2;
}
}
}
//CalendarJFrame.java文件
import java.awt.BorderLayout;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Font;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class CalendarJFrame extends JDialog implements ActionListener{
JTextField tfYear = new JTextField("2004", 5); //显示年份的文本域
Choice monthChoice = new Choice(); //月份选择下拉框
JButton btUpdate = new JButton("更新"); //更新按钮
CalendarJPanel cp;
JPanel p=new JPanel();
static WorkSchedule ws;
CalendarJFrame(){
}
CalendarJFrame(WorkSchedule ws){
this.ws=ws;
cp=new CalendarJPanel(this,ws);
cp.updateCalendarJPanel();
p.setBackground(Color.white); //设置背景颜色
cp.setBackground(Color.white);
p.add(new Label(" 年:")); //增加组件到Applet
tfYear.setText(String.valueOf(cp.searchYear)); //设置文本域文字
p.add(tfYear);
p.add(new Label(" 月:"));
monthChoice.setFont(cp.smallFont); //设置月份选择下拉框的显示字体
for (int i = 0; i < 12; i++) {
monthChoice.addItem(cp.months[i]); //增加下拉框选项
}
monthChoice.select(cp.searchMonth); //设置下拉框当前选择项
btUpdate.addActionListener(this);
p.add(monthChoice);
p.add(btUpdate);
int componentCount=this.getComponentCount(); //得到Applet中的组件数量
for (int i=0;i<componentCount;i++){
getComponent(i).setFont(cp.smallFont); //设置所有组件的显示字体
}
add(p,BorderLayout.NORTH);
add(cp,BorderLayout.CENTER);
setSize(500,500);
}
public void actionPerformed(ActionEvent ae) {
int searchYearInt;
if (ae.getSource()==btUpdate){
cp.removeAll();
cp.repaint(); //重绘屏幕
cp.searchMonth = monthChoice.getSelectedIndex(); //得到查询月份
searchYearInt = Integer.parseInt(tfYear.getText(), 10); //得到查询年份
if (searchYearInt > 1581) {
cp.searchYear = searchYearInt;
}
cp.updateCalendarJPanel();
cp.validate();
cp.repaint();
}
}
}
class CalendarJPanel extends JPanel implements ActionListener{
final int TOP = 70; //顶端距离
final int CELLWIDTH=50,CELLHEIGHT = 30; //单元格尺寸
final int MARGIN = 3; //边界距离
final int FEBRUARY = 1;
Font smallFont = new Font("TimesRoman", Font.PLAIN, 15); //显示小字体
Font bigFont = new Font("TimesRoman", Font.BOLD, 50); //显示大字体
String weeks[] = {"星期日", "星期一", "星期二", "星期三","星期四", "星期五", "星期六"};
String months[] = {"一月", "二月", "三月", "四月","五月", "六月", "七月", "八月", "九月","十月", "十一月", "十二月"};
int daysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //每个月的天数
int searchMonth,searchYear; //查询的年份及月份
int numDays,currentDay;
GregorianCalendar calendar=new GregorianCalendar(); //日历对象
int dayPos;
JButton[] jb;
WorkSchedule ws;
CalendarJFrame cjf;
CalendarJPanel(){
}
CalendarJPanel(CalendarJFrame cjf,WorkSchedule ws){
this.cjf=cjf;
this.ws=ws;
}
void updateCalendarJPanel(){
if(searchYear==0){
searchMonth = calendar.get(Calendar.MONTH); //得到系统年份
searchYear = calendar.get(Calendar.YEAR); //得到系统月份
currentDay=calendar.get(Calendar.DATE)-1; //得到系统日期
}
numDays = daysInMonth[searchMonth] + ((calendar.isLeapYear(searchYear) && (searchMonth == FEBRUARY)) ? 1 : 0);
setLayout(null);
int j=0;
int iwidth=0;
jb=new JButton[numDays];
JLabel[] jl=new JLabel[7];
dayPos = TOP + 30 / 2;
for(int i=0;i<7;i++){
jl[i]=new JLabel(weeks[i]);
jl[i].setBounds(CELLWIDTH+25 + i*CELLWIDTH,dayPos-50,CELLWIDTH,CELLHEIGHT);
add(jl[i]);
}
for(int i=0;i<numDays;i++){
jb[i]=new JButton(String.valueOf(i+1));
if(i==currentDay){
jb[i].setForeground(Color.RED);
}
if(j==0){
iwidth=i+getFirstDayOfMonth(searchYear, searchMonth);
}else{
iwidth=(i+getFirstDayOfMonth(searchYear, searchMonth))%7;
}
if(iwidth%7==0){
iwidth=0;
j++;
}
if(getFirstDayOfMonth(searchYear, searchMonth)==0)
jb[i].setBounds(TOP+iwidth*CELLWIDTH, TOP+(j-1)*CELLHEIGHT, CELLWIDTH, CELLHEIGHT);
else
jb[i].setBounds(TOP+iwidth*CELLWIDTH, TOP+j*CELLHEIGHT, CELLWIDTH, CELLHEIGHT);
jb[i].addActionListener(this);
jb[i].setContentAreaFilled(false);
add(jb[i]);
}
}
private int getNumberRows(int year, int month) { //得到行数量
int firstDay;
int numCells;
if (year < 1582) { //年份小于1582年,则返回-1
return (-1);
}
if ((month < 0) || (month > 11)) {
return (-1);
}
firstDay = getFirstDayOfMonth(year, month); //计算月份的第一天
if ((month == FEBRUARY) && (firstDay == 0) && !calendar.isLeapYear(year)) {
return 4;
}
numCells = firstDay + daysInMonth[month];
if ((month == FEBRUARY) && (calendar.isLeapYear(year))) {
numCells++;
}
return ((numCells <= 35) ? 5 : 6); //返回行数
}
private int getFirstDayOfMonth(int year, int month) { //得到每月的第一天
int firstDay;
int i;
if (year < 1582) { //年份小于1582年,返回-1
return (-1);
}
if ((month < 0) || (month > 11)) { //月份数错误,返回-1
return (-1);
}
firstDay = getFirstDayOfYear(year); //得到每年的第一天
for (i = 0; i < month; i++) {
firstDay += daysInMonth[i]; //计算每月的第一天
}
if ((month > FEBRUARY) && calendar.isLeapYear(year)) {
firstDay++;
}
return (firstDay % 7);
}
private int getFirstDayOfYear(int year){ //计算每年的第一天
int leapYears;
int hundreds;
int fourHundreds;
int first;
if (year < 1582) { //如果年份小于1582年
return (-1); //返回-1
}
leapYears = (year - 1581) / 4;
hundreds = (year - 1501) / 100;
leapYears -= hundreds;
fourHundreds = (year - 1201) / 400;
leapYears += fourHundreds;
first=5 + (year - 1582) + leapYears % 7; //得到每年第一天
return first;
}
public void actionPerformed(ActionEvent ae) {
for(int i=0;i<numDays;i++){
if(ae.getSource()==jb[i]){
System.out.println(ws.flag);
if(ws.flag==1){
ws.jtf.setText(searchYear+"-"+(searchMonth+1)+"-"+jb[i].getText());
}
if(ws.flag==2){
ws.jtf1.setText(searchYear+"-"+(searchMonth+1)+"-"+jb[i].getText());
Date nowdate=new Date();
String myString = searchYear+"-"+(searchMonth+1)+"-"+jb[i].getText();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
Date d = null;
Date startdate=null;
try {
d = sdf.parse(myString);
startdate=sdf.parse(ws.jtf.getText());
} catch (ParseException e) {
e.printStackTrace();
}
boolean flag =d.after(startdate);
if(!flag){
System.out.println("结束时间小于开始时间");
ws.jtf.requestFocus();
}
flag = d.before(nowdate);
if(flag)
ws.jtf1.setForeground(Color.RED);
}
System.out.println(searchYear+" "+(searchMonth+1)+" "+jb[i].getText());
cjf.dispose();
}
}
}
}
//WorkSchedule.java文件
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class WorkSchedule extends JFrame implements ActionListener{
JLabel jl,jl0,jl1,jl2,jl3,jl4;
JRadioButton jrb,jrb1;
ButtonGroup bg;
JTextArea jta;
JTextField jtf,jtf1;
JButton jb1,jb2;
CalendarJFrame cjf;
static int flag;
WorkSchedule(){
jl=new JLabel("工 作 内 容");
jl.setFont(new Font("微软雅黑",Font.BOLD,19));
jl.setForeground(Color.BLACK);
jl.setBounds(100, 20, 200, 20);
jl0=new JLabel("开始日期:");
jl0.setFont(new Font("微软雅黑",Font.BOLD,20));
jl0.setForeground(Color.BLACK);
jl0.setBounds(350, 20, 200, 20);
jl1=new JLabel("结束日期:");
jl1.setFont(new Font("微软雅黑",Font.BOLD,20));
jl1.setForeground(Color.BLACK);
jl1.setBounds(550, 20, 200, 20);
jl2 = new JLabel("是否完成:");
jl2.setFont(new Font("微软雅黑",Font.BOLD,19));
jl2.setForeground(Color.BLACK);
jl2.setBounds(760, 20, 200, 20);
jrb = new JRadioButton(" 是");
jrb.addActionListener(this);
jrb.setBounds(750, 50, 50, 20);
jrb1 = new JRadioButton("否");
jrb1.addActionListener(this);
jrb1.setBounds(800, 50, 50, 20);
bg=new ButtonGroup();
bg.add(jrb);
bg.add(jrb1);
jl3 = new JLabel("完成状态");
jl3.setFont(new Font("微软雅黑",Font.BOLD,20));//这行代码是用来设置按键上的字体大小的!
jl3.setForeground(Color.BLACK);
jl3.setBounds(1000, 5, 120, 50);
jl4=new JLabel();
jl4.setOpaque(true);
jl4.setBounds(970, 50, 160, 20);
jta=new JTextArea(3,5);
jta.setBounds(70, 50, 180, 50);
jtf=new JTextField();
jtf.setBounds(320, 50, 150, 20);
jb1=new JButton("...");
jb1.setBounds(470, 50, 30, 20);
jb1.addActionListener(this);
jtf1=new JTextField();
jtf1.setBounds(530, 50, 150, 20);
jb2=new JButton("...");
jb2.setBounds(680, 50, 30, 20);
jb2.addActionListener(this);
add(jl);add(jl0);add(jl1);add(jl2);add(jl3);add(jl4);
add(jta);add(jtf);add(jb1);add(jtf1);add(jb2);add(jrb);add(jrb1);
setLayout(null);
setSize(1200, 500);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
WorkSchedule ws=new WorkSchedule();
}
public void actionPerformed(ActionEvent ae) {
if(ae.getSource()==jrb){
jl4.setBackground(Color.GREEN);
}
if(ae.getSource()==jrb1){
jl4.setBackground(Color.RED);
}
if(ae.getSource()==jb1){
cjf=new CalendarJFrame(this);
cjf.setVisible(true);
flag=1;
}
if(ae.getSource()==jb2){
cjf=new CalendarJFrame(this);
cjf.setVisible(true);
flag=2;
}
}
}
//CalendarJFrame.java文件
import java.awt.BorderLayout;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Font;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class CalendarJFrame extends JDialog implements ActionListener{
JTextField tfYear = new JTextField("2004", 5); //显示年份的文本域
Choice monthChoice = new Choice(); //月份选择下拉框
JButton btUpdate = new JButton("更新"); //更新按钮
CalendarJPanel cp;
JPanel p=new JPanel();
static WorkSchedule ws;
CalendarJFrame(){
}
CalendarJFrame(WorkSchedule ws){
this.ws=ws;
cp=new CalendarJPanel(this,ws);
cp.updateCalendarJPanel();
p.setBackground(Color.white); //设置背景颜色
cp.setBackground(Color.white);
p.add(new Label(" 年:")); //增加组件到Applet
tfYear.setText(String.valueOf(cp.searchYear)); //设置文本域文字
p.add(tfYear);
p.add(new Label(" 月:"));
monthChoice.setFont(cp.smallFont); //设置月份选择下拉框的显示字体
for (int i = 0; i < 12; i++) {
monthChoice.addItem(cp.months[i]); //增加下拉框选项
}
monthChoice.select(cp.searchMonth); //设置下拉框当前选择项
btUpdate.addActionListener(this);
p.add(monthChoice);
p.add(btUpdate);
int componentCount=this.getComponentCount(); //得到Applet中的组件数量
for (int i=0;i<componentCount;i++){
getComponent(i).setFont(cp.smallFont); //设置所有组件的显示字体
}
add(p,BorderLayout.NORTH);
add(cp,BorderLayout.CENTER);
setSize(500,500);
}
public void actionPerformed(ActionEvent ae) {
int searchYearInt;
if (ae.getSource()==btUpdate){
cp.removeAll();
cp.repaint(); //重绘屏幕
cp.searchMonth = monthChoice.getSelectedIndex(); //得到查询月份
searchYearInt = Integer.parseInt(tfYear.getText(), 10); //得到查询年份
if (searchYearInt > 1581) {
cp.searchYear = searchYearInt;
}
cp.updateCalendarJPanel();
cp.validate();
cp.repaint();
}
}
}
class CalendarJPanel extends JPanel implements ActionListener{
final int TOP = 70; //顶端距离
final int CELLWIDTH=50,CELLHEIGHT = 30; //单元格尺寸
final int MARGIN = 3; //边界距离
final int FEBRUARY = 1;
Font smallFont = new Font("TimesRoman", Font.PLAIN, 15); //显示小字体
Font bigFont = new Font("TimesRoman", Font.BOLD, 50); //显示大字体
String weeks[] = {"星期日", "星期一", "星期二", "星期三","星期四", "星期五", "星期六"};
String months[] = {"一月", "二月", "三月", "四月","五月", "六月", "七月", "八月", "九月","十月", "十一月", "十二月"};
int daysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //每个月的天数
int searchMonth,searchYear; //查询的年份及月份
int numDays,currentDay;
GregorianCalendar calendar=new GregorianCalendar(); //日历对象
int dayPos;
JButton[] jb;
WorkSchedule ws;
CalendarJFrame cjf;
CalendarJPanel(){
}
CalendarJPanel(CalendarJFrame cjf,WorkSchedule ws){
this.cjf=cjf;
this.ws=ws;
}
void updateCalendarJPanel(){
if(searchYear==0){
searchMonth = calendar.get(Calendar.MONTH); //得到系统年份
searchYear = calendar.get(Calendar.YEAR); //得到系统月份
currentDay=calendar.get(Calendar.DATE)-1; //得到系统日期
}
numDays = daysInMonth[searchMonth] + ((calendar.isLeapYear(searchYear) && (searchMonth == FEBRUARY)) ? 1 : 0);
setLayout(null);
int j=0;
int iwidth=0;
jb=new JButton[numDays];
JLabel[] jl=new JLabel[7];
dayPos = TOP + 30 / 2;
for(int i=0;i<7;i++){
jl[i]=new JLabel(weeks[i]);
jl[i].setBounds(CELLWIDTH+25 + i*CELLWIDTH,dayPos-50,CELLWIDTH,CELLHEIGHT);
add(jl[i]);
}
for(int i=0;i<numDays;i++){
jb[i]=new JButton(String.valueOf(i+1));
if(i==currentDay){
jb[i].setForeground(Color.RED);
}
if(j==0){
iwidth=i+getFirstDayOfMonth(searchYear, searchMonth);
}else{
iwidth=(i+getFirstDayOfMonth(searchYear, searchMonth))%7;
}
if(iwidth%7==0){
iwidth=0;
j++;
}
if(getFirstDayOfMonth(searchYear, searchMonth)==0)
jb[i].setBounds(TOP+iwidth*CELLWIDTH, TOP+(j-1)*CELLHEIGHT, CELLWIDTH, CELLHEIGHT);
else
jb[i].setBounds(TOP+iwidth*CELLWIDTH, TOP+j*CELLHEIGHT, CELLWIDTH, CELLHEIGHT);
jb[i].addActionListener(this);
jb[i].setContentAreaFilled(false);
add(jb[i]);
}
}
private int getNumberRows(int year, int month) { //得到行数量
int firstDay;
int numCells;
if (year < 1582) { //年份小于1582年,则返回-1
return (-1);
}
if ((month < 0) || (month > 11)) {
return (-1);
}
firstDay = getFirstDayOfMonth(year, month); //计算月份的第一天
if ((month == FEBRUARY) && (firstDay == 0) && !calendar.isLeapYear(year)) {
return 4;
}
numCells = firstDay + daysInMonth[month];
if ((month == FEBRUARY) && (calendar.isLeapYear(year))) {
numCells++;
}
return ((numCells <= 35) ? 5 : 6); //返回行数
}
private int getFirstDayOfMonth(int year, int month) { //得到每月的第一天
int firstDay;
int i;
if (year < 1582) { //年份小于1582年,返回-1
return (-1);
}
if ((month < 0) || (month > 11)) { //月份数错误,返回-1
return (-1);
}
firstDay = getFirstDayOfYear(year); //得到每年的第一天
for (i = 0; i < month; i++) {
firstDay += daysInMonth[i]; //计算每月的第一天
}
if ((month > FEBRUARY) && calendar.isLeapYear(year)) {
firstDay++;
}
return (firstDay % 7);
}
private int getFirstDayOfYear(int year){ //计算每年的第一天
int leapYears;
int hundreds;
int fourHundreds;
int first;
if (year < 1582) { //如果年份小于1582年
return (-1); //返回-1
}
leapYears = (year - 1581) / 4;
hundreds = (year - 1501) / 100;
leapYears -= hundreds;
fourHundreds = (year - 1201) / 400;
leapYears += fourHundreds;
first=5 + (year - 1582) + leapYears % 7; //得到每年第一天
return first;
}
public void actionPerformed(ActionEvent ae) {
for(int i=0;i<numDays;i++){
if(ae.getSource()==jb[i]){
System.out.println(ws.flag);
if(ws.flag==1){
ws.jtf.setText(searchYear+"-"+(searchMonth+1)+"-"+jb[i].getText());
}
if(ws.flag==2){
ws.jtf1.setText(searchYear+"-"+(searchMonth+1)+"-"+jb[i].getText());
Date nowdate=new Date();
String myString = searchYear+"-"+(searchMonth+1)+"-"+jb[i].getText();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
Date d = null;
Date startdate=null;
try {
d = sdf.parse(myString);
startdate=sdf.parse(ws.jtf.getText());
} catch (ParseException e) {
e.printStackTrace();
}
boolean flag =d.after(startdate);
if(!flag){
System.out.println("结束时间小于开始时间");
ws.jtf.requestFocus();
}
flag = d.before(nowdate);
if(flag)
ws.jtf1.setForeground(Color.RED);
}
System.out.println(searchYear+" "+(searchMonth+1)+" "+jb[i].getText());
cjf.dispose();
}
}
}
}
更多追问追答
追问
大神能不能写在表格里面呀,想写的漂亮点的
追答
你想把工作内容,开始日期,结束日期,是否完成,完成状态都写在表格里吗?
如果是的话,可是比较复杂了.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询