java中编写日历的代码 java编程日历( 五 )


}
public void doMark(){
for(int i=0;ishowDay.length;i++){
showDay[i].removeAll();
String str=showDay[i].getText().trim();
try{
int n=Integer.parseInt(str);
if(isHaveDailyRecord(n)==true){ //见后面的isHaveDailyRecord()方法
JLabel mess=new JLabel("存");
mess.setFont(new Font("TimesRoman",Font.PLAIN,11));
mess.setForeground(Color.black) ;
showDay[i].add(mess);
}}
catch(Exception exp){}
}
calendarPad.repaint();
calendarPad.validate();
}
public boolean isHaveDailyRecord(int n){
String key=""+year+""+month+""+n;
String [] dayFile=dir.list();
boolean boo=false;
for(int k=0;kdayFile.length;k++){
if(dayFile[k].equals(key+".txt")){
boo=true;
break;
}}
return boo;
}
public static void main(String args[]){
new CalendarWindow();
}
}
//CalendarPad类:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class CalendarPad extends JPanel{
int year,month,day;
CalendarMessage calendarMessage;
JTextField [] showDay;
JLabel title[];
String [] 星期={"SUN/日","MON/一","TUE/二","WED/三","THU/四","FRI/五","SAT/六"};
JPanel north,center;
public CalendarPad(){
setLayout(new BorderLayout());
north=new JPanel();
north.setLayout(new GridLayout(1,7));
center=new JPanel();
center.setLayout(new GridLayout(6,7));
add(center,BorderLayout.CENTER);
add(north,BorderLayout.NORTH);
title=new JLabel[7];
for(int j=0;j7;j++){
title[j]=new JLabel();
title[j].setFont(new Font("TimesRoman",Font.BOLD,12));
title[j].setText(星期[j]);
title[j].setHorizontalAlignment(JLabel.CENTER);
title[j].setBorder(BorderFactory.createRaisedBevelBorder());
north.add(title[j]);
}
title[0].setForeground(Color.red);
title[6].setForeground(Color.blue);
}
public void setShowDayTextField(JTextField [] text){
showDay=text;
for(int i=0;ishowDay.length;i++){
showDay[i].setFont(new Font("TimesRoman",Font.BOLD,15));
showDay[i].setHorizontalAlignment(JTextField.CENTER);
showDay[i].setEditable(false);
center.add(showDay[i]);
}
}
public void setCalendarMessage(CalendarMessage calendarMessage){
this.calendarMessage=calendarMessage;
}
public void showMonthCalendar(){
String [] a=calendarMessage.getMonthCalendar();
for(int i=0;i42;i++)
showDay[i].setText(a[i]);
validate();
}
}
怎么用java写日历以下是两个类java中编写日历的代码 , 请楼主分别存成两个java文件:
其中
MainFrame.java是显示日历程序java中编写日历的代码,Clock.java是日历计算程序 。编译后运行MainFrame这个类即可 。
1.MainFrame.java
---
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Date;
import java.util.Calendar;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class MainFrame extends JFrame {
/** *//**
*
*/
private static final long serialVersionUID = 1L;
JPanel panel = new JPanel(new BorderLayout());
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel(new GridLayout(7, 7));
JPanel panel3 = new JPanel();
JLabel[] label = new JLabel[49];
JLabel y_label = new JLabel("年份");
JLabel m_label = new JLabel("月份");
JComboBox com1 = new JComboBox();
JComboBox com2 = new JComboBox();
int re_year, re_month;

推荐阅读