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

📄 display.java

📁 有关j2me的很好的例子可以研究一下
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
     * @exception NullPointerException if alert or nextDisplayable is null     * @exception IllegalArgumentException if nextDisplayable is an Alert     * @see Alert     *     * @see #getCurrent     */    public void setCurrent(Alert alert, Displayable nextDisplayable) {        if ((alert == null) || (nextDisplayable == null)) {            throw new NullPointerException();        }        if (nextDisplayable instanceof Alert) {            throw new IllegalArgumentException();        }        synchronized (LCDUILock) {            setCurrentImpl(alert, nextDisplayable);        }    }    /**     * Set the current Displayable     *     * @param nextDisplayable The next Displayable to display     */    void setCurrentImpl(Displayable nextDisplayable) {        pendingAlert = null;        nextScreen = nextDisplayable;        // If this is the foreground Display, schedule the update        if (hasForeground) {            // If a call to setCurrent() is coming in while in a            // suspended state, notify the event handler to dismiss            // the system screen            if (paintSuspended) {                eventHandler.clearSystemScreen();            }            eventHandler.scheduleTimer(EventHandler.SCREEN, 0);        }    }    /**     * Set the current Displayable to be an Alert, with the given     * next Displayable for after the Alert is dismissed     *     * @param alert The Alert to set to be the current Displayable     * @param nextDisplayable The Displayable to return to after the     *                        Alert is dismissed     */    void setCurrentImpl(Alert alert, Displayable nextDisplayable) {        pendingAlert = alert;        nextScreen   = nextDisplayable;        alertDelay   = alert.getTimeout();        // If this is the foreground Display, schedule the update        if (hasForeground) {            // If a call to setCurrent() is coming in while in a            // suspended state, notify the event handler to dismiss            // the system screen            if (paintSuspended) {                eventHandler.clearSystemScreen();            }            eventHandler.scheduleTimer(EventHandler.SCREEN, 0);        }        // Save flag indicating has a real current Displayable        hascurrent = nextDisplayable != null;        // Notify scheduler while not synchronized on Display        Scheduler.getScheduler().notifyHasCurrent(accessor, hascurrent);    }    /**     * Called by Alert when a modal alert has exited.     */    void clearAlert() {        pendingAlert = null;        eventHandler.scheduleTimer(EventHandler.SCREEN, 0);    }    /**     * play a sound.     * @param t type of alert     * @return true, if sound was played.     */    boolean playAlertSound(AlertType t) {        if (paintSuspended || !hasForeground) {            return false;        } else {            // SYNC NOTE: playAlertSound is a native method, no locking            // necessary            return playAlertSound(t.getType());        }    }    /** horizontal width */    static final int WIDTH;    /** vertical height */    static final int HEIGHT;    /** background color for erasing */    static final int ERASE_COLOR;    /** pixel depth of display. */    static final int DISPLAY_DEPTH;    /** true, if display supports color. */    static final boolean DISPLAY_IS_COLOR;    /** true, if the device has a pointing device. */    static final boolean POINTER_SUPPORTED;    /** true, if motion events are supported. */    static final boolean MOTION_SUPPORTED;    /** true, if repeating events are supported. */    static final boolean REPEAT_SUPPORTED;    /** true, if the display is double buffered. */    static final boolean IS_DOUBLE_BUFFERED;    static {        /* done this way because native access to static fields is hard */        DeviceCaps c = new DeviceCaps();        WIDTH            = c.width;        HEIGHT           = c.height;        ERASE_COLOR       = c.eraseColor;        DISPLAY_DEPTH     = c.displayDepth;        DISPLAY_IS_COLOR   = c.displayIsColor;        POINTER_SUPPORTED = c.pointerSupported;        MOTION_SUPPORTED  = c.motionSupported;        REPEAT_SUPPORTED  = c.repeatSupported;        IS_DOUBLE_BUFFERED = c.isDoubleBuffered;        c = null;    }    /** Standard foreground color */    static final int FG_COLOR   = 0;    /** Standard background highlight color */    static final int BG_H_COLOR = FG_COLOR;    /** Standard foreground highlight color */    static final int FG_H_COLOR = ERASE_COLOR;    /**      *play a sound.     * @param alertType type of alert     * @return true, if sound was played.     */    private native boolean playAlertSound(int alertType);    /** event handler for this Display instance. */    private static EventHandler eventHandler = getEventHandler();    /**  singleton Graphics object */    private static final Graphics screenGraphics = Graphics.getGraphics(null);    /** display accessor helper class */    private DisplayAccessor accessor;    // screen change handling    /** current displayable instance */    private Displayable current;    /** the next screen to be displayed */    private Displayable nextScreen;    /** the alert instance currently pending */    private Displayable pendingAlert;    /** time to wait for the current alert (microseconds) */    private int         alertDelay;    /** true, if last setCurrent was non-null */    private boolean     hascurrent;    // repaint handling    /** paint rectangle upper left x-coordinate */    private int paintRectX1;    /** paint rectangle upper left y-coordinate */    private int paintRectY1;    /** paint rectangle lower-right x-coordinate */    private int paintRectX2;    /** paint rectangle lower-right  y-coordinate */    private int paintRectY2;    /** true, if an update is pending */    private boolean updatePending;    /**     *  get the class that handle I/O event stream for this display.     * @return handle to the event handler for this display     */    private static EventHandler getEventHandler() {        try {            String n = Configuration.getProperty("com.sun.lcdui.eventHandler");            if (n == null) {                if (Configuration.getProperty("microedition.configuration")                    != null) {                    n = "com.sun.midp.lcdui.DefaultEventHandler";                } else {                    n = "com.sun.midp.lcdui.AWTEventHandler";                }            }            Class c = Class.forName(n);            return (EventHandler) c.newInstance();        } catch (Exception e) {            // TO DO: This is an ideal place to add some trace            // output            // java.lang.ClassNotFoundException            // java.lang.InstantiationException            throw new Error(e.getMessage());        }    }    /**     * get the associated MIDlet from the current display.     * @return MIDlet that is associated with the current Display.     */    MIDlet getMIDLet() {        return MIDLetMap.get(accessor);    }    /**     * Request a repaint for the given Displayable.  The rectangle to be     * painted is in x,y,w,h.  If delay is greater than zero, the repaint     * may be deferred until that interval (in milliseconds) has elapsed.     *     * If the given Displayable is not current, the request is ignored.     * This is safe because whenever a Displayable becomes current, it gets     * a full repaint anyway.     * @param d displayable object to be drawn     * @param x upper left corner x-coordinate     * @param y upper left corner y-coordinate     * @param w horizontal width     * @param h vertical height     * @param delay microseconds to delay after rendering     */    void repaintImpl(Displayable d, int x, int y, int w, int h, int delay) {        if (d != current) {            return;        }        if (updatePending) {            if (x < paintRectX1) {                paintRectX1 = x;            }            if (y < paintRectY1) {                paintRectY1 = y;            }            x += w;            y += h;            if (x > paintRectX2) {                paintRectX2 = x;            }            if (y > paintRectY2) {                paintRectY2 = y;            }        } else if ((w > 0) && (h > 0)) {            updatePending = true;            paintRectX1 = x;            paintRectY1 = y;            paintRectX2 = x + w;            paintRectY2 = y + h;            eventHandler.scheduleTimer(EventHandler.REPAINT, delay);        }    }    /**     * Process any pending repaint requests immediately.     *     * SYNC NOTE: this method performs its own locking of     * LCDUILock and calloutLock.  Therefore, callers     * must not hold any locks when they call this method.     */    void serviceRepaints() {        int x1, y1, x2, y2 = 0;        synchronized (LCDUILock) {            if (paintSuspended || !hasForeground || !updatePending) {                return;            }            x1 = paintRectX1;            y1 = paintRectY1;            x2 = paintRectX2;            y2 = paintRectY2;            updatePending = false;        }        // Protect from any unexpected application exceptions        try {            synchronized (calloutLock) {                screenGraphics.reset(x1, y1, x2, y2);                current.paint(screenGraphics);            }        } catch (Throwable thr) {            handleThrowable(thr);        }        refresh(x1, y1, x2, y2);    }    /**     * redraw a portiion of the display.     *     * @param x1 upper left corner x-coordinate     * @param y1 upper left corner y-coordinate     * @param x2 lower right corner x-coordinate     * @param y2 lower right corner y-coordinat     */    private native void refresh(int x1, int y1, int x2, int y2);    /**     * Return the key code that corresponds to the specified game     * action on the device.  gameAction must be a defined game action     * (Canvas.UP, Canvas.DOWN, Canvas.FIRE, etc.)     * <B>Post-conditions:</B><BR> The key code of the key that     * corresponds to the specified action is returned.  The return     * value will be -1 if the game action is invalid or not supported     * by the device.     *     * @param gameAction The game action to obtain the key code for.     * @return the key code.       */    static int getKeyCode(int gameAction) {        return eventHandler.getKeyCode(gameAction);    }    /**     * get the current horizontal scroll position.     * @return the horizontal scroll position.     */    int getHorizontalScrollPosition() {        // SYNC NOTE: No need to lock here because 'current'        // can only be null once, at startup, so we don't care        // if 'current' changes values, just that it isn't null        if (current != null) {            return current.getHorizontalScrollPosition();        } else {            return 0;        }    }    /**     * get the current horizontal scroll proportion.     * @return the horizontal scroll proportion.     */    int getHorizontalScrollProportion() {        // SYNC NOTE: No need to lock here because 'current'        // can only be null once, at startup, so we don't care        // if 'current' changes values, just that it isn't null        if (current != null) {            return current.getHorizontalScrollProportion();        } else {            return 100;        }    }

⌨️ 快捷键说明

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