movieselectionui.java

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

JAVA
409
字号
package com.sun.j2me.blueprints.smartticket.client.midp.ui;import javax.microedition.lcdui.*;import javax.microedition.midlet.*;import java.io.IOException;import java.util.Calendar;import com.sun.j2me.blueprints.smartticket.client.midp.model.Preferences;import com.sun.j2me.blueprints.smartticket.shared.midp.model.Theater;import com.sun.j2me.blueprints.smartticket.shared.midp.model.TheaterSchedule;import com.sun.j2me.blueprints.smartticket.shared.midp.model.Movie;public class MovieSelectionUI extends Form implements CommandListener,         ItemStateListener, ItemCommandListener {    private UIController uiController;    private Preferences preferences;    private ChoiceGroup theaterChoiceGroup;    private int theaterChoiceGroupItemNum;    private ChoiceGroup movieChoiceGroup;    private int movieChoiceGroupItemNum;    private ChoiceGroup dayChoiceGroup;    private int dayChoiceGroupItemNum;    private ChoiceGroup timeChoiceGroup;    private int timeChoiceGroupItemNum;    private StringItem selectSeatsItem;    private Command selectSeatsCommand;    private Command viewMovieInfoCommand;    private Command saveTheaterScheduleCommand;    private Theater[] theaters;    private TheaterSchedule.MovieSchedule[] movieSchedules;    private Movie[] movies;    private int[][] showTimes;    private int[] days;    private int[][] times;    public MovieSelectionUI(UIController uiController) {        super(uiController.getString(UIMessageCodes.CHOOSE_MOVIE_TITLE));        this.uiController = uiController;        theaterChoiceGroup = new ChoiceGroup(null, Choice.POPUP);        movieChoiceGroup = new ChoiceGroup(null, Choice.POPUP);        dayChoiceGroup =             new ChoiceGroup(uiController.getString(UIMessageCodes.DAYS),                             Choice.POPUP);        timeChoiceGroup =             new ChoiceGroup(uiController.getString(UIMessageCodes.SHOWTIMES),                             Choice.POPUP);        selectSeatsItem =             new StringItem(null,                            uiController.getString(UIMessageCodes.SELECT_SEATS),                            Item.BUTTON);        selectSeatsItem.setLayout(Item.LAYOUT_CENTER);        setItemStateListener(this);        selectSeatsCommand =             new Command(uiController.getString(UIMessageCodes.SELECT_SEATS),                         Command.SCREEN, 1);        viewMovieInfoCommand =             new Command(uiController.getString(UIMessageCodes.MORE_MOVIE_INFO),                         Command.SCREEN, 3);        saveTheaterScheduleCommand =             new Command(uiController.getString(UIMessageCodes.SAVE_THEATER_SCHEDULE),                         Command.SCREEN, 4);        selectSeatsItem.setItemCommandListener(this);        setCommandListener(this);    }    public void init(Preferences preferences) {        this.preferences = preferences;        deleteAll();    }     public void setTheaters(Theater[] theaters, Theater[] localTheaters,                             long[] localTheatersExpirationDates,                             boolean online) {        append(new StringItem(uiController.getString(UIMessageCodes.MOVIE_SCHEDULE_FOR),                               null));        theaterChoiceGroupItemNum = append(theaterChoiceGroup);        theaterChoiceGroup.deleteAll();        theaterChoiceGroup.append(uiController.getString(UIMessageCodes.CHOOSE_A_THEATER),                                   null);        long currentTimeMillis = System.currentTimeMillis();        Image image = null;        for (int i = 0; i != theaters.length; i++) {            image =                 uiController.getImage(UIController.ICON_IDX_SCHEDULE_REMOTE);            for (int j = 0; j < localTheaters.length; j++) {                if (theaters[i].getPrimaryKey().equals(localTheaters[j].getPrimaryKey())) {                    if (currentTimeMillis > localTheatersExpirationDates[j]) {                        image =                             uiController.getImage(UIController.ICON_IDX_SCHEDULE_EXPIRED);                    } else {                        image =                             uiController.getImage(UIController.ICON_IDX_SCHEDULE_LOCAL);                    }                     break;                }             }             theaterChoiceGroup.append(theaters[i].getName() + ' ' + '['                                       + theaters[i].getZipCode() + ']',                                       image);        }         if (online) {            theaterChoiceGroup.append(uiController.getString(UIMessageCodes.TRY_ANOTHER_ZIP_CODE),                                       null);        } else {            theaterChoiceGroup.append(uiController.getString(UIMessageCodes.MORE_THEATERS_ONLINE),                                       null);        }         this.theaters = theaters;        removeCommand(viewMovieInfoCommand);        removeCommand(saveTheaterScheduleCommand);        uiController.setCurrentItem(theaterChoiceGroup);    }     public void setMovies(Movie[] movies) {        append(new StringItem(uiController.getString(UIMessageCodes.MOVIES_FOR_THIS_WEEK),                               null));        movieChoiceGroupItemNum = append(movieChoiceGroup);        movieChoiceGroup.deleteAll();        movieChoiceGroup.append(uiController.getString(UIMessageCodes.CHOOSE_A_MOVIE),                                 null);        for (int i = 0; i != movies.length; i++) {            String rating = movies[i].getRating();            Image image = null;            if ("g".equals(rating)) {                image = uiController.getImage(UIController.ICON_IDX_RATING_G);            } else if ("pg".equals(rating)) {                image =                     uiController.getImage(UIController.ICON_IDX_RATING_PG);            } else if ("r".equals(rating)) {                image = uiController.getImage(UIController.ICON_IDX_RATING_R);            }             movieChoiceGroup.append(movies[i].getTitle(), image);        }         this.movies = movies;        removeCommand(viewMovieInfoCommand);        uiController.setCurrentItem(movieChoiceGroup);    }     public void setShowTimes(int[][] showTimes) {        dayChoiceGroupItemNum = append(dayChoiceGroup);        dayChoiceGroup.deleteAll();        dayChoiceGroup.append(uiController.getString(UIMessageCodes.CHOOSE_A_DAY),                               null);        boolean mondayShowingExists = false;        boolean tuesdayShowingExists = false;        boolean wednesdayShowingExists = false;        boolean thursdayShowingExists = false;        boolean fridayShowingExists = false;        boolean saturdayShowingExists = false;        boolean sundayShowingExists = false;        for (int i = 0; i != showTimes.length; i++) {            if (showTimes[i][0] == Calendar.MONDAY) {                mondayShowingExists = true;            } else if (showTimes[i][0] == Calendar.TUESDAY) {                tuesdayShowingExists = true;            } else if (showTimes[i][0] == Calendar.WEDNESDAY) {                wednesdayShowingExists = true;            } else if (showTimes[i][0] == Calendar.THURSDAY) {                thursdayShowingExists = true;            } else if (showTimes[i][0] == Calendar.FRIDAY) {                fridayShowingExists = true;            } else if (showTimes[i][0] == Calendar.SATURDAY) {                saturdayShowingExists = true;            } else if (showTimes[i][0] == Calendar.SUNDAY) {                sundayShowingExists = true;            }         }         days = new int[7];        int numDays = 0;        if (mondayShowingExists) {            dayChoiceGroup.append(uiController.getString(UIMessageCodes.MONDAY),                                   null);            days[numDays++] = Calendar.MONDAY;        } 

⌨️ 快捷键说明

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