资源描述:
《一个java_swing做的日历控件》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、packagecom.gxaedu.jms.util;importjava.awt.Color;importjava.awt.Component;importjava.awt.Font;importjava.awt.Insets;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.ItemEvent;importjava.awt.event.ItemListener;importjava.awt.event.KeyAda
2、pter;importjava.awt.event.KeyEvent;importjava.awt.event.MouseAdapter;importjava.awt.event.MouseEvent;importjava.text.DateFormatSymbols;importjava.util.Calendar;importjava.util.GregorianCalendar;importjavax.swing.*;importjavax.swing.table.DefaultTableCellRenderer;importjavax.s
3、wing.table.DefaultTableModel;importjavax.swing.table.TableModel;/***一个小的日历*用于输入合法时间*@author王琛**/publicclassSelfCalendarextendsJDialog{privatestaticJPanelmainPanel;///主面板,用来放置
各个组件privatestaticJTextFieldtextYear;//文本框,显示输入年
份privatestaticJComboBoxcomboMonth;//下拉框,显示输入月份private
4、JButtonbtnYearUp;///按钮,年份加一privateJButtonbtnYearDown;//按钮,年份减一privateJPaneltopPanel;///顶部面板,放置
textYear,comboMonth,btnYearUp,btnYearDownprivateJScrollPanescrollPane;privatestaticJTabletbCalendar;//放置日历主体privateJLabelnowDate;//显示当前年月日privateJPanelnowDatePanel=newJPanel();priva
5、teString[]strMonth=
{"1","2","3","4","5","6","7","8","9","10","11","12"};privateObject[]col;////表列名,星期几privateObject[][]data;//privateTableModeltableModel;privatestaticGregorianCalendargc=newGregorianCalendar();privateintselfYear;privateintselfMonth;privatestaticStringselfDat
6、e;privateintk=0;privatebooleanflag;privateJTextFieldtxtTime;/***自定义日历的构造方法*/publicSelfCalendar(JTextFieldtxtTime){//super(frame,true);this.txtTime=txtTime;this.setSize(190,200);this.setModal(true);///设置为模式窗口this.setFocusable(true);/////this.setUndecorated(true);///去掉修饰this.se
7、tLocationRelativeTo(null);///简单的居中this.init();this.addListener();this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);this.setLayout(null);this.setVisible(true);this.setResizable(false);}privatevoidinit(){mainPanel=newJPanel();mainPanel.setBounds(0,0,180,170);mainPanel.setLayout(n
8、ull);mainPanel.setBackground(Color.BLACK);topPanel=newJPanel();topPa