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

📄 displayable.java

📁 有关j2me的很好的例子可以研究一下
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * @(#)Displayable.java	1.51 01/08/20 * Copyright (c) 1999-2001 Sun Microsystems, Inc. All Rights Reserved. * * This software is the confidential and proprietary information of Sun * Microsystems, Inc. ("Confidential Information").  You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with Sun. * * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING * THIS SOFTWARE OR ITS DERIVATIVES. */package javax.microedition.lcdui;/** * <P>An object that has the capability of being placed on the display.  A * Displayable object may have commands and listeners associated with it.  The  * contents displayed and their interaction with the user are defined by * subclasses.</P> */abstract public class Displayable {    /**     * Create a new Displayable     */    Displayable() { }    /**     * Checks if the Displayable is actually visible on the display.  In order      * for a Displayable to be visible, all of the following must be true:     * the Display's MIDlet must be running in the foreground, the Displayable      * must be the Display's current screen, and the Displayable must not be      * obscured by a <a href="Display.html#systemscreens">     * system screen</a>.     *     * @return true if the Displayable is currently visible     */    public boolean isShown() {        synchronized (Display.LCDUILock) {            if (currentDisplay == null) {                return false;            } else {                return currentDisplay.isShown(this);            }        }    }    /**     * Adds a command to the Displayable. The implementation may choose,     * for example,     * to add the command to any of the available softbuttons or place it     * in a menu.     * If the added command is already in the screen (tested by comparing the     * object references), the method has no effect.     * If the Displayable is actually visible on the display, and this call      * affects the set of visible commands, the implementation should update      * the display as soon as it is feasible to do so.     *      * @param cmd the command to be added     *     * @throws java.lang.NullPointerException   if cmd is null     */    public void addCommand(Command cmd) {        if (cmd == null) {            throw new NullPointerException();        }        synchronized (Display.LCDUILock) {            addCommandImpl(cmd);        } // synchronized    }    /**     * Removes a command from the Displayable.     * If the command is not in the Displayable (tested by comparing the     * object references), the method has no effect.     * If the Displayable is actually visible on the display, and this call     * affects the set of visible commands, the implementation should update     * the display as soon as it is feasible to do so.     *      * @param cmd the command to be removed     */    public void removeCommand(Command cmd) {        synchronized (Display.LCDUILock) {            removeCommandImpl(cmd);        } // synchronized    }    /**     * Sets a listener for {@link Command Commands} to this Displayable,     * replacing any previous CommandListener. A <code>null</code> reference is     * allowed and has the effect of removing any existing listener.     *     * @param l the new listener, or <code>null</code>.     */    public void setCommandListener(CommandListener l) {        synchronized (Display.LCDUILock) {            listener = l;        }    };    /*      * these are protected on Canvas.  They are here so that a     * single event-delivery method can be used for Screen and     * for Canvas.     */    /**     * Handle a key press     *     * @param keyCode The key that was pressed     */    void keyPressed(int keyCode) { }    /**     * Handle a repeated key press     *     * @param keyCode The key that was pressed     */    void keyRepeated(int keyCode) { }    /**     * Handle a key release     *     * @param keyCode The key that was released     */    void keyReleased(int keyCode) { }    /**     * Handle a key that was typed from the keyboard     *     * @param c The char that was typed     */    void keyTyped(char c) {}    /**     * Handle a pointer press event     *     * @param x The x coordinate of the press     * @param y The y coordinate of the press     */    void pointerPressed(int x, int y) { }    /**     * Handle a pointer drag event     *     * @param x The x coordinate of the drag     * @param y The y coordinate of the drag     */    void pointerDragged(int x, int y) { }    /**     * Handle a pointer release event     *     * @param x The x coordinate of the release     * @param y The y coordinate of the release     */    void pointerReleased(int x, int y) { }    /**     * Repaint this Displayable     *     * @param x The x coordinate of the region to repaint     * @param y The y coordinate of the region to repaint     * @param width The width of the region to repaint     * @param height The height of the region to repaint     */    void repaint(int x, int y, int width, int height) {        // NOTE: Notice the 30ms delay. In an animation application        // which relies solely on calls to repaint() (no need to use        // serviceRepaints()) the 30ms delay below essentially yields        // a ~30fps framerate (1000/30). There is probably no need to        // go any faster than 30fps, assuming the device is even        // capable. The delay in general allows for subsequent calls        // to repaint() to be coalesced. That is, several application        // calls to repaint() occurring in a short period of time (within        // the 30ms delay window) will have their dirty regions        // coalesced and will result in a single call to the application's        // paint() method at the end of the 30ms delay. Specific        // implementations may want to tune this delay to better match        // the underlying hardware, as small devices are probably only        // capable of a much lesser framerate.        if (currentDisplay != null) {            currentDisplay.repaintImpl(this, x, y, width, height, 30);        }    }    /**     * Repaint this Displayable in its entirety, ie     * the same as repaint(0, 0, Display.WIDTH, Display.HEIGHT);     */    void repaint() {        repaint(0, 0, Display.WIDTH, Display.HEIGHT);    }    /**     * Paint this Displayable     *     * @param g The Graphics object to paint to     */    abstract void paint(Graphics g);    /**     * The horizontal scroll position     */    private int hScrollPosition     = 0;    /**     * The horizontal scroll proportion     */    private int hScrollProportion   = 100;    /**     * Set the horizontal scroll position and proportion.     * Note that currently, true horizontal scrolling is not     * supported by the HI specification (in fact its explicitly forbidden).     * The API is used currently solely for indicating to the user the     * ability to increase/decrease the value of a Gauge. The next version     * will most likely modify this behavior and all APIs regarding     * horizontal scrolling will be removed, since they're not very     * indicative of what they actually do.     *     * @param scrollPosition The position of the horizontal scroll position     *                       on a scale of 0 to 100. This is used to turn on     *                       the left/right indicator arrows for the user.     * @param scrollProportion This isn't really used since the HI spec     *                         forbids horizontal scrolling. Normally, it     *                         would be used to render a scrollbar.     */    void setHorizontalScroll(int scrollPosition, int scrollProportion) {        this.hScrollPosition = scrollPosition;        this.hScrollProportion = scrollProportion;        synchronized (Display.LCDUILock) {            if ((currentDisplay != null) && currentDisplay.isShown(this)) {                currentDisplay.setHorizontalScroll(scrollPosition,                                                   scrollProportion);            }        }

⌨️ 快捷键说明

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