資源描述:
《JAVA實現(xiàn)日期選擇控件》由會員上傳分享,免費在線閱讀,更多相關內容在教育資源-天天文庫。
1、JAVA實現(xiàn)日期選擇控件實現(xiàn)效果如下所示:想自己寫個小的記帳本,數(shù)據(jù)庫那該沒問題了,想想前臺的布置的時候,突然想要有個日期選擇的控件舊好了,我知道DELPHI里有的,不知道JAVA里有沒有,百渡下,好象沒有很成型的,還有的要收費的,找到了下面的程序,是嵌到Button里的,自己寫了個測試程序,還行,界面還算可以,基本功能也基本實現(xià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