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

📄 manager.java

📁 有关j2me的很好的例子可以研究一下
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
     * @return icon image     */    private static Image getSingleSuiteIcon() {        if (singleSuiteIcon != null) {            return singleSuiteIcon;        }        singleSuiteIcon = getIconFromStorage(                        (colorDisplay ? "_single8.png" : "_single2.png"));        return singleSuiteIcon;    }    /**     * Gets an icon from storage.     *     * @param iconName name without a path     * @return icon image     */    private static Image getIconFromStorage(String iconName) {        String iconFilename;        RandomAccessStream stream;        byte[] rawPng;        iconFilename = File.getStorageRoot() + iconName;        stream = new RandomAccessStream(classSecurityDomain);        try {             stream.connect(iconFilename, Connector.READ);            rawPng = new byte[stream.getSizeOf()];            stream.readBytes(rawPng, 0, rawPng.length);            stream.disconnect();            return Image.createImage(rawPng, 0, rawPng.length);        } catch (java.io.IOException noImage) {        }        return null;    }    /**     * Create and initialize a new Manager MIDlet.     * The Display is retreived and the list of MIDlets read     * from the descriptor file.     */    public Manager() {        installer = Installer.getInstaller(classSecurityDomain);        display = Display.getDisplay(this);        colorDisplay = display.isColor();        mcount = 0;        minfo = new MIDletSuiteInfo[20];        readMIDletSuiteInfo();        restoreSettings();    }    /**     * Start puts up a List of the MIDlets found in the descriptor file.     */    public void startApp() {        setupList();        if (mcount > 0) {            mlist.addCommand(launchCmd);            mlist.addCommand(infoCmd);            mlist.addCommand(removeCmd);            mlist.addCommand(updateCmd);        }        mlist.addCommand(installCmd);        mlist.addCommand(settingsCmd);        mlist.addCommand(aboutCmd);        mlist.setCommandListener(this); // Listen for the selection        if (first) {            first = false;            Alert splash = new Alert(null);            if (display.numColors() > 2) {                splash.setImage(getIconFromStorage((colorDisplay ?                    "_logo_8.png" : "_logo_2.png")));            }            splash.setString(SMALL_COPYRIGHT);            display.setCurrent(splash, mlist);        } else {            display.setCurrent(mlist);        }    }    /**     * Pause; there are no resources that need to be released.     */    public void pauseApp() {    }    /**     * Destroy cleans up.     *     * @param unconditional is ignored; this object always     * destroys itself when requested.     */    public void destroyApp(boolean unconditional) {        /*         * The backgroundInstaller could be waiting for an update of the          * install state.         */        cancelBackgroundInstall();    }    /**     * Respond to a command issued on any Screen.     * The commands on list is Select and About.     * Select triggers the creation of the MIDlet of the same name.     * About puts up the copyright notice.     *     * @param c command activiated by the user     * @param s the Displayable the command was on.     */    public void commandAction(Command c, Displayable s) {        if ((s == mlist && c == List.SELECT_COMMAND) || (c == launchCmd)) {            launchSuite(minfo[mlist.getSelectedIndex()]);        } else if (c == infoCmd) {            displaySuiteInfo(minfo[mlist.getSelectedIndex()]);        } else if (c == removeCmd) {            // save the selected suite for the removeOk command            selectedSuite = mlist.getSelectedIndex();            confirmRemove(minfo[selectedSuite]);        } else if (c == removeOkCmd) {            removeSuite(minfo[selectedSuite]);        } else if (c == updateCmd) {            updateSuite(minfo[mlist.getSelectedIndex()]);        } else if (s == mlist && c == installCmd) {            // user wants a list of suites to install            getUrl();        } else if (c == selectSuiteCmd) {            // user wants to select a suite to install            selectSuiteToInstall(urlTextBox.getString());        } else if (s == installListBox &&                  (c == List.SELECT_COMMAND || c == installCmd)) {            // the user has selected a suite            installSuite(installListBox.getSelectedIndex());        } else if (c == nextCmd) {            // the user has entered a username and password            resumeInstallWithPassword();        } else if (c == okCmd) {            resumeInstallAfterWarning();        } else if (c == settingsCmd) {            getSettings();        } else if (c == saveSettingsCmd) {            saveSettings();        } else if (c == aboutCmd) {            Alert a = new Alert(Resource.getString("About Wireless Profile"));            a.setString(COPYRIGHT);            display.setCurrent(a, mlist);        } else if (c == stopCmd) {            if (installer != null) {                /*                 * backgroundInstaller may be displaying                 * the "Finishing" message                 */                if (installer.stopInstalling()) {                    displayCancelledMessage(cancelledMessage);                }            } else {                display.setCurrent(mlist);            }        } else if (c == cancelInstallCmd) {            cancelBackgroundInstall();        } else if (c == backCmd || c == cancelCmd) {            // goto back to the main list of suites            display.setCurrent(mlist);        }    }    /**     * Lauches a suite.     *     * @param suiteInfo information for suite to launch     */    private void launchSuite(MIDletSuiteInfo suiteInfo) {        try {            // Create an instance of the MIDlet class            // All other initialization happens in MIDlet constructor            if (installer.execute(suiteInfo.storageName,                                  suiteInfo.displayName)) {                /*                 * Give the new MIDlet the screen by destroy our self,                 * because we are running in a limited VM and must                 * restart the VM let the select suite run.                 */                destroyApp(false);                notifyDestroyed();            } else {                // Give the new MIDlet the screen by pausing and                // asking to be resumed.                notifyPaused();                resumeRequest();            }        } catch (Exception ex) {            StringBuffer sb = new StringBuffer()                .append(suiteInfo.displayName)                .append("\n")                .append(Resource.getString("Error"))                .append(ex.toString());            Alert a = new Alert(Resource.getString("Cannot start: "),                                 sb.toString(), null, AlertType.ERROR);            a.setTimeout(Alert.FOREVER);            display.setCurrent(a, mlist);        }    }    /**     * Display the information for a suite.     *     * @param suiteInfo information for suite to display     */    private void displaySuiteInfo(MIDletSuiteInfo suiteInfo) {        Form infoForm;        String name;        Image icon;        try {            infoForm = new Form(null);            if (suiteInfo.singleMidlet) {                name = suiteInfo.displayName;                icon = suiteInfo.icon;            } else {                name = suiteInfo.midletSuite.getProperty(                          Installer.SUITE_NAME_PROP);                icon = getSuiteIcon();            }            infoForm.setTitle(Resource.getString("Info") + ": " + name);            infoForm.append(                new ImageItem(null, icon, ImageItem.LAYOUT_NEWLINE_BEFORE +                              ImageItem.LAYOUT_CENTER +                              ImageItem.LAYOUT_NEWLINE_AFTER, null));            // round up the size to a Kilobyte            infoForm.append(Resource.getString("Size"));            infoForm.append(": ");            infoForm.append(                Integer.toString((suiteInfo.midletSuite.getStorageUsed() +                    1023) / 1024));            infoForm.append(" K");            infoForm.append("\n");            infoForm.append(Resource.getString("Version"));            infoForm.append(": ");            infoForm.append(                suiteInfo.midletSuite.getProperty(Installer.VERSION_PROP));            infoForm.append("\n");            infoForm.append(Resource.getString("Vendor"));            infoForm.append(": ");            infoForm.append(                suiteInfo.midletSuite.getProperty(Installer.VENDOR_PROP));            infoForm.append("\n");            if (!suiteInfo.singleMidlet) {                infoForm.append(Resource.getString("Contents"));                infoForm.append(": ");                infoForm.append("\n");                appendMIDletsToForm(suiteInfo.midletSuite, infoForm);            }            infoForm.append(Resource.getString("Website"));            infoForm.append(": ");            infoForm.append(suiteInfo.midletSuite.getJadUrl());        } catch (Exception ex) {            StringBuffer sb = new StringBuffer()                .append(suiteInfo.displayName)                .append("\n")                .append(Resource.getString("Exception"))                .append(": ")                .append(ex.toString());            Alert a = new Alert(Resource.getString("Cannot access: "),                                 sb.toString(), null, AlertType.ERROR);            a.setTimeout(Alert.FOREVER);            display.setCurrent(a, mlist);            return;        }        infoForm.addCommand(backCmd);        infoForm.setCommandListener(this);        display.setCurrent(infoForm);    }    /**     * Confirm the removal of a suite.     *     * @param suiteInfo information for suite to remove     */    private void confirmRemove(MIDletSuiteInfo suiteInfo) {        Form confirmForm;        String extraConfirmMsg;        try {            confirmForm = new Form(null);            confirmForm.setTitle(Resource.getString("Confirmation"));            confirmForm.append(Resource.getString(                "Are you sure you want to remove "));            confirmForm.append("\"");            if (suiteInfo.singleMidlet) {                confirmForm.append(suiteInfo.displayName);            } else {                confirmForm.append(suiteInfo.midletSuite.getProperty(                                   Installer.SUITE_NAME_PROP));            }            confirmForm.append("\"?");            confirmForm.append("\n");            confirmForm.append("\n");            extraConfirmMsg =                 suiteInfo.midletSuite.getProperty("MIDlet-delete-confirm");            if (extraConfirmMsg != null) {                confirmForm.append(extraConfirmMsg);                confirmForm.append("\n");                confirmForm.append("\n");            }            if (!suiteInfo.singleMidlet) {                confirmForm.append(Resource.getString("This suite contains"));                confirmForm.append(": ");                confirmForm.append("\n");                appendMIDletsToForm(suiteInfo.midletSuite, confirmForm);                confirmForm.append("\n");            }            confirmForm.append(Resource.getString(                "Removing will erase all data and cannot be undone."));        } catch (Exception ex) {            StringBuffer sb = new StringBuffer()                .append(suiteInfo.displayName)                .append("\n")                .append(Resource.getString("Exception"))                .append(": ")                .append(ex.toString());            Alert a = new Alert(Resource.getString("Cannot access: "),                                 sb.toString(), null, AlertType.ERROR);            a.setTimeout(Alert.FOREVER);            display.setCurrent(a, mlist);            return;        }        confirmForm.addCommand(cancelCmd);        confirmForm.addCommand(removeOkCmd);        confirmForm.setCommandListener(this);        display.setCurrent(confirmForm);    }    /**     * Remove a suite.     *     * @param suiteInfo information for suite to remove     */    private void removeSuite(MIDletSuiteInfo suiteInfo) {        installer.remove(suiteInfo.storageName);        destroyApp(false);        notifyDestroyed();    }    /**     * Update a suite.     *     * @param suiteInfo information for suite to update     */    private void updateSuite(MIDletSuiteInfo suiteInfo) {        String name;        if (suiteInfo.singleMidlet) {            name = suiteInfo.displayName;        } else {            name =                 suiteInfo.midletSuite.getProperty(Installer.SUITE_NAME_PROP);        }        cancelledMessage = Resource.getString("Update cancelled.");        finishingMessage = Resource.getString("Finishing update.");        installSuiteCommon("Updating", name,            suiteInfo.midletSuite.getJadUrl(),            name + Resource.getString(" was successfully updated"),            true);

⌨️ 快捷键说明

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