📄 ticketauction.java
字号:
/* * "@(#)TicketAuction.java 1.35 01/08/15" * Copyright (c) 1999-2001 Sun Microsystems, Inc. All Rights Reserved. * * This software is the confidential and proprietary information of Sun * Microsystems, Inc. ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with Sun. * * SUN MAKES NO REPRESENT THE SUITABILITY OF THE * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING * THIS SOFTWARE OR ITS DERIVATIVES. */package example.auction;import java.util.*;import javax.microedition.midlet.*;import javax.microedition.lcdui.*;import javax.microedition.lcdui.List;public class TicketAuction extends MIDlet implements CommandListener { Display display; Band band = new Band(); Login login = new Login(); TextBox addBand; RmBand rmBand = new RmBand(); static final Command BACK_CMD = new Command("Back", Command.BACK, 1); static final Command SAVE_CMD = new Command("Save", Command.SCREEN, 2); static final Command NEXT_CMD = new Command("Next", Command.SCREEN, 2); static final Command SUBMIT_CMD = new Command("Submit", Command.SCREEN, 2); List mainMenu, cateMenu, aucMenu, bandList, ticketList, setMenu; Ticker ticker; Alert notImpl, savedMsg, alertMsg; Form ticketForm, enterForm, bidForm, submitMsg; TextField enterText, bidText; UpdateAlert updateAlert = new UpdateAlert(); SetDate date = new SetDate(); // SetNumber number = new SetNumber(); SetTicker setTicker = new SetTicker(); Gauge submitGauge; Timer TimerService; SetMenuForm setMenu2 = new SetMenuForm(); // Update updateInt = new Update(); // Band Name and Index number of the selected band in Band Screen bandList String _bandName; int _bandIndex = 0; // commands for Band Screen bandList static final Command SHOW_CMD = new Command("Show Auctions", Command.SCREEN, 1); static final Command ADD_CMD = new Command("Add Bands", Command.SCREEN, 2); static final Command RMV_CMD = new Command("Remove Bands", Command.SCREEN, 3); static final Command SETTING_CMD = new Command("Settings", Command.SCREEN, 4); static final Command EXIT_CMD = new Command("Exit", Command.EXIT, 3); // commands for Auction Screen ticketList static final Command SHOW_INFO_CMD = new Command("More Info", Command.SCREEN, 1); static final Command MAKE_BID_CMD = new Command("Make a Bid", Command.SCREEN, 2); static final Command SET_ALERT_CMD = new Command("Set an Alert", Command.SCREEN, 3); // command for Bid screen ticketForm static final Command BAND_CMD = new Command("Bands", Command.SCREEN, 1); public TicketAuction() { display = Display.getDisplay(this); } public void startApp() { notImpl = new Alert("Sorry!!!", "Not Implemented", null, null); savedMsg = new Alert(null, "Your new settings have been saved!", null, null); alertMsg = new Alert(null, "Your alerts have been saved!", null, null); submitGauge = new Gauge("", false, 100, 0); submitMsg = new Form("Submitting bid..."); submitMsg.append(submitGauge); ticker = new Ticker(""); ticker.setString(band.toTickerString(null)); aucMenu = new List("Auction Menu", Choice.IMPLICIT); aucMenu.append("Ticket Info", null); aucMenu.append("Make a Bid", null); aucMenu.append("Set an Alert", null); aucMenu.append("Settings", null); aucMenu.append("About", null); aucMenu.addCommand(BACK_CMD); aucMenu.setCommandListener(this); aucMenu.setTicker(ticker); // display.setCurrent(aucMenu); bandList = new List("Choose Band", Choice.IMPLICIT); bandList.addCommand(SHOW_CMD); bandList.addCommand(ADD_CMD); bandList.addCommand(RMV_CMD); bandList.addCommand(SETTING_CMD); bandList.addCommand(EXIT_CMD); bandList.setCommandListener(this); bandList.setTicker(ticker); String[] list = band.getList(); for (int i = 0; i < list.length; i++) { bandList.append(list[i], null); } display.setCurrent(bandList); ticketList = new List("dummy", Choice.IMPLICIT); ticketList.addCommand(SHOW_INFO_CMD); ticketList.addCommand(MAKE_BID_CMD); ticketList.addCommand(SET_ALERT_CMD); ticketList.addCommand(BACK_CMD); ticketList.setCommandListener(this); ticketForm = new Form("dummy"); ticketForm.append("dummy"); ticketForm.addCommand(BACK_CMD); ticketForm.addCommand(BAND_CMD); ticketForm.addCommand(MAKE_BID_CMD); ticketForm.addCommand(SET_ALERT_CMD); ticketForm.setCommandListener(this); enterText = new TextField("Tell me when bid reaches:", "", 10, TextField.NUMERIC); enterForm = new Form("Alert"); enterForm.append(enterText); enterForm.addCommand(BACK_CMD); enterForm.addCommand(SAVE_CMD); enterForm.setCommandListener(this); bidText = new TextField("Enter Bid:", "", 10, TextField.NUMERIC); bidForm = new Form("dummy"); bidForm.append("dummy"); bidForm.append(bidText); bidForm.addCommand(BACK_CMD); bidForm.addCommand(NEXT_CMD); bidForm.setCommandListener(this); setMenu = new List("Settings", Choice.IMPLICIT); setMenu.append("Ticker Tape", null); setMenu.append("Updates", null); setMenu.addCommand(BACK_CMD); setMenu.setCommandListener(this); setMenu.setTicker(ticker); addBand = new TextBox("Add Bands, Bands:", "", 100, TextField.ANY); addBand.addCommand(BACK_CMD); addBand.addCommand(SAVE_CMD); addBand.setCommandListener(this); } public void destroyApp(boolean unconditional) { } public void pauseApp() { } public void commandAction(Command c, Displayable s) { if (s instanceof List) { List obj = (List) s; if (obj == aucMenu) { if (c == List.SELECT_COMMAND) { int idx = obj.getSelectedIndex(); switch (idx) { case 0: // chooseBandType = 0; display.setCurrent(bandList); break; case 1: // chooseBandType = 1; display.setCurrent(bandList); break; case 2: // chooseBandType = 2; display.setCurrent(bandList); break; case 3: display.setCurrent(setMenu); break; case 4: example.About.showAbout(display); break; } } else if (c == BACK_CMD) { display.setCurrent(bandList); } } else if (obj == bandList) { if (c == List.SELECT_COMMAND || c == SHOW_CMD) { int idx = obj.getSelectedIndex(); String bandName = band.getName(idx); ticketList.setTitle(bandName); reconstructList(ticketList, band.getTicketList(bandName)); display.setCurrent(ticketList); } else if (c == ADD_CMD) { display.setCurrent(addBand); } else if (c == RMV_CMD) { display.setCurrent(rmBand); } else if (c == SETTING_CMD) { display.setCurrent(setMenu); } else if (c == EXIT_CMD) { notifyDestroyed(); } } else if (obj == ticketList) { int idx = obj.getSelectedIndex(); _bandIndex = idx; String bandName = ticketList.getTitle(); _bandName = bandName; if (c == List.SELECT_COMMAND || c == SHOW_INFO_CMD) { deleteFormItem(ticketForm); ticketForm.setTitle(bandName); band.getTicketData(ticketForm, bandName, idx); display.setCurrent(ticketForm); } else if (c == MAKE_BID_CMD) { login.setBandAttributes(ticketList.getTitle(), _bandIndex); login.id.setString(null); login.pd.setString(null); display.setCurrent(login); } else if (c == SET_ALERT_CMD) { display.setCurrent(enterForm); } else if (c == BACK_CMD) { display.setCurrent(bandList); } } else if (obj == setMenu) { if (c == List.SELECT_COMMAND) { int idx = obj.getSelectedIndex(); switch (idx) { case 0: display.setCurrent(setTicker); break; case 1: display.setCurrent(setMenu2); break; } } else if (c == BACK_CMD) { display.setCurrent(bandList); } } } else if (s instanceof Form) { Form obj = (Form) s; if (obj == ticketForm) { if (c == BACK_CMD) { display.setCurrent(ticketList); } else if (c == BAND_CMD) { display.setCurrent(bandList); } else if (c == MAKE_BID_CMD) { login.setBandAttributes(ticketList.getTitle(), _bandIndex); login.id.setString(null); login.pd.setString(null); display.setCurrent(login); } else if (c == SET_ALERT_CMD) { display.setCurrent(enterForm); } } else if (obj == bidForm) { if (c == BACK_CMD) { login.setBandAttributes(ticketList.getTitle(), _bandIndex); display.setCurrent(login); } else if (c == NEXT_CMD) { String bidAmt = bidText.getString(); // 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("# "+login.ticketID, "")); login.confirm.append(new StringItem(login.bandName, "")); login.confirm.append(new StringItem("Bid Amount:", "$"+bidAmt)); display.setCurrent(login.confirm); } } } else if (obj == enterForm) { if (c == BACK_CMD) { enterText.setString(null); display.setCurrent(bandList); } else if (c == SAVE_CMD) { updateAlert.set(ticketList.getTitle(), enterText.getString()); display.setCurrent(alertMsg, bandList); } } } else if (s instanceof TextBox) { TextBox obj = (TextBox) s; if (obj == addBand) { if (c == BACK_CMD) { // display.setCurrent(setMenu); display.setCurrent(bandList); } else if (c == SAVE_CMD) { updateBandList(addBand.getString()); display.setCurrent(savedMsg, bandList); } } } } 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"); Alert loginAlert = new Alert("Alert", "Your must enter your ID and password" + " before you can proceed.", null, null); Login() { super(null); append(new StringItem("Please Enter Auction ID:", "")); append(id); append(new StringItem("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); deleteFormItem(notice); notice.append(new StringItem("Your bid has been received:", "")); notice.append(new StringItem("Confirm #:", "12-B455-31")); notice.addCommand(BACK_CMD); notice.addCommand(BAND_CMD); notice.setCommandListener(this); loginAlert.setTimeout(Alert.FOREVER); } 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; } public void commandAction(Command c, Displayable s) { if (s instanceof Form) { Form obj = (Form) s; if (obj == this) { if (c == BACK_CMD) { display.setCurrent(ticketList); } else if (c == NEXT_CMD) { if ((id.getString().length() == 0) || (pd.getString().length() == 0)) { display.setCurrent(loginAlert); } else { login.setID(_bandName, band.getTicketID(_bandName, _bandIndex)); bidForm.setTitle(null); bidText.setString(null); band.getTicketBidTitle(bidForm, _bandName, _bandIndex); bidForm.append(bidText); display.setCurrent(bidForm); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -