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控制台实现万年历-要求打印当前年月日的日历表格,要求对当天的日期单独标示以下是用java swing编写的日历,很好用,在我所做的系统里就能够正常的使用
接下来 是具体代码:
package Demo;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.border.LineBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class DateChooser extends JPanel implements ActionListener,
ChangeListener {
/**
*
*/
private static final long serialVersionUID = 1L;
int startYear = 1980;
int lastYear = 2050;
int width = 270;
int height = 200;
Color backGroundColor = Color.gray;
Color palletTableColor = Color.white;
Color todayBackColor = Color.orange;
Color weekFontColor = Color.blue;
Color dateFontColor = Color.black;
Color weekendFontColor = Color.red;
Color controlLineColor = Color.pink;
Color controlTextColor = Color.white;
Color rbFontColor = Color.white;
Color rbBorderColor = Color.red;
Color rbButtonColor = Color.pink;
Color rbBtFontColor = Color.red;
JDialog dialog;
JSpinner yearSpin;
JSpinner monthSpin;
JSpinner hourSpin;
JSpinner minuteSpin;
JButton[][] daysButton = new JButton[6][7];
JFormattedTextField jFormattedTextField;
Calendar c = getCalendar();
DateChooser(JFormattedTextField jftf) {
jFormattedTextField = jftf;
setLayout(new BorderLayout());
setBorder(new LineBorder(backGroundColor, 2));
setBackground(backGroundColor);
JPanel topYearAndMonth = createYearAndMonthPanal();
推荐阅读
- word2007怎么页眉,word2007页眉距边界怎么设置
- 新安装路由器怎么选择,新买个路由器安装教程
- 20兆经营游戏,20mb的游戏
- 安卓平板吃鸡哪家强点好,安卓平板哪个好吃鸡
- python双摄函数 python双目运算符
- a88主板搭配什么cpu,a88主板搭配什么显卡
- 什么可以和cpu互换,cpu能和什么打交道
- 手机直播怎么发送视频,怎样发送直播视频
- 函数求极限用python 函数求极限用等价换算的条件