can use Jieformatteddatebox box = new Jieformatteddatebox ("yyyy mm month DD Day hh point mm minute ss seconds");
You can also use jieformatteddatebox box = new Jieformatteddatebox ("HH:mm:ss") to enter the time
You can also use JSpinner spinner = new JSpinner (); Jieformatteddatebox fdb = new Jieformatteddatebox (format); Spinner.setmodel (FDB); Spinner.seteditor (FDB);
public void SetTime (Timestamp time) {if (time!= null) SetValue (time); Public Timestamp GetTime () {return time; }
public static string replace (string src,string replacesrc,string replacewith) {if (src = null) return null; StringBuffer sb = new StringBuffer (); int start = 0; int end = Src.indexof (REPLACESRC); while (end >= 0) {sb.append (src.substring (start,end)); Start = End+replacesrc.length (); End = Src.indexof (Replacesrc,start); Sb.append (replacewith); } sb.append (Src.substring (start)); return sb.tostring (); }
Public Jieformatteddatebox (String format) {super (); This.format = format; TimeFormat = new SimpleDateFormat (format); Time = new Timestamp (System.currenttimemillis ());
try{String mask = format; for (int i=0;i<alais.length;i++) {mask = replace (mask,alais[i],formats[i]); } maskformatter MF = new Maskformatter (mask); Mf.setplaceholdercharacter ('_'); Setformatterfactory (New Defaultformatterfactory (MF)); }catch (Exception e) {e.printstacktrace (); }
SetText (Timeformat.format (time)); this.getdocument (). Adddocumentlistener (New Documentlistener () { public void Insertupdate (Documentevent e) { checktime (); } public void Removeupdate (documentevent e) { checktime (); } public void Changedupdate (Documentevent e) {} }); This.sethorizontalalignment ( Swingconstants.right); This.addfocuslistener (New Focuslistener () { public void focusgained (FocusEvent e) {} public void Focuslost (FocusEvent e) { SetValue (Time); } }); }
void Checktime () { try{ String Text = GetText (); if (text = null | | text.equals ("")) return; time = New Timestamp (Timeformat.parse (text). GetTime ()); }catch (Exception ex) { try{ Swingutilities.invokelater (New Runnable () { Public void Run () { & nbsp; SetValue (Time); } }); }catch (Exception e) {} }
}
public Object GetValue () { return This.gettext (); } public void SetValue (Object value) { time = (Timestamp) value; int index = this.getcaretposition (); if (time = null) { This.settext (""); }else This.settext (Timeformat.format (time)); this.setcaretposition (index); /keep caret position } public Object getnextvalue () { return new Timestamp (Time.gettime () +getincrease (This.getcaretposition (), format,time)); } public Object getpreviousvalue () { return new Timestamp (Time.gettime ()-getdecrease (This.getcaretposition (), format,time)); } public void Addchangelistener (ChangeListener l) {} public void Removechangelistener (ChangeListener l) {}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.