📄 auctiondemo.java
字号:
/* * "@(#)AuctionDemo.java 1.33 01/06/22" * 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 AuctionDemo extends MIDlet implements CommandListener { Display display; public AuctionDemo() { display = Display.getDisplay(this); } public void destroyApp(boolean unconditional) { } public void pauseApp() { } Band band = new Band(); static final Command BYE_CMD = new Command("Exit", Command.STOP, 0); static final Command BACK_CMD = new Command("Back", Command.SCREEN, 1); static final Command NEXT_CMD = new Command("Next", Command.SCREEN, 2); static final Command MENU_CMD = new Command("Main", Command.SCREEN, 2); static final Command SAVE_CMD = new Command("Save", Command.SCREEN, 2); static final Command SUBMIT_CMD = new Command("Submit", Command.SCREEN, 2); static final Command ABOUY_CMD = new Command("About", Command.HELP, 30); Ticker ticker; Alert notImpl, savedMsg, alertMsg; Canvas welcome; List mainMenu, cateMenu, aucMenu, bandList, ticketList, setMenu; Form ticketForm, enterForm, bidForm, submitMsg; TextField enterText, bidText; TextBox addBand; Login login = new Login(); SetDate date = new SetDate(); SetTicker setTicker = new SetTicker(); Update updateInt = new Update(); UpdateAlert updateAlert = new UpdateAlert(); Gauge submitGauge; RmBand rmBand = new RmBand(); Timer TimerService; 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); // submitMsg = new Alert(null); // submitMsg.append("Submitting bid..."); submitGauge = new Gauge("", false, 100, 0); submitMsg = new Form("Submitting bid..."); submitMsg.append(submitGauge); ticker = new Ticker(""); ticker.setString(band.toTickerString(null)); welcome = new Canvas() { Image img = Image.createImage(dukeData, 0, dukeData.length); protected void paint(Graphics g) { int x = (getWidth() - img.getWidth()) / 2; int y = (getHeight() - img.getHeight()) / 2; g.drawImage(img, x, y, Graphics.TOP | Graphics.LEFT); } }; welcome.addCommand(MENU_CMD); welcome.addCommand(BYE_CMD); welcome.setCommandListener(this); display.setCurrent(welcome); mainMenu = new List("Main", Choice.IMPLICIT); mainMenu.append("Address List", null); mainMenu.append("Options", null); mainMenu.append("News", null); mainMenu.append("Auction", null); mainMenu.append("Traffic", null); mainMenu.append("Banking", null); mainMenu.append("Games", null); mainMenu.addCommand(BACK_CMD); mainMenu.setCommandListener(this); cateMenu = new List("Categories", Choice.IMPLICIT); cateMenu.append("Antiques", null); cateMenu.append("Books", null); cateMenu.append("Clothing", null); cateMenu.append("Computers", null); cateMenu.append("Jewelry", null); cateMenu.append("Pet Supplies", null); cateMenu.append("Stamps", null); cateMenu.append("Tickets", null); cateMenu.append("Toys", null); cateMenu.addCommand(BACK_CMD); cateMenu.setCommandListener(this); 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); bandList = new List("Choose Band", Choice.IMPLICIT); bandList.addCommand(BACK_CMD); bandList.setCommandListener(this); bandList.setTicker(ticker); String[] list = band.getList(); for (int i = 0; i < list.length; i++) { bandList.append(list[i], null); } ticketList = new List("dummy", Choice.IMPLICIT); ticketList.addCommand(BACK_CMD); ticketList.setCommandListener(this); ticketForm = new Form("dummy"); ticketForm.append("dummy"); ticketForm.addCommand(BACK_CMD); ticketForm.addCommand(MENU_CMD); ticketForm.setCommandListener(this); enterText = new TextField("", "", 10, TextField.NUMERIC); enterForm = new Form("Alert"); enterForm.append("Tell me when bid reaches:"); enterForm.append(enterText); enterForm.addCommand(BACK_CMD); enterForm.addCommand(SAVE_CMD); enterForm.setCommandListener(this); bidText = new TextField("", "", 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("Set Date & Time", null); setMenu.append("Ticker Tape", null); setMenu.append("Updates", null); setMenu.append("Add Bands", null); setMenu.append("Remove Bands", null); setMenu.addCommand(BACK_CMD); setMenu.setCommandListener(this); setMenu.setTicker(ticker); addBand = new TextBox("Add Bands,\nBands:", "", 100, TextField.ANY); addBand.addCommand(BACK_CMD); addBand.addCommand(SAVE_CMD); addBand.setCommandListener(this); } int chooseBandType = 0; public void commandAction(Command c, Displayable s) { if (s instanceof Canvas) { Canvas obj = (Canvas) s; if (obj == welcome) { if (c == MENU_CMD) { display.setCurrent(mainMenu); } else if (c == BYE_CMD) { notifyDestroyed(); } } } else if (s instanceof List) { List obj = (List) s; if (obj == mainMenu) { if (c == List.SELECT_COMMAND) { int idx = obj.getSelectedIndex(); if (idx == 3) { display.setCurrent(cateMenu); } else { display.setCurrent(notImpl); } } else if (c == BACK_CMD) { display.setCurrent(welcome); } } else if (obj == cateMenu) { if (c == List.SELECT_COMMAND) { int idx = obj.getSelectedIndex(); if (idx == 7) { display.setCurrent(aucMenu); } else { display.setCurrent(notImpl); } } else if (c == BACK_CMD) { display.setCurrent(mainMenu); } } else 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(cateMenu); } } else if (obj == bandList) { if (c == List.SELECT_COMMAND) { int idx = obj.getSelectedIndex(); String bandName = band.getName(idx); ticketList.setTitle(bandName); reconstructList(ticketList, band.getTicketList(bandName)); display.setCurrent(ticketList); } else if (c == BACK_CMD) { display.setCurrent(aucMenu); } } else if (obj == ticketList) { if (c == List.SELECT_COMMAND) { int idx = obj.getSelectedIndex(); String bandName = ticketList.getTitle(); if (chooseBandType == 0) { ticketForm.setTitle(bandName); ticketForm.delete(0); ticketForm.append(band.getTicketData(bandName, idx)); display.setCurrent(ticketForm); } else if (chooseBandType == 1) { login.setID(bandName, band.getTicketID(bandName, idx)); bidForm.setTitle(null); StringItem item = new StringItem("", band.getTicketBidTitle(bandName, idx)); bidForm.set(0, item); display.setCurrent(bidForm); } else if (chooseBandType == 2) { display.setCurrent(enterForm); } } else if (c == BACK_CMD) { display.setCurrent(bandList);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -