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

📄 alert.java

📁 有关j2me的很好的例子可以研究一下
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @param cmd the Command     *     * @throws IllegalStateException always     */    public void addCommand(Command cmd) {        // SYNC NOTE: no sync necessary        throw new IllegalStateException();    }    /**     * Listeners are not allowed on Alerts, so this method will always throw     * IllegalStateException whenever it is called.     *     * @param l the Listener     * @throws IllegalStateException always     */    public void setCommandListener(CommandListener l) {        // SYNC NOTE: no sync necessary        throw new IllegalStateException();    }    // package private    /**     * Static default Command for "OK"     */    static final Command OK = new Command(Resource.getString("Done"),                                          Command.OK, 0);    /**     * Special CommandListener instance to handle execution of     * the default "OK" Command     */    CommandListener implicitListener = new CommandListener() {        /**         * Handle the execution of the given Command and Displayable.         *         * @param c The Command to execute         * @param s The Displayable from which the Command originated         */        public void commandAction(Command c, Displayable s) {            if (c == OK) {                synchronized (Display.LCDUILock) {                    currentDisplay.clearAlert();                }            }        }    };    /**     * Notify this Alert that is being displayed on the     * given Display and wether it needs to initialize its     * highlight     *     * @param d The Display this Alert will be shown on     */    void showNotifyImpl(Display d) {        super.showNotifyImpl(d);        if (getTimeout() == FOREVER) {            super.addCommandImpl(OK);            super.setCommandListener(implicitListener);        }    }    /**     * Notify this Alert that it will no longer be displayed     * on the given Display     *     * @param d The Display showing this Alert     */    void hideNotifyImpl(Display d) {        super.hideNotifyImpl(d);        super.removeCommandImpl(OK);        super.setCommandListener(null);    }    /**     * Paint the contents of this Alert given the graphics context.     *     * @param g The Graphics object to paint this Alert to     */    void paintContent(Graphics g) {        // clear the screen area for the image & text        g.setColor(Display.ERASE_COLOR);        g.fillRect(g.getClipX(), g.getClipY(),                    g.getClipWidth(), g.getClipHeight());        // offset to vertically center the alert content if the alert height        // is less than the view port height.        int yOffset = (viewPortHeight - alertHeight) / 2;        if (yOffset < 0) {            yOffset = 0;        }        // center and paint the image        if (alertImage != null) {            int xOffset = (viewPortWidth - alertImage.getWidth()) / 2;            if (xOffset < 0) {                xOffset = 0;            }            g.drawImage(alertImage, xOffset, yOffset,                         Graphics.TOP | Graphics.LEFT);        }        // paint the text        if (alertText != null) {            g.translate(0, imgHeight + yOffset);            alertText.paint(g, false, false);        }    }    /**     * Layout the content of this Alert given the width and     * height parameters     *     * @param w The allowed width of this Alert     * @param h The allowed height of this Alert     * @return int  The height this Alert will require given the allowable     *              width     */    int layoutContent(int w, int h) {        // layout the alert text         alertHeight = 0;        if (alertText != null) {            alertHeight += alertText.setWidth(w);        }        // update the alert height        alertHeight += imgHeight;        return alertHeight;    }    //    // Private fields    //    /**     * The default timeout of all alerts     */    private static final int DEFAULT_TIMEOUT = 2000;    /**     * The timeout value of this alert     */    private int time;    /**     * The type of this alert     */    private AlertType type;    /**     * The layout object for the alert text string     */    private StringLayout alertText;    /**     * The image of this alert     */    private Image alertImage;    /**     * The height of this alert image     */    private int imgHeight;    /**     * The height of this alert     */    private int alertHeight;    /**     * Set the image displayed by this Alert     *     * @param img   The new Image to be displayed by this Alert     */    private void setImageImpl(Image img) {        Image currentImg = getImage();        // Don't do anything if nothing is changed.        // The check is only if the image object reference is the same.        // There is no image comparison for 2 different image object        // reference, even though they could be the same image.        if (((currentImg == null) && (img == null)) ||                ((currentImg != null) && (img != null) &&                (currentImg == img))) {            return;        }        if ((img != null) && img.isMutable()) {            throw new IllegalArgumentException();        }        int newImageHeight = (img == null) ? 0 : img.getHeight();        this.alertImage = img;        contentChanged(null, 0, 0, newImageHeight - imgHeight);        // update the alert and image height        alertHeight += (newImageHeight - imgHeight);        imgHeight = newImageHeight;    }    /**     * Set the message displayed by this Alert     *     * @param str   The new message to be displayed by this Alert     */    private void setStringImpl(String str) {        String currentStr = getStringImpl();        // don't do anything if nothing is changed        if (((currentStr == null) && (str == null)) ||            ((currentStr != null) && (str != null) && currentStr.equals(str))) {            return;        }        int deltaHeight = 0;        if (this.alertText == null) {            this.alertText = new StringLayout(str, CONTENT_FONT);            if (initLayoutDone()) {                deltaHeight = this.alertText.setWidth(viewPortWidth);            }        } else {            deltaHeight = alertText.setString(str);        }        // update the alert height        alertHeight += deltaHeight;        contentChanged(null, 0, 0, deltaHeight);    }    /**     * Get the message displayed by this Alert     *     * @return String The message displayed by this Alert     */    private String getStringImpl() {        return (alertText == null ? null : alertText.getString());    }}

⌨️ 快捷键说明

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