Class TimeBox


  • public class TimeBox
    extends Window
    Class used to input a time from the user. Correctly handles the AM/PM depending on Settings.is24Hour.

    When the window closes, a PRESSED event is sent to the caller, and the time can be retrieved using getTime. Here's a sample:
     TimeBox tb;
     
     public void initUI() {
            try {
                    (tb = new TimeBox()).popupNonBlocking();
            } catch (Exception e) {
                    e.printStackTrace();
            }
     }
     
     public void onEvent(Event e) {
            if (e.type == ControlEvent.PRESSED && e.target == tb)
                    Vm.debug("ret: " + tb.getTime());
     }
     
    The time can be entered also using the arrow keys and by typing the numbers directly.
    Since:
    TotalCross 1.22
    See Also:
    getTime()
    • Field Detail

      • btClear

        protected Button btClear
      • btBack

        protected Button btBack
      • btForw

        protected Button btForw
      • btAM

        protected Radio btAM
      • btPM

        protected Radio btPM
      • visor

        protected totalcross.ui.dialog.TimeBox.Visor visor
      • okCaption

        public static java.lang.String okCaption
        Used in the button. Change it if you want to localize the text.
      • clearCaption

        public static java.lang.String clearCaption
        Used in the button. Change it if you want to localize the text.
      • hideIfInvalid

        public static boolean hideIfInvalid
        Set to false to disable the buttons instead of hiding them if they are not a valid number to appear at the current position. By default, the buttons are hidden, but setting this to false can disable them instead.
    • Constructor Detail

      • TimeBox

        public TimeBox()
        Constructs a TimeBox with time set to midnight.
      • TimeBox

        public TimeBox​(Time time)
        Constructs a TimeBox with the given time. If the time is invalid, it is set to midnight.
    • Method Detail

      • setTime

        public void setTime​(Time time)
        Set the time, if it was not yet set in the constructor.
      • onFontChanged

        public void onFontChanged()
        Description copied from class: Control
        Called after a setFont
        Overrides:
        onFontChanged in class Control
      • onPopup

        protected void onPopup()
        Description copied from class: Window
        Placeholder called imediatly before the popup began. The default implementation does nothing.
        Overrides:
        onPopup in class Window
      • getTime

        public Time getTime()
        Returns the time placed in this control, which is the time passed in the constructor (if any) updated with the hours, minutes and seconds.
      • reposition

        public void reposition()
        Description copied from class: Control
        Reposition this control, calling again setRect with the original parameters.
        Overrides:
        reposition in class Control
      • setBackColor

        public void setBackColor​(int c)
        Changing this method will also change the UIColors.timeboxBack attribute
        Overrides:
        setBackColor in class Control
      • setForeColor

        public void setForeColor​(int c)
        Changing this method will also change the UIColors.timeboxFore attribute
        Overrides:
        setForeColor in class Control
      • setBackForeColors

        public void setBackForeColors​(int back,
                                      int fore)
        Changing this method will also change the UIColors.timeboxBack and UIColors.timeboxFore attributes
        Overrides:
        setBackForeColors in class Control
      • onEvent

        public void onEvent​(Event event)
        Description copied from class: Control
        Called to process key, pen, control and other posted events.
        Overrides:
        onEvent in class Control
        Parameters:
        event - the event to process
        See Also:
        Event, KeyEvent, PenEvent
      • postUnpop

        protected void postUnpop()
        Description copied from class: Window
        Placeholder called after the unpop is done and after the repaint of the other window. The default implementation does nothing.
        Overrides:
        postUnpop in class Window