資源描述:
《JAVA實(shí)現(xiàn)日期選擇控件》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、JAVA實(shí)現(xiàn)日期選擇控件實(shí)現(xiàn)效果如下所示:想自己寫個(gè)小的記帳本,數(shù)據(jù)庫(kù)那該沒問題了,想想前臺(tái)的布置的時(shí)候,突然想要有個(gè)日期選擇的控件舊好了,我知道DELPHI里有的,不知道JAVA里有沒有,百渡下,好象沒有很成型的,還有的要收費(fèi)的,找到了下面的程序,是嵌到Button里的,自己寫了個(gè)測(cè)試程序,還行,界面還算可以,基本功能也基本實(shí)現(xiàn),雖然有些地方不是很智能,有待改進(jìn).程序如下:importjava.util.Date;importjava.util.Calendar;importjava.text.D
2、ateFormat;importjava.text.SimpleDateFormat;importjava.text.ParseException;importjava.awt.Color;importjava.awt.Font;importjava.awt.Point;importjava.awt.Dimension;importjava.awt.BorderLayout;importjava.awt.FlowLayout;importjava.awt.GridLayout;importjava.
3、awt.Component;importjava.awt.Cursor;importjava.awt.Frame;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.MouseListener;importjava.awt.event.MouseAdapter;importjava.awt.event.MouseEvent;//importjavax.swing.JFram
4、e;importjavax.swing.JButton;importjavax.swing.JDialog;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.JLabel;importjavax.swing.JSpinner;importjavax.swing.JSpinner.NumberEditor;importjavax.swing.SpinnerNumberModel;importjavax.swing.S
5、wingUtilities;importjavax.swing.SwingConstants;importjavax.swing.event.ChangeListener;importjavax.swing.event.ChangeEvent;importjavax.swing.border.LineBorder;publicclassDateChooserJButtonextendsJButton{?privateDateChooserdateChooser=null;?privateString
6、preLabel="";?publicDateChooserJButton(){??this(getNowDate());?}?publicDateChooserJButton(SimpleDateFormatdf,StringdateString){??this();??setText(df,dateString);?}?publicDateChooserJButton(Datedate){??this("",date);?}?publicDateChooserJButton(StringpreL
7、abel,Datedate){??if(preLabel!=null)???this.preLabel=preLabel;??setDate(date);??setBorder(null);??setCursor(newCursor(Cursor.HAND_CURSOR));??super.addActionListener(newActionListener(){???publicvoidactionPerformed(ActionEvente){????if(dateChooser==null)
8、?????dateChooser=newDateChooser();????Pointp=getLocationOnScreen();????p.y=p.y+30;????dateChooser.showDateChooser(p);???}??});?}?privatestaticDategetNowDate(){??returnCalendar.getInstance().getTime();?}?privatestaticSimpleDateFormatgetD