⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newticketauction.java

📁 j2me Demos for example
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            if (selected[1]) {            }            // Country            if (selected[2]) {            }            // Alternative            if (selected[3]) {                if (s.length() > 0) {                    s += " ";                }                s += alt_ticker;            }            // Jazz            if (selected[4]) {            }            // Classical            if (selected[5]) {            }            return s;        }        long stringToLong1000(String s) {            if ((s == null) || s.equals("")) {                return 0;            }            try {                int index = s.indexOf('.');                if (index == -1) {                    return (long)1000 * Integer.parseInt(s);                }                long integerPart = 1000 * Integer.parseInt(s.substring(0, index));                String fracString = s.substring(index + 1);                int multBy = 0;                switch (fracString.length()) {                case 0:                    multBy = 0;                    break;                case 1:                    multBy = 100;                    break;                case 2:                    multBy = 10;                    break;                case 3:                    multBy = 1;                    break;                }                long fractionalPart = multBy * Integer.parseInt(fracString);                return integerPart + fractionalPart;            } catch (NumberFormatException nfe) {                return 0;            }        }        String long1000ToString(long l) {            if (l == 0) {                return "0";            }            String s = String.valueOf(l);            if (s.length() < 4) {                return "0";            }            String newStr = s.substring(0, s.length() - 3) + "." + s.substring(s.length() - 2);            return newStr;        }        class TicketItem {            // Ticket info            String name; // item name i.e. band name            String seat; // seat number            String sect; // seat section            String date; // concert date            String place; // concert place            String state; // place's state            // Bid info            String id; // id i.e. item number            String numItem; // quantity            String begBid; // beginning bid price            String curBid; // current bid price            String incBid; // bid increment            String numBids; // # of bids            String endsAt; // Bid close time            TicketItem(String name, String seat, String sect, String date, String place,                String state, String id, String numItem, String begBid, String curBid,                String incBid, String numBids, String endsAt) {                this.name = name;                this.seat = seat;                this.sect = sect;                this.date = date;                this.place = place;                this.state = state;                this.id = id;                this.numItem = numItem;                this.begBid = begBid;                this.curBid = curBid;                this.incBid = incBid;                this.numBids = numBids;                this.endsAt = endsAt;            }            TicketItem(String name) {                this(name, "n/a", "n/a", "n/a", "n/a", "n/a", "0", "0", "0", "0", "0", "0", "0");            }        }        class BandListTable {            private Vector vec = new Vector();            BandListTable() {                vec = new Vector();            }            void put(int nth, Object obj) {                Object o = null;                try {                    o = vec.elementAt(nth);                } catch (ArrayIndexOutOfBoundsException e) {                    o = null;                }                if (o == null) {                    vec.addElement(obj);                } else {                    vec.setElementAt(obj, nth);                }            }            Object get(String bandName) {                int num = vec.size();                for (int i = 0; i < num; i++) {                    Object obj = vec.elementAt(i);                    if (obj instanceof Vector) {                        Vector v = (Vector)obj;                        TicketItem item = (TicketItem)v.elementAt(0);                        if (item.name.equals(bandName)) {                            return obj;                        }                    }                }                return null;            }            Object elementAt(int index) {                return vec.elementAt(index);            }            void remove(int i) {                Object o = null;                try {                    o = vec.elementAt(i);                } catch (ArrayIndexOutOfBoundsException e) {                    o = null;                }                if (o != null) {                    vec.removeElementAt(i);                }            }            int size() {                return vec.size();            }        }    } // end  band    class RmBand extends List implements CommandListener {        RmBand() {            super("Remove Bands", Choice.MULTIPLE);            String[] list = band.getList();            for (int i = 0; i < list.length; i++) {                append(list[i], null);            }            addCommand(BACK_CMD);            addCommand(SAVE_CMD);            setCommandListener(this);        }        public void commandAction(Command c, Displayable s) {            if (c == SAVE_CMD) {                // Make the ChoiceGroup invisible before doing                // reconstruction                boolean[] ret = new boolean[size()];                getSelectedFlags(ret);                removeBandList(ret);                // go back to band_ticket_Form after save                display.setCurrent(savedMsg, band_ticket_Form);            } else if (c == BACK_CMD) {                display.setCurrent(band_ticket_Form);            }        }        void reset() {            reconstructList(this, band.getList());        }        void removeBandList(boolean[] t) {            int i = t.length;            while (--i >= 0) {                if (t[i]) {                    band.remove(i);                }            }            reconstructBandTicketForm(band.getList());            reconstructList(this, band.getList());        }    } // end rm band    class UpdateAlert {        String band = "";        String bid = "";        Alert soundAlert;        UpdateAlert() {            soundAlert = new Alert("Alert", "", null, AlertType.ALARM);            soundAlert.setTimeout(Alert.FOREVER);        }        void set(String band, String bid) {            this.band = band;            this.bid = bid;        }        boolean hasDataToUpdate() {            return ((band != null) && (band != "") && (bid != null) && (bid != ""));        }        void show() {            // no-op if band & bid aren't set            if (hasDataToUpdate()) {                String s = new String(band + "\n" + "ticket bids\n" + "have reached\n" + "$" + bid);                soundAlert.setString(s);                display.setCurrent(soundAlert);            }        }    } // end UpdateAlert    class SetMenuForm extends Form implements CommandListener, ItemStateListener {        Timer timerService = new Timer();        ChoiceGroup tickerCg;        ChoiceGroup updatesCg;        Gauge gauge;        DateField dateTimeItem;        int updateChoice;        int volumeValue;        boolean[] musicChoice;        boolean systemCurrentDate = true;        long setTimeMillisDelta;        long curTimeMillisDelta;        SetMenuForm() {            super("Settings");            tickerCg = new ChoiceGroup("Ticker Display", Choice.MULTIPLE);            tickerCg.append("Rock", null);            tickerCg.append("Pop", null);            tickerCg.append("Country", null);            tickerCg.append("Alternative", null);            tickerCg.append("Jazz", null);            tickerCg.append("Classical", null);            musicChoice = new boolean[] { false, false, false, true, false, false };            append(tickerCg);            updatesCg = new ChoiceGroup("Updates", Choice.EXCLUSIVE);            updatesCg.append("Continuous", null);            updatesCg.append("15 minutes", null);            updatesCg.append("30 minutes", null);            updatesCg.append("1 hour", null);            updatesCg.append("3 hours", null);            updateChoice = 0;            append(updatesCg);            /* Set Number */            gauge = new Gauge(null, true, 40, 0);            volumeValue = 0;            append(gauge);            setItemStateListener(this);            setTimeMillisDelta = curTimeMillisDelta = 0;            dateTimeItem =                new DateField("Set Date:", DateField.DATE_TIME) {                        public void showNotify() {                            long millis = System.currentTimeMillis();                            if (curTimeMillisDelta != 0) {                                millis -= curTimeMillisDelta;                            }                            setDate(new java.util.Date(millis));                        }                    };            append(dateTimeItem);            settings(musicChoice, updateChoice, volumeValue, setTimeMillisDelta);            addCommand(BACK_CMD);            addCommand(SAVE_CMD);            setCommandListener(this);        }        public void settings(boolean[] musicChoice, int updateChoice, int volumeValue,            long curTimeMillisDelta) {            tickerCg.setSelectedFlags(musicChoice);            updatesCg.setSelectedIndex(updateChoice, true);            gauge.setValue(volumeValue);            gauge.setLabel("Set Alert Volume: " + volumeValue);            long millis = System.currentTimeMillis();            if (curTimeMillisDelta != 0) {                millis -= curTimeMillisDelta;            }            dateTimeItem.setDate(new java.util.Date(millis));        }        public void commandAction(Command c, Displayable s) {            if (c == SAVE_CMD) {                tickerCg.getSelectedFlags(musicChoice);                String str = band.toTickerString(musicChoice);                if (str != null) {                    ticker.setString(str);                }                updateChoice = updatesCg.getSelectedIndex();                volumeValue = gauge.getValue();                setTimeMillisDelta = curTimeMillisDelta;                if (updateAlert.hasDataToUpdate()) {                    int idx = updatesCg.getSelectedIndex();                    TimerTask timerClient =                        new TimerTask() {                            public final void run() {                                updateAlert.show();                            }                        };                    switch (idx) {                    case 0:                        timerService.schedule(timerClient, 3000);                        break;                    case 1:                        timerService.schedule(timerClient, 3000);                        break;                    case 2:                        timerService.schedule(timerClient, 3000);                        break;                    case 3:                        timerService.schedule(timerClient, 3000);                        break;                    case 4:                        timerService.schedule(timerClient, 3000);                        break;                    }                }                display.setCurrent(savedMsg, band_ticket_Form);            } else if (c == BACK_CMD) {                display.setCurrent(band_ticket_Form);                settings(musicChoice, updateChoice, volumeValue, setTimeMillisDelta);            }        }        public void itemStateChanged(Item item) {            if (item == gauge) {                int currentValue = gauge.getValue();                gauge.setLabel("Set Alert Volume: " + String.valueOf(currentValue));            } else if (item == dateTimeItem) {                curTimeMillisDelta = System.currentTimeMillis() - dateTimeItem.getDate().getTime();            }        }    }}

⌨️ 快捷键说明

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