📄 newticketauction.java
字号:
Form confirm = new Form("Confirm Bid"); Form notice = new Form("Bid Received"); Form auctionForm = new Form("dummy"); Alert loginAlert = new Alert("Alert", "Your must enter your ID and password" + " before you can proceed.", null, null); Login() { super("Make A Bid"); id.setLabel("Enter Auction ID:"); append(id); pd.setLabel("Enter PIN:"); append(pd); append(curBid); append(incBid); append(minBid); append(bidText); addCommand(BACK_CMD); addCommand(NEXT_CMD); setCommandListener(this); ItemCommandListener icl = new MyItemCommandListener(); confirm.append("dummy"); confirm.addCommand(CANCEL_CMD); confirm.setCommandListener(this); auctionHyperlink.setDefaultCommand(AUCTION_CMD); auctionHyperlink.setItemCommandListener(icl); submitButton.setDefaultCommand(SUBMIT_CMD); submitButton.setItemCommandListener(icl); deleteFormItem(notice); notice.append(new StringItem("Your bid has been received:", "")); notice.append(new StringItem("Confirm #:", "12-B455-31")); notice.addCommand(BAND_CMD); notice.setCommandListener(this); loginAlert.setTimeout(Alert.FOREVER); auctionForm.append("dummy"); auctionForm.addCommand(BACK_CMD); auctionForm.setCommandListener(this); } String bandName, bid, ticketID, _bandName; int _bandIndex; void setBid(String bandName, String bid) { this.bandName = bandName; this.bid = bid; } void setID(String bandName, String ticketID) { this.bandName = bandName; this.ticketID = ticketID; } void setBandAttributes(String bandName, int bandIndex) { _bandName = bandName; _bandIndex = bandIndex; } void doSubmit() { TimerService = new Timer(); TimerClient timerClient = new TimerClient(); TimerService.schedule(timerClient, 0, 1000); display.setCurrent(submitMsg); } class MyItemCommandListener implements ItemCommandListener { public void commandAction(Command c, Item item) { if (c == SUBMIT_CMD) { doSubmit(); } else if (c == AUCTION_CMD) { deleteFormItem(auctionForm); auctionForm.setTitle("Auction:" +login.ticketID); band.getAuctionData(auctionForm, login.bandName, login._bandIndex); display.setCurrent(auctionForm); } } } public void commandAction(Command c, Displayable s) { if (s instanceof Form) { Form obj = (Form) s; if (obj == this) { if (c == BACK_CMD) { display.setCurrent(band_ticket_Form); } else if (c == NEXT_CMD) { if ((id.getString().length() == 0) || (pd.getString().length() == 0)) { // || // (bidText.getString().length() == 0)) { display.setCurrent(loginAlert); } else { login.setID(_bandName, band.getTicketID(_bandName, _bandIndex)); String bidAmt = bidText.getString(); System.err.println("\n\n #### bidAmt : " + bidAmt); // check if bid text is valid, if not pop up an alert if (bidAmt.equals("")) { Alert errorAlert = new Alert("Alert", "The bid amount you have entered is invalid.", null, AlertType.ERROR); errorAlert.setTimeout(Alert.FOREVER); display.setCurrent(errorAlert); } else { deleteFormItem(login.confirm); login.confirm.append(new StringItem("Please confirm this information is correct before submitting your bid", "")); auctionHyperlink.setText(login.ticketID); login.confirm.append(auctionHyperlink); login.confirm.append(new StringItem("Band: " + login.bandName, "")); login.confirm.append(new StringItem("Bid Amount:", "$"+bidAmt)); login.confirm.append(submitButton); display.setCurrent(login.confirm); } } } } else if (obj == confirm) { if (c == CANCEL_CMD) { display.setCurrent(this); } } else if (obj == notice) { if (c == BAND_CMD) { display.setCurrent(band_ticket_Form); } } else if (obj == auctionForm) { if (c == BACK_CMD) { display.setCurrent(confirm); } } } } 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 Band { private BandListTable table; class TicketItem { // Ticket info String name; // item name i.e. band name String seat; // seat number String sect; // seat section String date; // concert date String place; // concert place String state; // place's state // Bid info String id; // id i.e. item number String numItem; // quantity String begBid; // beginning bid price String curBid; // current bid price String incBid; // bid increment String numBids; // # of bids String endsAt; // Bid close time TicketItem(String name, String seat, String sect, String date, String place, String state, String id, String numItem, String begBid, String curBid, String incBid, String numBids, String endsAt) { this.name = name; this.seat = seat; this.sect = sect; this.date = date; this.place = place; this.state = state; this.id = id; this.numItem = numItem; this.begBid = begBid; this.curBid = curBid; this.incBid = incBid; this.numBids = numBids; this.endsAt = endsAt; } TicketItem(String name) { this(name, "n/a", "n/a", "n/a", "n/a", "n/a", "0", "0", "0", "0", "0", "0", "0"); } } class BandListTable { private Vector vec = new Vector(); BandListTable() { vec = new Vector(); } void put(int nth, Object obj) { Object o = null; try { o = vec.elementAt(nth); } catch (ArrayIndexOutOfBoundsException e) { o = null; } if (o == null) { vec.addElement(obj); } else { vec.setElementAt(obj, nth); } } Object get(String bandName) { int num = vec.size(); for (int i = 0; i < num; i++) { Object obj = vec.elementAt(i); if (obj instanceof Vector) { Vector v = (Vector) obj; TicketItem item = (TicketItem) v.elementAt(0); if (item.name.equals(bandName)) { return obj; } } } return null; } Object elementAt(int index) { return vec.elementAt(index); } void remove(int i) { Object o = null; try { o = vec.elementAt(i); } catch (ArrayIndexOutOfBoundsException e) { o = null; } if (o != null) { vec.removeElementAt(i); } } int size() { return vec.size(); } } Band() { table = new BandListTable(); TicketItem t; /** * 0: Alanis Morrisette */ t = new TicketItem("Alanis Morrisette", "18 & 19", "XF, Row 17", "Aug 23, 2002", "PacBell Stadium", "San Francisco, CA", "#7720", "2", "45.00", "69.00", "2.00", "3", "12:00 am on Aug 16, 2002"); add(0, "Alanis Morrisette", t); /** * 1: Envy */ t = new TicketItem("Envy", "10, 11, 12, 13", "F9, Row A", "Sep 7, 2002", "Civic Center", "Santa Cruz, CA", "4509", "4", "100.00", "101.00", "1.00", "1", "9:45 pm on Sep 1, 2002"); add(1, "Envy", t); t = new TicketItem("Envy", "69 & 70", "PIT Row 1", "Aug 9, 2002", "Monterey Civic Ampitheatre", "Monterey, CA", "3058", "2", "9.00", "175.00", "2.50", "40", "9:00 pm on Aug 2, 2002"); add(1, "Envy", t); t = new TicketItem("Envy", "5 & 6 & 7", "PIT Rw 11", "Aug 10, 2002", "Monterey Civic Ampitheatre", "Monterey, CA", "3541", "3", "28.00", "97.00", "1.00", "11", "11:15 pm on Aug 2, 2002"); add(1, "Envy", t);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -