movieselectionui.java

来自「SUN公司发布的SmartTicket 2.0蓝图」· Java 代码 · 共 409 行 · 第 1/2 页

JAVA
409
字号
        if (tuesdayShowingExists) {            dayChoiceGroup.append(uiController.getString(UIMessageCodes.TUESDAY),                                   null);            days[numDays++] = Calendar.TUESDAY;        }         if (wednesdayShowingExists) {            dayChoiceGroup.append(uiController.getString(UIMessageCodes.WEDNESDAY),                                   null);            days[numDays++] = Calendar.WEDNESDAY;        }         if (thursdayShowingExists) {            dayChoiceGroup.append(uiController.getString(UIMessageCodes.THURSDAY),                                   null);            days[numDays++] = Calendar.THURSDAY;        }         if (fridayShowingExists) {            dayChoiceGroup.append(uiController.getString(UIMessageCodes.FRIDAY),                                   null);            days[numDays++] = Calendar.FRIDAY;        }         if (saturdayShowingExists) {            dayChoiceGroup.append(uiController.getString(UIMessageCodes.SATURDAY),                                   null);            days[numDays++] = Calendar.SATURDAY;        }         if (sundayShowingExists) {            dayChoiceGroup.append(uiController.getString(UIMessageCodes.SUNDAY),                                   null);            days[numDays++] = Calendar.SUNDAY;        }         this.showTimes = showTimes;        int favoriteDay = preferences.getFavoriteDay();        for (int i = 0; i != numDays; i++) {            if (days[i] == favoriteDay) {                dayChoiceGroup.setSelectedIndex(i + 1, true);            }         }         uiController.setCurrentItem(dayChoiceGroup);    }     public void commandAction(Command command, Displayable displayable) {        if (command == saveTheaterScheduleCommand) {            uiController.handleEvent(UIController.EventIds.EVENT_ID_THEATER_SCHEDULE_SAVE_REQUESTED);        } else if (command == viewMovieInfoCommand) {            uiController.handleEvent(UIController.EventIds.EVENT_ID_MOVIE_INFO_REQUESTED);        } else {            uiController.commandAction(command, displayable);        }     }     public void commandAction(Command command, Item item) {        if (command == selectSeatsCommand) {            uiController.handleEvent(UIController.EventIds.EVENT_ID_SEAT_SELECTION_SELECTED);        }     }     public void itemStateChanged(Item item) {        if (item == theaterChoiceGroup) {            deleteAfter(theaterChoiceGroupItemNum);            int selectedIndex = theaterChoiceGroup.getSelectedIndex();            if (selectedIndex == theaterChoiceGroup.size() - 1) {                if (theaterChoiceGroup.getString(selectedIndex).equals("Try another zip code...")) {                    Form form = new Form("Enter Zip Code");                    final TextField textField = new TextField(null, null, 5,                                                               TextField.ANY);                    Command okCommand =                         new Command(uiController.getString(UIMessageCodes.OK),                                     Command.OK, 1);                    Command cancelCommand =                         new Command(uiController.getString(UIMessageCodes.CANCEL),                                     Command.CANCEL, 1);                    form.append(textField);                    form.addCommand(okCommand);                    form.addCommand(cancelCommand);                    form.setCommandListener(new CommandListener() {                        public void commandAction(Command c, Displayable d) {                            uiController.handleEvent(UIController.EventIds.EVENT_ID_THEATERS_IN_ZIP_CODE_REQUESTED,                                                      new Object[] {                                textField.getString()                            });                        }                     });                    uiController.setCurrent(form);                } else {                    uiController.handleEvent(UIController.EventIds.EVENT_ID_THEATERS_ONLINE_REQUESTED,                                              new Object[0]);                }             } else if (selectedIndex > 0) {                Theater selectedTheater = theaters[selectedIndex - 1];                addCommand(saveTheaterScheduleCommand);                removeCommand(viewMovieInfoCommand);                uiController.handleEvent(UIController.EventIds.EVENT_ID_THEATER_SELECTED,                                          new Object[] {                    selectedTheater                });            }         } else if (item == movieChoiceGroup) {            deleteAfter(movieChoiceGroupItemNum);            int selectedIndex = movieChoiceGroup.getSelectedIndex();            if (selectedIndex > 0) {                Movie selectedMovie = movies[selectedIndex - 1];                addCommand(viewMovieInfoCommand);                uiController.handleEvent(UIController.EventIds.EVENT_ID_MOVIE_SELECTED,                                          new Object[] {                    selectedMovie                });            }         } else if (item == dayChoiceGroup) {            deleteAfter(dayChoiceGroupItemNum);            int selectedIndex = dayChoiceGroup.getSelectedIndex();            if (selectedIndex > 0) {                int selectedDay = days[selectedIndex - 1];                timeChoiceGroupItemNum = append(timeChoiceGroup);                timeChoiceGroup.deleteAll();                timeChoiceGroup.append(uiController.getString(UIMessageCodes.SELECT_SHOWTIME),                                        null);                StringBuffer timeStringBuffer = new StringBuffer();                times = new int[showTimes.length][3];                int numTimes = 0;                for (int i = 0; i != showTimes.length; i++) {                    if (selectedDay == showTimes[i][0]) {                        times[numTimes++] = showTimes[i];                        timeStringBuffer.delete(0, timeStringBuffer.length());                        if (showTimes[i][1] < 10) {                            timeStringBuffer.append('0');                        }                         timeStringBuffer.append(showTimes[i][1]);                        if (showTimes[i][2] < 10) {                            timeStringBuffer.append('0');                        }                         timeStringBuffer.append(showTimes[i][2]);                        timeChoiceGroup.append(timeStringBuffer.toString(),                                                uiController.getImage(UIController.ICON_IDX_CLOCK));                    }                 }                 uiController.setCurrentItem(timeChoiceGroup);            }         } else if (item == timeChoiceGroup) {            deleteAfter(timeChoiceGroupItemNum);            int selectedIndex = timeChoiceGroup.getSelectedIndex();            if (selectedIndex > 0) {                int[] selectedShowTime = times[selectedIndex - 1];                uiController.handleEvent(UIController.EventIds.EVENT_ID_SHOW_TIME_SELECTED,                                          new Object[] {                    selectedShowTime                });                append(selectSeatsItem);                selectSeatsItem.setDefaultCommand(selectSeatsCommand);                uiController.setCurrentItem(selectSeatsItem);            }         }     }     public void deleteAfter(int itemNum) {        if (size() > itemNum) {            for (int i = size() - 1; i > itemNum; i--) {                delete(i);            }         }     } }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?