NewTicketAuctionpublic class NewTicketAuction extends MIDlet implements CommandListener
Fields Summary |
---|
Display | display | Alert | splashScreenAlertuser interface alert component. | static final int | DefaultTimeout | Image | splashScreen | boolean | imageLoaded | Band | band | Login | login | TextBox | addBand | RmBand | rmBand | static final Command | BACK_CMD | static final Command | SAVE_CMD | static final Command | NEXT_CMD | static final Command | SUBMIT_CMD | static final Command | AUCTION_CMD | static final Command | CANCEL_CMD | static final Command | STOP_CMD | javax.microedition.lcdui.List | mainMenu | javax.microedition.lcdui.List | cateMenu | javax.microedition.lcdui.List | ticketList | Ticker | ticker | Alert | notImpl | Alert | savedMsg | Alert | alertMsg | Form | band_ticket_Form | Form | ticketForm | Form | enterForm | Form | bidForm | Form | submitMsg | TextField | enterText | ChoiceGroup | bandCg | ChoiceGroup | auctionCg | StringItem | auctionName | UpdateAlert | updateAlert | Gauge | submitGauge | Timer | TimerService | SetMenuForm | setMenu2 | String | _bandName | int | _bandIndex | static final Command | EXIT_CMD | static final Command | ABOUT_CMD | static final Command | SHOW_CMD | static final Command | ADD_CMD | static final Command | RMV_CMD | static final Command | SETTING_CMD | static final Command | SHOW_INFO_CMD | static final Command | MAKE_BID_CMD | static final Command | SET_ALERT_CMD | static final Command | BAND_CMD |
Constructors Summary |
---|
public NewTicketAuction()
display = Display.getDisplay(this);
|
Methods Summary |
---|
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);
}
}
}
| void | deleteFormItem(Form f)
int num = f.size();
while (--num >= 0) {
f.delete(num);
}
| public void | destroyApp(boolean unconditional)
| public void | pauseApp()
| void | reconstructBandTicketForm(java.lang.String[] items)
if (items == null || items.length == 0) {
bandCg.deleteAll();
auctionCg.setLabel(null);
auctionCg.deleteAll();
return;
}
reconstructList(bandCg, items);
bandCg.setSelectedIndex(0, true);
String bandName = band.getName(bandCg.getSelectedIndex());
auctionCg.setLabel(bandName + " Auctions:");
reconstructList(auctionCg, band.getTicketList(bandName));
| void | reconstructList(Choice list, java.lang.String[] items)
list.deleteAll();
for (int i = 0; i < items.length; i++) {
list.append(items[i], null);
}
| 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);
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);
display.setCurrent(splashScreenAlert, band_ticket_Form);
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);
| void | updateBandList(java.lang.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));
}
}
reconstructBandTicketForm(band.getList());
rmBand.reset();
|
|