扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
import java.text.SimpleDateFormat; import java.util.Calendar; public class TestDate { public static final String[] weeks = { "日", "一", "二", "三", "四", "五", "六" }; public static void main(String[] args) { Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR,2011);//2011年 c.set(Calendar.MONTH,0);//java中Calendar类,月从0开始, 0代表一月 c.set(Calendar.DATE,1);//1号 int day = c.get(Calendar.DAY_OF_WEEK);//获致是本周的第几天地, 1代表星期天...7代表星期六 System.out.println(new SimpleDateFormat( "yyyy-MM-dd ").format(c.getTime())); System.out.println("星期" + weeks[day-1]); } } 把以上测试代码写作一个方法 方法的参数名为年月日, 即可。当然Calendar 还有很多功能,比如一周的第几天,一年的第几个月……
目前创新互联已为千余家的企业提供了网站建设、域名、虚拟主机、网站托管、服务器托管、企业网站设计、前郭网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
import javax.swing.*;
import java.lang.*;
public class Wanyear
{
public static void main(String[] args)
{
String input=JOptionPane.showInputDialog
("Please Enter the year");
int year=Integer.parseInt(input);
String input1=JOptionPane.showInputDialog
("Please Enter the Month");
int m=Integer.parseInt(input1);
String input2=JOptionPane.showInputDialog
("Please Enter the Day");
int d=Integer.parseInt(input2);
String Nyear=Integer.toString(year);
String Sc=Nyear.substring(0,1);
String Sy=Nyear.substring(2,3);
int c=Integer.parseInt(Sc);
int y=Integer.parseInt(Sy);
if(m3){
year--;
m+=12;}
else
c--;
int w=(c/4)-(2*c)+y+(y/4)+(13*(m+1)/5)+d-1;
int result=0;
if(w=0)
result=w%7;
else
result=(w+700)%7;
switch(result)
{
case 0: System.out.println("SUN"); break;
case 1: System.out.println("MON"); break;
case 2: System.out.println("TUE"); break;
case 3: System.out.println("WED"); break;
case 4: System.out.println("THU"); break;
case 5: System.out.println("FRI"); break;
case 6: System.out.println("SAT"); break;
}
}
}
/*
题目:输出任意年份任意月份的日历表(公元后)
思路:
1.已知1年1月1日是星期日,1 % 7 = 1 对应的是星期日,2 % 7 = 2 对应的是星期一,以此类推;
2.计算当年以前所有天数+当年当月1号之前所有天数;
a.年份分平年闰年,平年365天,闰年366天;
b.闰年的判断方法year % 400 == 0 || (year % 100 != 0 year % 4 == 0)若为真,则为闰年否则为平年;
c.定义平年/闰年数组,包含各月天数;
d.遍历数组求和,计算当年当月前总天数;
e.当年以前所有天数+当年当月前总天数+1即为1年1月1日到当年当月1日的总天数;
3.总天数对7取模,根据结果判断当月1号是星期几,输出空白区域;
4.输出当月日历表,逢星期六换行
*/
import java.util.Scanner;
class FindMonthList {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入年份:");
int year = sc.nextInt(); //年份
if (year 1) { //判断非法输入年份
System.out.println("输入错误!");
return;
}
System.out.println("请输入月份:");
int month = sc.nextInt(); //月份
if (month 1 || month 12) { //判断非法输入月份
System.out.println("输入错误!");
return;
}
//输出表头
System.out.println("-------" + year + " 年 " + month + " 月 " + "-------");
System.out.println();
System.out.println("日 一 二 三 四 五 六");
//计算当前年份以前所有天数beforeYearTotalDay;每4年一个闰年,闰年366天,平年365天
int beforeYearTotalDay = ((year - 1) / 4 * 366) + (year-1 - ((year - 1) / 4)) * 365;
int[] arrLeapYear = {0,31,29,31,30,31,30,31,31,30,31,30,31}; //闰年各月天数 int数组
int[] arrNormalYear = {0,31,28,31,30,31,30,31,31,30,31,30,31}; //平年各月天数 int数组
int beforeMonthTotalDay = 0; //定义本年当月之前月份的总天数
if (year % 400 == 0 || (year % 100 != 0 year % 4 == 0)) { //判断当前年份是否是闰年
for (int i = 0 ; i month ; i ++ ) { //for循环计算当月之前总天数
//计算当前月份之前的所有天数
beforeMonthTotalDay = beforeMonthTotalDay + arrLeapYear[i];
}
//判断当月1日是星期几
int totalDay = beforeYearTotalDay + beforeMonthTotalDay + 1;
int week = totalDay % 7;//已知1年1月1日是星期日,即模7得1对应的是星期日
for (int i = 0 ; i (week - 1 + 7) % 7 ; i ++) { //如果写成i (week-1)会出现i-1的情况
System.out.print(" ");//输出开头空白
}
for (int i = 1 ;i = arrLeapYear[month] ;i ++ ) { //for循环输出各月天数
System.out.print(i + " ");
if (i 10 ) { //小于10的数补一个空格,以便打印整齐
System.out.print(" ");
}
if (i % 7 == ((7-(week - 1)) % 7 ) || i == arrLeapYear[month]) {//每逢星期六/尾数换行
System.out.println();
}
}
} else { //不是闰年就是平年
for (int i = 0 ; i month ; i ++ ) { //for循环计算出当月之前月份总天数
beforeMonthTotalDay = beforeMonthTotalDay + arrNormalYear[i];
}
//判断当月1日是星期几
int totalDay = beforeYearTotalDay + beforeMonthTotalDay + 1;
int week = totalDay % 7;//已知1年1月1日是星期日,即模7得1对应的是星期日
for (int i = 0 ; i (week - 1 + 7) % 7 ; i ++) { //如果写成i (week-1)会出现i-1的情况
System.out.print(" ");//输出开头空白
}
for (int i = 1 ;i = arrNormalYear[month] ;i ++ ) {//for循环输出各月天数
System.out.print(i + " ");
if (i 10 ) { //小于10的数补一个空格,以便打印整齐
System.out.print(" ");
}
if (i % 7 == ((7-(week - 1)) % 7 ) || i == arrNormalYear[month]) {//每逢星期六/尾数换行
System.out.println();
}
}
}
}
}
显示效果:
这是我刚做出来的,时间紧迫,做得有些粗糙,但是你要的功能基本实现了!import java.awt.*;
import java.text.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
//import java.util.Timer;
public class DataSimple implements ItemListener
{
JFrame mainFrame;
JLabel yearLabel,monthLabel,showTextLabel,timeLabel;
JTextArea showArea;
JComboBox yearBox,monthBox;
JPanel panel_top,panel_down;
Container con;
//JTable myTable;
//JScrollPane JSpane;
String year[]=new String[9000];
String month[]=new String[12];
Date today;
GregorianCalendar cal;
//Timer myTimer;
//TimerTask myTask;
int totalDays,startDay,i;
String selectYear,selectMonth;
Object [][] day=new Object[4][6];
static final String head[]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
SimpleDateFormat timeFormat=new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
public DataSimple()
{
mainFrame=new JFrame("模拟万年日历");
con=mainFrame.getContentPane();
yearLabel=new JLabel("选择年份:");
monthLabel=new JLabel("选择月份:");
for(int i=1900;i10000;i++)
{
try
{
//year[i-1900]=(new Integer(i)).toString();
year[i-1900]=String.valueOf(i);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(mainFrame,"出现异常");
}
}
yearBox=new JComboBox(year);
yearBox.setSelectedItem("2010");
yearBox.addItemListener(this);
for(int i=0;i12;i++)
{
month[i]=(new Integer(i)).toString();
}
monthBox=new JComboBox(month);
monthBox.setSelectedItem("1");
monthBox.addItemListener(this);
panel_top=new JPanel();
panel_top.setLayout(new FlowLayout());
panel_top.add(yearLabel);
panel_top.add(yearBox);
panel_top.add(monthLabel);
panel_top.add(monthBox);
con.add(panel_top,BorderLayout.NORTH);
showArea=new JTextArea();
showArea.setEditable(false);
showDate(2010,1);
//myTable=new JTable(day,head);
con.add(showArea,BorderLayout.CENTER);
showTextLabel=new JLabel("现在时间是:");
today=new Date();
timeLabel=new JLabel(timeFormat.format(today));
panel_down=new JPanel();
panel_down.setLayout(new FlowLayout());
panel_down.add(showTextLabel);
panel_down.add(timeLabel);
con.add(panel_down,BorderLayout.SOUTH);
//con.add(showArea,BorderLayout.CENTER);
mainFrame.setSize(400,300);
mainFrame.setVisible(true);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void showDate(int year,int month)
{
showArea.setText("");
cal=new GregorianCalendar(year,month-1,1);
totalDays=cal.getActualMaximum(Calendar.DAY_OF_MONTH);
startDay=cal.get(Calendar.DAY_OF_WEEK)-1;
for(i=0;ihead.length;i++)
showArea.append(head[i]+" ");
showArea.append("\n");
//输出第一天之前的空格,每个输出项8个空格
for(i=0;istartDay;i++)
{
//day[0][i]=new Integer(0);
showArea.append(" ");
}
//依次输出每一天,每一个输出项占8个字符宽度
for(int days=1;days=totalDays;days++)
{ /*for(int j=0;j5;j++)
{
for(int z=0;z7;z++)
{
if(!day[j][z].equals(0))
{
day[j][z]=new Integer(days);
}*/
if(days10)
{
showArea.append(" "+days+" ");
}
else if(days=10)
{
showArea.append(" "+days+" ");
}
i++;
if(i==7)
{
showArea.append("\n");
i=0;
}
/*}
}*/
}
}
public void itemStateChanged(ItemEvent e)
{
if(e.getStateChange()==ItemEvent.SELECTED)
{
selectYear=(String)(yearBox.getSelectedItem());
selectMonth=(String)(monthBox.getSelectedItem());
showDate(Integer.parseInt(selectYear),Integer.parseInt(selectMonth));
}
}
public static void main(String argv[])
{
new DataSimple();
}
}运行截图:
先上张效果图:以下是实现代码:/*日历*/
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.regex.Pattern;
import javax.swing.*;
public class Demo28 extends JFrame {
int m = 1;
String[] monthchoose = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
"11", "12" }; // 存放月份的字符数组
String[] columnNames = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" }; // 存放星期的字符数组
Calendar ca = Calendar.getInstance();
Container contentPane = getContentPane();
VectorString vector = new VectorString();
String[][] date = new String[6][7]; // 表格的显示数据的格式
TextField tf; // 文本框的值代表的是年份
JComboBox jb;
JTable table; // 把日期用table的方式显示出来
public void getDate(String year, String month, String week, int Max_Day) {
int n = 0, b = 0;
// 动态把传进来月份的天数存放到容器里
for (int j = 1; j = Max_Day; j++) {
vector.add(String.valueOf(j));
}
//每次往table里添加数据的时候,都预先把原table里 的 数据清空
for(int x = 0;xdate.length;x++){
for(int y = 0;ydate[x].length;y++){
date[x][y] = null;
}
}
// 根据传进来月份的第一天是星期几,来构建Table
for (int a = Integer.parseInt(week) - 1; a date[0].length; a++) {
date[0][a] = new String((String) vector.toArray()[n]);
n++;
}
for (int i = 1; i date.length; i++) {
for (int j = 0; j date[i].length; j++) {
if (n vector.size()) {
date[i][j] = new String((String) vector.toArray()[n]);
n++;
} else
break;
}
}
// 把容器里的数据全部清除,以备下次再存放新的数据
while (b vector.size()) {
vector.remove(b);
}
}
public void chooseDate(String day) {
JLabel label = new JLabel();
for (int y = 0; y date.length; y++) {
for (int z = 0; z date[y].length; z++) {
System.out.print(date[y][z] + " ");
System.out.println(day);
if (date[y][z] != null) {
if (date[y][z].equals(day)) {
table.setSelectionBackground(Color.yellow);
return;
}
}
}
}
}
public void paint() {
setTitle("日历");
setBounds(200, 200, 350, 178);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
int m = 0;
String year = String.valueOf(ca.get(Calendar.YEAR)); // 得到当前的系统时间的年份,并把这个数值存放到year这个变量里
String month = String.valueOf(ca.get(Calendar.MONTH) + 1); // 得到当前的系统时间的月份,并把这个数值存放到month这个变量里
String day = String.valueOf(ca.get(Calendar.DATE)); // 得到当前的系统时间的日期,并把这个数值存放到day这个变量里
ca.set(Calendar.DATE, 1); // 把Calendar 对象的DATA设置为1
String week = String.valueOf(ca.get(Calendar.DAY_OF_WEEK)); // 根据设置的Calendar对象,计算出这个月第一天是星期几
int Max_Day = ca.getActualMaximum(Calendar.DATE); // 得到当前系统时间月份有多少天
getDate(year, month, week, Max_Day);
// 从月份数组里取出与当前系统时间一样的月份值
for (int i = 0; i monthchoose.length; i++) {
if (monthchoose[i].equals(month)) {
m = i;
}
}
JToolBar toolBar = new JToolBar();
JButton b1 = new JButton("<");
b1.addMouseListener(new myMouseListener1());
JButton b2 = new JButton(">");
b2.addMouseListener(new myMouseListener2());
JLabel j1 = new JLabel("年");
JLabel j2 = new JLabel("月");
tf = new TextField(5);
tf.addKeyListener(new myKeyListener());
tf.setText(year);
jb = new JComboBox(monthchoose);
jb.setSelectedIndex(m);
jb.addActionListener(new myActionListener3());
table = new JTable(date, columnNames);
//table.addMouseListener(new tableMouseListener());
table.setPreferredScrollableViewportSize(new Dimension(350, 150));
JScrollPane jsp = new JScrollPane(table);
contentPane.add(jsp, BorderLayout.CENTER);
chooseDate(day);
toolBar.add(b1);
toolBar.add(tf);
toolBar.add(b2);
toolBar.add(j1);
toolBar.add(jb);
toolBar.add(j2);
toolBar.setLocation(0, 0);
toolBar.setSize(400, 15);
contentPane.add(toolBar, BorderLayout.NORTH);
setVisible(true);
new Thread(new PaintThread()).start(); // 调用内部类PaintThread,根据里面的设置来重画
}
public static void main(String[] args) {
Demo28 d28 = new Demo28();
d28.paint();
}
// 鼠标单击左边按钮触发的事件
class myMouseListener1 extends MouseAdapter {
public void mouseClicked(MouseEvent e) {
String str = tf.getText().trim(); // 得到文本框的值
int i = Integer.parseInt(str);
i = i - 1;
tf.setText(String.valueOf(i));
String new_year = String.valueOf(i); // 把表示年份的文本框的值存放到变量new_year里
ca.set(Calendar.YEAR, i); // 把Calendar 对象的YEAR设置为用户设置的年份
String new_month = (String) jb.getSelectedItem(); // 得到月份值
ca.set(Calendar.MONTH, Integer.parseInt(new_month) - 1); // 把Calendar对象的MONTH设置为用户设置的月份
ca.set(Calendar.DATE, 1); // 把Calendar 对象的DATA设置为1
String new_week = String.valueOf(ca.get(Calendar.DAY_OF_WEEK)); // 根据设置的Calendar对象,计算出这个月第一天是星期几
int Max_Day = ca.getActualMaximum(Calendar.DATE); // 根据设置后的Calendar对象计算这个月份有多少天
getDate(new_year, new_month, new_week, Max_Day);
}
}
class myKeyListener extends KeyAdapter {
public void keyReleased(KeyEvent e) {
try {
int i = Integer.parseInt(tf.getText().trim());
int key = e.getKeyCode();
if (key == KeyEvent.VK_ENTER) {
String new_year = String.valueOf(i);
ca.set(Calendar.YEAR, i); // 把Calendar对象的YEAR设置为用户设置的年份
String new_month = (String) jb.getSelectedItem(); // 得到月份值
ca.set(Calendar.MONTH, Integer.parseInt(new_month) - 1); // 把Calendar对象的MONTH设置为用户设置的月份
ca.set(Calendar.DATE, 1); // 把Calendar 对象的DATA设置为1
String new_week = String.valueOf(ca
.get(Calendar.DAY_OF_WEEK)); // 根据设置的Calendar对象,计算出这个月第一天是星期几
int Max_Day = ca.getActualMaximum(Calendar.DATE); // 根据设置后的Calendar对象计算这个月份有多少天
getDate(new_year, new_month, new_week, Max_Day);
}
} catch (NumberFormatException excption) {
System.out.println("你输入的年份不正确!");
}
}
}
// 鼠标单击右边按钮触发的事件
class myMouseListener2 extends MouseAdapter {
public void mouseClicked(MouseEvent e) {
String str = tf.getText().trim();
int i = Integer.parseInt(str);
i = i + 1;
tf.setText(String.valueOf(i));
String new_year = String.valueOf(i); // 把表示年份的文本框的值存放到变量new_year里
ca.set(Calendar.YEAR, i); // 把Calendar 对象的YEAR设置为用户设置的年份
String new_month = (String) jb.getSelectedItem(); // 得到月份值
ca.set(Calendar.MONTH, Integer.parseInt(new_month) - 1); // 把Calendar对象的MONTH设置为用户设置的月份
ca.set(Calendar.DATE, 1); // 把Calendar 对象的DATA设置为1
String new_week = String.valueOf(ca.get(Calendar.DAY_OF_WEEK)); // 根据设置的Calendar对象,计算出这个月第一天是星期几
int Max_Day = ca.getActualMaximum(Calendar.DATE); // 根据设置后的Calendar对象计算这个月份有多少天
getDate(new_year, new_month, new_week, Max_Day);
}
}
// 鼠标单击选择框触发的事件
class myActionListener3 implements ActionListener {
public void actionPerformed(ActionEvent e) {
String new_year = String.valueOf(ca.get(Calendar.YEAR)); // 把表示年份的文本框的值存放到变量new_year里
String new_month = (String) jb.getSelectedItem(); // 得到用户设置的月份
ca.set(Calendar.MONTH, Integer.parseInt(new_month) - 1); // 把Calendar对象的月份值设置为用户定义的月份
ca.set(Calendar.DATE, 1); // 把Calendar 对象的DATA设置为1
String new_week = String.valueOf(ca.get(Calendar.DAY_OF_WEEK)); // 根据设置的Calendar对象,计算出这个月第一天是星期几
int Max_Day = ca.getActualMaximum(Calendar.DATE); // 根据设置后的Calendar对象计算这个月份有多少天
getDate(new_year, new_month, new_week, Max_Day);
}
}
// 重画组件
private class PaintThread implements Runnable {
public void run() {
while (true) {
repaint();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
按照你的要求编写的Java swing 带界面的万年历代码如下
//日历
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class CCI extends JFrame implements ActionListener{
JButton jb1=new JButton("");
JButton jb2=new JButton("");
JButton jb3=new JButton("");
JButton jb4=new JButton("");
JPanel jp1=new JPanel();
JPanel jp2=new JPanel();
JPanel jp3=new JPanel();
JPanel jp4=new JPanel();
JLabel jl1=new JLabel();
JLabel jl2=new JLabel();
JLabel[]jl=new JLabel[49];
String []week={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
Calendar c=Calendar.getInstance();
int year,month,day;
int nowyear,nowmonth,nowday;
CCI(){
super("简单日历");
nowyear=c.get(Calendar.YEAR);
nowmonth=c.get(Calendar.MONTH)+1;
nowday=c.get(Calendar.DAY_OF_MONTH);
year=nowyear;
month=nowmonth;
day=nowday;
String s=year+"年"+month+"月";
jl1.setForeground(Color.RED);
jl1.setFont(new Font(null,Font.BOLD,20));
jl1.setText(s);
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3.addActionListener(this);
jb4.addActionListener(this);
jp1.add(jb1);jp1.add(jb2);jp1.add(jl1);jp1.add(jb3);jp1.add(jb4);
jp2.setLayout(null);
createMonthPanel();
jp2.add(jp3);
jl2.setFont(new Font(null,Font.BOLD,20));
jl2.setText("今天是"+nowyear+"年"+nowmonth+"月"+nowday+"日");
jp4.add(jl2);
add(jp1,BorderLayout.NORTH);
add(jp2,BorderLayout.CENTER);
add(jp4,BorderLayout.SOUTH);
setSize(500,500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent ae) {
if(ae.getSource()==jb1){
year=year-1;
String s=year+"年"+month+"月";
jl1.setText(s);
jp3.removeAll();
createMonthPanel();
jp3.validate();
}
if(ae.getSource()==jb2){
if(month==1){
year=year-1;
month=12;
}else{
month=month-1;
}
String s=year+"年"+month+"月";
jl1.setText(s);
jp3.removeAll();
createMonthPanel();
jp3.validate();
}
if(ae.getSource()==jb3){
if(month==12){
year=year+1;
month=1;
}else{
month=month+1;
}
String s=year+"年"+month+"月";
jl1.setText(s);
jp3.removeAll();
createMonthPanel();
jp3.validate();
}
if(ae.getSource()==jb4){
year=year+1;
String s=year+"年"+month+"月";
jl1.setText(s);
jp3.removeAll();
createMonthPanel();
jp3.validate();
}
}
public static void main(String[] args) {
new CCI();
}
public int getMonthDays(int year, int month) {
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;
case 2:
if ((year%4==0year%100!=0)||year%400==0) {
return 29;
} else {
return 28;
}
default:
return 30;
}
}
public void createMonthPanel(){
c.set(year, month-1, getMonthDays(year,month));
int weekOfMonth=c.get(Calendar.WEEK_OF_MONTH);
if(weekOfMonth==6){
jp3.setLayout(new GridLayout(7,7));
jp3.setBounds(50, 20, 420, 350);
}else{
jp3.setLayout(new GridLayout(6,7));
jp3.setBounds(50, 20, 420, 300);
}
jp3.setBorder(BorderFactory.createEtchedBorder());
for(int i=0;i7;i++){
jl[i]=new JLabel(week[i],JLabel.CENTER);
jl[i].setFont(new Font(null,Font.BOLD,20));
jl[i].setBorder(BorderFactory.createEtchedBorder());
jp3.add(jl[i]);
}
c.set(year, month-1, 1);
int emptyFirst=c.get(Calendar.DAY_OF_WEEK)-1;
int daysOfMonth=getMonthDays(year,month);
for(int i=6+emptyFirst;i=7;i--){
int intyear=year;
int intmonth=month;
if(intmonth==1){
intyear=intyear-1;
intmonth=12;
}else{
intmonth=intmonth-1;
}
int intdays=getMonthDays(intyear,intmonth);
jl[i]=new JLabel((intdays+7-i)+"",JLabel.CENTER);
jl[i].setFont(new Font(null,Font.BOLD,20));
jl[i].setForeground(Color.GRAY);
jl[i].setBorder(BorderFactory.createEtchedBorder());
jp3.add(jl[i]);
}
for(int i=7+emptyFirst;idaysOfMonth+7+emptyFirst;i++){
jl[i]=new JLabel((i-7-emptyFirst+1)+"",JLabel.CENTER);
jl[i].setFont(new Font(null,Font.BOLD,20));
if((i+1)%7==0 || (i+1)%7==1){
jl[i].setForeground(Color.RED);
}else if((i-7-emptyFirst+1)==nowdaymonth==nowmonthyear==nowyear)
jl[i].setForeground(Color.BLUE);
else
jl[i].setForeground(Color.BLACK);
jl[i].setBorder(BorderFactory.createEtchedBorder());
jp3.add(jl[i]);
}
if(weekOfMonth==6)
for(int i=48;i=daysOfMonth+emptyFirst+7;i--){
jl[i]=new JLabel((49-i)+"",JLabel.CENTER);
jl[i].setFont(new Font(null,Font.BOLD,20));
jl[i].setForeground(Color.GRAY);
jl[i].setBorder(BorderFactory.createEtchedBorder());
jp3.add(jl[i]);
}
else
for(int i=41;i=daysOfMonth+emptyFirst+7;i--){
jl[i]=new JLabel((42-i)+"",JLabel.CENTER);
jl[i].setFont(new Font(null,Font.BOLD,20));
jl[i].setForeground(Color.GRAY);
jl[i].setBorder(BorderFactory.createEtchedBorder());
jp3.add(jl[i]);
}
}
}
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流