/** Constructor for PCF8563Demo. */ public PCF8563Demo() { my8563 = new PCF8563(); ttrans = new Time(); Display lcd = new Display(); // initialize the rtc try { my8563.reset(); } catch (IOException ex) { } // get time/date from rtc try { my8563.getTime(ttrans); } catch (IOException ex) { if (ex instanceof TimeIntegrityLostException) { lcd.drawString("PCF8563-time not valid", 4, 31); } } // set time/date of the JCU RTC.setTime(ttrans); // initialize vole components mainContainer = new Container(); mainContainer.setBounds(0, 0, 128, 64); this.add(mainContainer); mainMenu(); setVisible(true); }
/** The main menu with date labels and analog clock. */ void mainMenu() { modify = false; mainContainer.removeAll(); // remove all components okButton = null; // delete all components for the garbage collector cancelButton = null; dayChange = null; monthChange = null; yearChange = null; hourChange = null; minuteChange = null; secondChange = null; if (graphics != null) graphics.clearRect(0, 0, 128, 64); // clear screen Border b1 = new Border("Datum", 0, 0, 53, 34); // create borders mainContainer.add(b1); Border b2 = new Border("Uhrzeit", 54, 0, 74, 64); mainContainer.add(b2); changeButton = new Button("stellen", 2, 51, 40, 11); // the set time button mainContainer.add(changeButton); changeButton.setActionListener(this); clock = new AnalogClock(63, 5, 28, true); // analog clock mainContainer.add(clock); { // initialize time values Time t = new Time(); years = t.year; months = t.month; days = t.day; clock.setValue(t.hour, t.minute, t.second); // initially draw the clock } // create date labels day = new Label((days < 10 ? "0" : "").concat(String.valueOf(days)).concat("."), 2, 15); month = new Label((months < 10 ? "0" : "").concat(String.valueOf(months)).concat("."), 15, 15); year = new Label(String.valueOf(years), 28, 15); // add date labels mainContainer.add(day); mainContainer.add(month); mainContainer.add(year); changeButton.requestFocus(); // start time requester thread timeRequester = new TimeRequester(); timeRequester.start(); }
/** The time modify page. */ void modifyMenu() { modify = true; // stop the time request thread if (timeRequester != null) { while (!timeRequesterReady) { try { ThreadExt.sleep(100); } catch (InterruptedException ex) { } } timeRequester = null; } mainContainer.removeAll(); // remove all components graphics.clearRect(0, 0, 128, 64); // clear screen day = null; // delete all components for the garbage collector month = null; year = null; clock = null; changeButton = null; mainContainer.add(new Border("Datum/Uhrzeit stellen", 0, 0, 128, 64)); // border okButton = new Button("Ok", 2, 51, 40, 11); // ok button okButton.setActionListener(this); mainContainer.add(okButton); cancelButton = new Button("Abbrechen", 44, 51, 40, 11); // cancel button cancelButton.setActionListener(this); mainContainer.add(cancelButton); // initialize all number choosers with the current time Time t = new Time(); dayChange = new NumberChooser(10, 10, 1, 31); // day dayChange.setValue(t.day); mainContainer.add(dayChange); dayChange.setActionListener(this); monthChange = new NumberChooser(40, 10, 1, 12); // month monthChange.setValue(t.month); mainContainer.add(monthChange); monthChange.setActionListener(this); yearChange = new NumberChooser(70, 10, 2003, 2099); // year yearChange.setValue(t.year); mainContainer.add(yearChange); yearChange.setActionListener(this); hourChange = new NumberChooser(10, 25, 0, 23); // hours hourChange.setValue(t.hour); mainContainer.add(hourChange); hourChange.setActionListener(this); minuteChange = new NumberChooser(40, 25, 0, 59); // minutes minuteChange.setValue(t.minute); mainContainer.add(minuteChange); minuteChange.setActionListener(this); secondChange = new NumberChooser(70, 25, 0, 59); // seconds secondChange.setValue(t.second); mainContainer.add(secondChange); secondChange.setActionListener(this); okButton.requestFocus(); }