📄 ticketauction.java
字号:
form.append(new StringItem("Quantity:", item.numItem)); form.append(new StringItem("Starts at:", "$"+item.begBid)); form.append(new StringItem("Current:", "$"+item.curBid)); form.append(new StringItem("Bids:", item.numBids)); form.append(new StringItem("Ends at:", item.endsAt)); form.append(new StringItem("Sec:", item.sect)); form.append(new StringItem("Seat(s):", item.seat)); form.append(new StringItem("Date:", item.date)); form.append(new StringItem("Place:", item.place+","+item.state)); } boolean isTicketData(String bandName, String itemID) { return (getTicketItem(bandName, itemID) == null) ? false : true; } TicketItem getTicketItem(String bandName, String itemID) { Object obj = table.get(bandName); if (obj == null) { return null; } Vector vec = (Vector) obj; int num = vec.size(); for (int i = 0; i < num; i++) { TicketItem item = (TicketItem) vec.elementAt(i); if (item.id.equals(itemID)) { return item; } } return null; } void getTicketBidTitle(Form f, String bandName, int itemID) { TicketItem item = getTicketItem(bandName, itemID); long min = stringToLong1000(item.curBid) + stringToLong1000(item.incBid); String minBid = long1000ToString(min); deleteFormItem(f); f.append(new StringItem("Current Bid:", "$"+item.curBid)); f.append(new StringItem("Increment:", "$"+item.incBid)); f.append(new StringItem("Minimum Bid:", "$"+minBid)); } String def_ticker = "Ricky Martin 2 tix $90.00 2 tix $110.00" + " 2 tix $200.00 Tina Turner 2 tix $65.00"; String alt_ticker = "Alanis Morisette 2 tix $58.00 4 tix $115.00" + " Fiona Apple 2 tix $37.00"; String toTickerString(boolean[] selected) { String s = ""; if (selected == null) { return alt_ticker; } // Rock Bands if (selected[0]) { s += def_ticker; } // Pop if (selected[1]) { } // Country if (selected[2]) { } // Alternative if (selected[3]) { if (s.length() > 0) { s += " "; } s += alt_ticker; } // Jazz if (selected[4]) { } // Classical if (selected[5]) { } return s; } long stringToLong1000(String s) { if (s == null || s.equals("")) { return 0; } try { int index = s.indexOf('.'); if (index == -1) return (long)1000*Integer.parseInt(s); long integerPart = 1000*Integer.parseInt(s.substring(0, index)); String fracString = s.substring(index+1); int multBy = 0; switch (fracString.length()) { case 0: multBy = 0; break; case 1: multBy = 100; break; case 2: multBy = 10; break; case 3: multBy = 1; break; } long fractionalPart = multBy * Integer.parseInt(fracString); return integerPart + fractionalPart; } catch (NumberFormatException nfe) { return 0; } } String long1000ToString(long l) { if (l == 0) return "0"; String s = String.valueOf(l); if (s.length() < 4) return "0"; String newStr = s.substring(0, s.length()-3) +"."+ s.substring(s.length()-2); return newStr; } } // end band class RmBand extends List implements CommandListener { RmBand() { super("Remove Bands", Choice.MULTIPLE); String[] list = band.getList(); for (int i = 0; i < list.length; i++) { append(list[i], null); } addCommand(BACK_CMD); addCommand(SAVE_CMD); setCommandListener(this); } public void commandAction(Command c, Displayable s) { if (c == SAVE_CMD) { // Make the ChoiceGroup invisible before doing // reconstruction boolean[] ret = new boolean[size()]; getSelectedFlags(ret); removeBandList(ret); // go back to bandList after save display.setCurrent(savedMsg, bandList); } else if (c == BACK_CMD) { display.setCurrent(bandList); } } void reset() { reconstructList(this, band.getList()); } void removeBandList(boolean[] t) { int i = t.length; while (--i >= 0) { if (t[i]) { band.remove(i); } } reconstructList(bandList, band.getList()); reconstructList(this, band.getList()); } } // end rm band class UpdateAlert { String band = "", bid = ""; Alert soundAlert; UpdateAlert() { soundAlert = new Alert("Alert", "", null, AlertType.ALARM); soundAlert.setTimeout(Alert.FOREVER); } void set(String band, String bid) { this.band = band; this.bid = bid; } boolean hasDataToUpdate() { return ((band != null) && (band != "") && (bid != null) && (bid != "")); } void show() { // no-op if band & bid aren't set if (hasDataToUpdate()) { String s = new String(band + "\n" + "ticket bids\n" + "have reached\n" + "$" + bid); soundAlert.setString(s); display.setCurrent(soundAlert); } } }// end UpdateAlert void updateBandList(String list) { if (list.length() == 0) { return; } Vector vec = new Vector(); int fidx = 0; while (true) { int idx = list.indexOf(',', fidx); if (idx == -1) { vec.addElement(list.substring(fidx)); break; } vec.addElement(list.substring(fidx, idx)); fidx = idx + 1; } for (int i = 0; i < vec.size(); i++) { String str = (String)vec.elementAt(i); int j = 0; int len = str.length(); for (; j < len; j++) { if (str.charAt(j) != ' ') { break; } } if (j == len) { continue; } if (j == 0) { band.add(str); } else { band.add(str.substring(j)); } } reconstructList(bandList, band.getList()); rmBand.reset(); } void reconstructList(Choice list, String[] items) { int num = list.size(); while (--num >= 0) { list.delete(num); } for (int i = 0; i < items.length; i++) { list.append(items[i], null); } // list.setSelectedIndex(0, true); } class SetTicker extends List implements CommandListener { SetTicker() { super("Ticker Display", Choice.EXCLUSIVE); append("Rock", null); append("Pop", null); append("Country", null); append("Alternative", null); append("Jazz", null); append("Classical", null); 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) { 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); } } }// end SetTicker class SetDate extends Form implements CommandListener { DateField dateTimeItem = new DateField(null, DateField.DATE_TIME); Date currentDate = new java.util.Date(); 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(currentDate); } public void commandAction(Command c, Displayable s) { if (s instanceof Form) { Form obj = (Form) s; if (obj == this) { Date newDate = dateTimeItem.getDate(); if (!newDate.equals(currentDate)) { currentDate = newDate; } if (c == BACK_CMD) { display.setCurrent(setMenu2); } } } } }// end SetDate class SetMenuForm extends Form implements CommandListener, ItemStateListener { Gauge gauge = new Gauge("0", true, 40, 0); int n = 0; int oldValue = 0; Timer timerService = new Timer(); ChoiceGroup cg; SetMenuForm() { super("Settings"); cg = new ChoiceGroup("Updates", 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); append("\n"); append("\n"); /* Set Number */ append(new StringItem("Set Alert Volume", "")); append(gauge); setItemStateListener(this); addCommand(BACK_CMD); addCommand(SAVE_CMD); setCommandListener(this); } void setNumber(int num) { gauge.setValue(num); } 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, bandList); } else if (c == BACK_CMD) { display.setCurrent(setMenu); } } public void itemStateChanged(Item item) { if (item == gauge) { int currentValue = gauge.getValue(); gauge.setLabel(String.valueOf(currentValue)); } } } void deleteFormItem(Form f) { int num = f.size(); while (--num >= 0) { f.delete(num); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -