📄 newticketauction.java
字号:
/* * @(#)NewTicketAuction.java 1.2 03/01/22 * * Copyright (c) 1999-2003 Sun Microsystems, Inc. All rights reserved. * PROPRIETARY/CONFIDENTIAL * Use is subject to license terms */package example.auction;import java.util.*;import javax.microedition.midlet.*;import javax.microedition.lcdui.*;import javax.microedition.lcdui.List;public class NewTicketAuction extends MIDlet implements CommandListener { Display display; /** user interface alert component. */ Alert splashScreenAlert; // Wait for 2sec static final int DefaultTimeout = 2000; Image splashScreen; boolean imageLoaded; 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.ITEM, 2); static final Command AUCTION_CMD = new Command("Auction", Command.ITEM, 2); static final Command CANCEL_CMD = new Command("Cancel", Command.CANCEL, 1); static final Command STOP_CMD = new Command("Stop", Command.STOP, 1); List mainMenu, cateMenu, ticketList; // bandList, ticketList; Ticker ticker; Alert notImpl, savedMsg, alertMsg; Form band_ticket_Form, ticketForm, enterForm, bidForm, submitMsg; TextField enterText; ChoiceGroup bandCg, auctionCg; StringItem auctionName; UpdateAlert updateAlert = new UpdateAlert(); Gauge submitGauge; Timer TimerService; SetMenuForm setMenu2 = new SetMenuForm(); // Band Name and Index number of the selected band in // Band Screen band_ticket_Form String _bandName; int _bandIndex = 0; static final Command EXIT_CMD = new Command("Exit", Command.EXIT, 1); static final Command ABOUT_CMD = new Command("About Tickets", Command.HELP, 1); // commands for Band Screen bandForm static final Command SHOW_CMD = new Command("Show Auctions", Command.SCREEN, 1); static final Command ADD_CMD = new Command("Add Bands", Command.SCREEN, 1); static final Command RMV_CMD = new Command("Remove Bands", Command.SCREEN, 2); static final Command SETTING_CMD = new Command("Settings", Command.SCREEN, 3); // commands for Auction Screen ticketList static final Command SHOW_INFO_CMD = new Command("Show More Info", Command.ITEM, 1); static final Command MAKE_BID_CMD = new Command("Make a Bid", Command.ITEM, 2); static final Command SET_ALERT_CMD = new Command("Set an Alert", Command.ITEM, 3); // command for Bid screen ticketForm static final Command BAND_CMD = new Command("Bands", Command.SCREEN, 1); private boolean firstTime; public NewTicketAuction() { display = Display.getDisplay(this); 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); submitMsg.addCommand(STOP_CMD); submitMsg.setCommandListener(this); ticker = new Ticker(""); ticker.setString(band.toTickerString(null)); band_ticket_Form = new Form("Welcome To Tickets"); band_ticket_Form.addCommand(SHOW_INFO_CMD); band_ticket_Form.addCommand(MAKE_BID_CMD); band_ticket_Form.addCommand(SET_ALERT_CMD); band_ticket_Form.addCommand(ADD_CMD); band_ticket_Form.addCommand(RMV_CMD); band_ticket_Form.addCommand(SETTING_CMD); band_ticket_Form.addCommand(ABOUT_CMD); band_ticket_Form.addCommand(EXIT_CMD); band_ticket_Form.setCommandListener(this); band_ticket_Form.setTicker(ticker); // bandCg = new ChoiceGroup("Choose a Band", Choice.EXCLUSIVE); bandCg = new ChoiceGroup("Choose a Band", Choice.POPUP); band_ticket_Form.append(bandCg); String[] list = band.getList(); for (int i = 0; i < list.length; i++) { bandCg.append(list[i], null); } String bandName = band.getName(bandCg.getSelectedIndex()); auctionCg = new ChoiceGroup(bandName + " Auctions:", Choice.EXCLUSIVE); auctionCg.setLayout(Item.LAYOUT_EXPAND); band_ticket_Form.append(auctionCg); reconstructList(auctionCg, band.getTicketList(bandName)); band_ticket_Form.setItemStateListener( new ItemStateListener() { public void itemStateChanged(Item item) { if (item instanceof ChoiceGroup) { ChoiceGroup obj = (ChoiceGroup) item; if (obj == bandCg) { int idx = obj.getSelectedIndex(); String bandName = band.getName(idx); auctionCg.setLabel(bandName + " Auctions:"); reconstructList(auctionCg, band.getTicketList(bandName)); } } } } ); try { splashScreen = Image.createImage("/example/auction/images/splashScreen.png"); imageLoaded = true; } catch (java.io.IOException ex) { } splashScreenAlert = new Alert("Welcome to Ticket Auction", "", splashScreen, AlertType.INFO); splashScreenAlert.setTimeout(DefaultTimeout); 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.DECIMAL); enterForm = new Form("Set an Alert"); enterForm.append(enterText); enterForm.addCommand(BACK_CMD); enterForm.addCommand(SAVE_CMD); enterForm.setCommandListener(this); addBand = new TextBox("Add Bands, Bands:", "", 100, TextField.ANY); addBand.addCommand(BACK_CMD); addBand.addCommand(SAVE_CMD); addBand.setCommandListener(this); firstTime = true; } public void startApp() { if (firstTime) { display.setCurrent(splashScreenAlert, band_ticket_Form); firstTime = false; } } public void destroyApp(boolean unconditional) { } public void pauseApp() { } public void commandAction(Command c, Displayable s) { if (s instanceof Form) { Form obj = (Form) s; if (obj == band_ticket_Form) { int idx = auctionCg.getSelectedIndex(); _bandIndex = idx; int bandIdx = bandCg.getSelectedIndex(); String bandName = ""; if (bandIdx >= 0) { bandName = band.getName(bandIdx); } _bandName = bandName; if (c == SHOW_INFO_CMD) { deleteFormItem(ticketForm); ticketForm.setTitle(band.getTicketDataTitle(bandName, idx)); band.getTicketData(ticketForm, bandName, idx); display.setCurrent(ticketForm); } else if (c == MAKE_BID_CMD) { login.setBandAttributes(bandName, _bandIndex); deleteFormItem(login); login.append(login.id); login.id.setLabel("Enter Your ID:"); login.append(login.pd); login.pd.setLabel("Enter PIN:"); login.append(login.curBid); login.append(login.incBid); login.append(login.minBid); login.append(login.bidText); login.id.setString(null); login.pd.setString(null); login.bidText.setString(null); band.getTicketBidTitle(login, _bandName, _bandIndex); display.setCurrent(login); } else if (c == SET_ALERT_CMD) { display.setCurrent(enterForm); } else if (c == ADD_CMD) { display.setCurrent(addBand); } else if (c == RMV_CMD) { display.setCurrent(rmBand); } else if (c == SETTING_CMD) { display.setCurrent(setMenu2); } else if (c == ABOUT_CMD) { example.About.showAbout(display); } else if (c == EXIT_CMD) { notifyDestroyed(); } } else if (obj == ticketForm) { if (c == BACK_CMD) { display.setCurrent(band_ticket_Form); } else if (c == BAND_CMD) { display.setCurrent(band_ticket_Form); } else if (c == MAKE_BID_CMD) { login.setBandAttributes(band.getName( bandCg.getSelectedIndex()), _bandIndex); deleteFormItem(login); login.append(login.id); login.id.setLabel("Enter Auction ID:"); login.append(login.pd); login.pd.setLabel("Enter PIN:"); login.append(login.curBid); login.append(login.incBid); login.append(login.minBid); login.append(login.bidText); login.id.setString(null); login.pd.setString(null); login.bidText.setString(null); band.getTicketBidTitle(login, _bandName, _bandIndex); display.setCurrent(login); } else if (c == SET_ALERT_CMD) { deleteFormItem(enterForm); int selectedBand = bandCg.getSelectedIndex(); String ticketID = band.getTicketID(band.getName(selectedBand), login._bandIndex); enterForm.append(new StringItem("Auction:", band.getName(selectedBand)+ " " + ticketID)); String curBid = band.getCurrentBid(band.getName(selectedBand), login._bandIndex); enterForm.append(new StringItem("Current Bid:", "$"+ curBid)); enterForm.append(enterText); display.setCurrent(enterForm); } } else if (obj == enterForm) { if (c == BACK_CMD) { enterText.setString(null); display.setCurrent(band_ticket_Form); } else if (c == SAVE_CMD) { updateAlert.set(band.getName(bandCg.getSelectedIndex()), enterText.getString()); display.setCurrent(alertMsg, band_ticket_Form); } } else if (obj == submitMsg) { if (c == STOP_CMD) { TimerService.cancel(); display.setCurrent(login.confirm); } } } else if (s instanceof TextBox) { TextBox obj = (TextBox) s; if (obj == addBand) { if (c == BACK_CMD) { // display.setCurrent(setMenu); display.setCurrent(band_ticket_Form); } else if (c == SAVE_CMD) { updateBandList(addBand.getString()); display.setCurrent(savedMsg, band_ticket_Form); } } } } class Login extends Form implements CommandListener { TextField id = new TextField("", "", 10, TextField.ANY); TextField pd = new TextField("", "", 10, (TextField.NUMERIC|TextField.PASSWORD)); TextField bidText = new TextField("Enter Bid:", "", 10, TextField.DECIMAL); StringItem submitButton = new StringItem("", "Submit", Item.BUTTON); StringItem auctionHyperlink = new StringItem("Auction:", "", Item.HYPERLINK); StringItem curBid = new StringItem("Current Bid:", ""); StringItem incBid = new StringItem("Increment:", ""); StringItem minBid = new StringItem("Minimum Bid:", "");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -