📄 auctiondemo.java
字号:
} } else if (obj == setMenu) { if (c == List.SELECT_COMMAND) { int idx = obj.getSelectedIndex(); switch (idx) { case 0: date.setDate(); display.setCurrent(date); break; case 1: display.setCurrent(setTicker); break; case 2: display.setCurrent(updateInt); break; case 3: display.setCurrent(addBand); break; case 4: display.setCurrent(rmBand); break; } } else if (c == BACK_CMD) { display.setCurrent(aucMenu); } } } else if (s instanceof Form) { Form obj = (Form) s; if (obj == ticketForm) { if (c == BACK_CMD) { display.setCurrent(ticketList); } else if (c == MENU_CMD) { display.setCurrent(aucMenu); } } else if (obj == bidForm) { if (c == BACK_CMD) { display.setCurrent(ticketList); } else if (c == NEXT_CMD) { login.setBid(ticketList.getTitle(), bidText.getString()); display.setCurrent(login); } } else if (obj == enterForm) { if (c == BACK_CMD) { display.setCurrent(ticketList); } else if (c == SAVE_CMD) { updateAlert.set(ticketList.getTitle(), enterText.getString()); display.setCurrent(alertMsg, aucMenu); } } } else if (s instanceof TextBox) { TextBox obj = (TextBox) s; if (obj == addBand) { if (c == BACK_CMD) { display.setCurrent(setMenu); } else if (c == SAVE_CMD) { updateBandList(addBand.getString()); display.setCurrent(savedMsg, setMenu); } } } } class Login extends Form implements CommandListener { TextField id = new TextField("", "", 10, TextField.ANY); TextField pd = new TextField("", "", 10, (TextField.NUMERIC|TextField.PASSWORD)); Form confirm = new Form("Confirm"); Form notice = new Form("Alert"); Login() { super(null); append("Please Enter Auction ID:"); append(id); append("Password:"); append(pd); addCommand(BACK_CMD); addCommand(NEXT_CMD); setCommandListener(this); confirm.append("dummy"); confirm.addCommand(BACK_CMD); confirm.addCommand(SUBMIT_CMD); confirm.setCommandListener(this); notice.append("Your bid\n"); notice.append("has been\n"); notice.append("received.\n"); notice.append("Confirm #:\n"); notice.append("12-B455-31"); notice.addCommand(BACK_CMD); notice.addCommand(MENU_CMD); notice.setCommandListener(this); } String band, bid, ticketID; void setBid(String band, String bid) { this.band = band; this.bid = bid; } void setID(String band, String ticketID) { this.band = band; this.ticketID = ticketID; } public void commandAction(Command c, Displayable s) { if (s instanceof Form) { Form obj = (Form) s; if (obj == this) { if (c == BACK_CMD) { display.setCurrent(bidForm); } else if (c == NEXT_CMD) { String str = "# " + ticketID + "\n" + band + "\n" + "Bid Amount:\n" + "$" + bid; confirm.delete(0); confirm.append(str); display.setCurrent(confirm); } } else if (obj == confirm) { if (c == BACK_CMD) { display.setCurrent(bidForm); } else if (c == SUBMIT_CMD) { // display.setCurrent(submitMsg, notice); TimerService = new Timer(); TimerClient timerClient = new TimerClient(); TimerService.schedule(timerClient, 0, 1000); display.setCurrent(submitMsg); } } else if (obj == notice) { if (c == BACK_CMD) { display.setCurrent(bidForm); } else if (c == MENU_CMD) { display.setCurrent(aucMenu); } } } } private class TimerClient extends TimerTask { public final void run() { if (submitGauge.getValue() == submitGauge.getMaxValue()) { TimerService.cancel(); submitGauge.setValue(0); display.setCurrent(notice); } else { submitGauge.setValue(submitGauge.getValue()+10); } } } } class SetDate extends Form implements CommandListener { DateField dateTimeItem = new DateField(null, DateField.DATE_TIME); SetDate() { super(null); append("Use this screen to set the date and time" + " on your phone before submitting bids.\n"); append(dateTimeItem); addCommand(BACK_CMD); setCommandListener(this); } void setDate() { dateTimeItem.setDate(new java.util.Date()); } public void commandAction(Command c, Displayable s) { if (s instanceof Form) { Form obj = (Form) s; if (obj == this) { if (c == BACK_CMD) { display.setCurrent(setMenu); } } } } } class SetTicker extends Form implements CommandListener { ChoiceGroup cg; SetTicker() { super("Ticker Display"); cg = new ChoiceGroup(null, Choice.MULTIPLE); cg.append("My Bands", null); cg.append("Pop", null); cg.append("Rock", null); cg.append("Alternative", null); cg.append("Jazz", null); cg.append("Classical", null); append(cg); cg.setSelectedIndex(3, true); addCommand(BACK_CMD); addCommand(SAVE_CMD); setCommandListener(this); } boolean[] ret = new boolean[6]; public void commandAction(Command c, Displayable s) { if (c == SAVE_CMD) { cg.getSelectedFlags(ret); String str = band.toTickerString(ret); if (str != null) { ticker.setString(str); } display.setCurrent(savedMsg, setMenu); } else if (c == BACK_CMD) { display.setCurrent(setMenu); } } } class Update extends Form implements CommandListener { Timer timerService = new Timer(); ChoiceGroup cg; Update() { super("Update"); cg = new ChoiceGroup(null, Choice.EXCLUSIVE); cg.append("Continuous", null); cg.append("15 minutes", null); cg.append("30 minutes", null); cg.append("1 hour", null); cg.append("3 hours", null); append(cg); addCommand(BACK_CMD); addCommand(SAVE_CMD); setCommandListener(this); } public void commandAction(Command c, Displayable s) { if (c == SAVE_CMD) { if (updateAlert.hasDataToUpdate()) { int idx = cg.getSelectedIndex(); TimerTask timerClient = new TimerTask() { public final void run() { updateAlert.show(); } }; switch (idx) { case 0: timerService.schedule(timerClient, 3000); break; case 1: timerService.schedule(timerClient, 3000); break; case 2: timerService.schedule(timerClient, 3000); break; case 3: timerService.schedule(timerClient, 3000); break; case 4: timerService.schedule(timerClient, 3000); break; } } display.setCurrent(savedMsg, setMenu); } else if (c == BACK_CMD) { display.setCurrent(setMenu); } } } class UpdateAlert implements CommandListener { String band = "", bid = ""; Form f = new Form("Alert"); UpdateAlert() { f.append("dummy"); f.addCommand(BACK_CMD); f.setCommandListener(this); } void set(String band, String bid) { this.band = band; this.bid = bid; } boolean hasDataToUpdate() { return ((band != null) && (band != "") && (bid != null) && (bid != "")); } void show() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -