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

📄 simplebasisamsimagebutton.java

📁 This is a resource based on j2me embedded,if you dont understand,you can connection with me .
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     *     * @param border     the over border     */    public void setOverBorder(SimpleBasisAMSBorder border) {        if (border != null) {            setBorder(OVER, border);        } else {            setBorder(OVER, borders[UNPRESSED]);        }        setBorder(OVER, border);    }        /**     * Sets the border to display when the button is disabled.     *     * @param border     the disabled border     */    public void setDisabledBorder(SimpleBasisAMSBorder border) {        if (border != null) {            setBorder(DISABLED, border);        } else {            setBorder(DISABLED, borders[UNPRESSED]);        }        if (buttonState == DISABLED) {            repaint();        }    }        /**     * Gets the border to display when the button is not pressed or hilited     * because of a mouse-over.  This border is also used in those other cases     * if no alternative border is requested.     *     * @return     the unarmed border     */    /*        public Border getUnpressedBorder() {            return (borders[UNPRESSED]);        }     */        /**     * Gets the border to display when the button is pressed and the mouse     * is still over the button.     *     * @return     the armed border     */    /*        public Border getDepressedBorder() {            return (borders[DEPRESSED]);        }     */        /**     * Gets the border to display when the button is not pressed and the mouse     * is over the button.     *     * @return     the over border     */    /*        public Border getOverBorder() {            return (borders[OVER]);        }     */        /**     * Gets the border to display when the button is disabled.     *     * @return     the armed border     */    /*        public Border getDisabledBorder() {            return (borders[DISABLED]);        }     */        /**     * Gets the current buttonState id for the button     *     * @return     the button state integer id     */    /*        public int getButtonState() {            return buttonState;        }     */        /**     * Sets the current buttonState id for the button     *     * @param   buttonState     the button state integer id     */    protected void setButtonState(int buttonState) {        if (buttonState != this.buttonState) {            this.buttonState = buttonState;            repaint();        }    }        public void setLabel(String str) {        label = str;    }        public void setLabel(String str, int x, int y) {        label = str;        labelX = x;        labelY = y;    }        public String getLabel() {        return label;    }        /**     * Overrides awt.Component.disable() to also set the button state.     */    /*        public void disable() {            setButtonState(DISABLED);            super.disable();        }     */        /**     * Overrides awt.Component.enable() to also set the button state.     */    /*        public void enable() {            setButtonState(UNPRESSED);            super.enable();        }     */        /**     * Overrides awt.Component.paint() to paint the current border and image.     *     * @param     g     The Graphics in which to draw     */    public void paint(Graphics g) {                Dimension size = getSize();        if (hasFocus()) {            g.setColor(Color.black);        } else {            g.setColor(getForeground());        }        g.fillRect(0, 0, size.width, size.height);                try {            if (!tracker.checkID(buttonState)) {                tracker.waitForID(buttonState);            }            if (!tracker.isErrorID(buttonState)) {                Insets insets = borders[buttonState].getInsets();                if (images[buttonState] != null) {                    int imageWidth = images[buttonState].getWidth(this);                    int imageHeight = images[buttonState].getHeight(this);                    int x = insets.left +                            ( ( (size.width - (insets.left + insets.right)) -                            imageWidth) / 2);                    int y = insets.top +                            ( ( (size.height - (insets.top + insets.bottom)) -                            imageHeight) / 2) - 5;                    g.drawImage(images[buttonState], x, y, this);                }            } else {                trace("ERROR: Invalid image used for button: " + label);            }        } catch (Exception e) {            trace(e.getMessage());        }                // for label        if (label != null) {            FontMetrics fm = null;            if (currentFont != null) {                g.setFont(currentFont);                fm = getFontMetrics(currentFont);            } else {                g.setFont(defaultFont);                fm = getFontMetrics(defaultFont);            }                        int labelWidth = (int) fm.stringWidth(label);            int buttonWidth = size.width;            String displayLabel = label;            String tmpLabel = null;            while (labelWidth > size.width) {                displayLabel = displayLabel.substring(0, displayLabel.length() - 1);                tmpLabel = displayLabel + "...";                labelWidth = (int) fm.stringWidth(tmpLabel);            }                        if (tmpLabel != null) {                displayLabel = tmpLabel;            }                        int height = (int) fm.getHeight();            if (labelX == -1) {                labelX = ( (size.width - labelWidth) / 2);                if (labelX < 0) {                    labelX = 0;                }            }            if (labelY == -1) {                if (images[buttonState] != null && !tracker.isErrorID(buttonState)) {                    labelY = (int) (size.height - 5);                } else {                    labelY = (int) (size.height / 2) + (height / 2) ;                }            }                        g.setColor(textColor);            if (labelDisplay) {                if (textShadow) {                    drawTextShadowString(g, displayLabel, labelX, labelY);                } else {                    g.drawString(displayLabel, labelX, labelY);                }            }        }                if (paintBorders) {            borders[buttonState].paint(g, getBackground(), 0, 0, size.width,                    size.height);        }    }        private void trace(String str) {        SimpleBasisAMS.trace(str);    }        private void drawTextShadowString(Graphics g, String str, int x, int y) {        Color origColor = g.getColor();        g.setColor(Color.BLACK);        g.drawString(str, x + 1, y + 1);        g.setColor(origColor);        g.drawString(str, x, y);    }        /*        public Dimension getMinimumSize() {            return getPreferredSize();        }     */        /*        public Dimension getMaximumSize() {            return getPreferredSize();        }     */        /**     * Overrides awt.Component.preferredSize() to return the preferred size of the button.     * This assumes the images (if more than one) are all the same size.  It also calculates     * the maximum insets from all borders and adds them to the image dimensions.     *     * @param     g     The Graphics in which to draw     */    public Dimension getPreferredSize() {                if (prefSize != null) {            return prefSize;        } else {            return new Dimension(120, 70);        }        /*                if (prefSize != null) {                    return prefSize;                }                         Dimension pref = new Dimension();                try {                    if (!tracker.checkID(buttonState)) {                        tracker.waitForID(buttonState);                    }                    if (!tracker.isErrorID(buttonState)) {                        Dimension size = size();                        pref.width = images[buttonState].getWidth(this);                        pref.height = images[buttonState].getHeight(this);                    }                    int maxWidthAdd = 0;                    int maxHeightAdd = 0;                    for (int i = 0; i < DISABLED; i++) {                        Insets insets = borders[i].getInsets();         maxWidthAdd = Math.max(maxWidthAdd, insets.left + insets.right);                        maxHeightAdd = Math.max(maxHeightAdd,                                                insets.top + insets.bottom);                    }                    pref.width += maxWidthAdd;                    pref.height += maxHeightAdd;                }                catch (InterruptedException ie) {                }                return pref;         */    }        public void processMouseEvent(MouseEvent e) {        if (actionListener != null) {            if (e.getID() == MouseEvent.MOUSE_RELEASED) {                ActionEvent ae = new ActionEvent(this,                        ActionEvent.ACTION_PERFORMED,                        "");                actionListener.actionPerformed(ae);            }        }            }        public synchronized void addActionListener(ActionListener l) {        actionListener = AWTEventMulticaster.add(actionListener, l);    }        public synchronized void removeActionListener(ActionListener l) {        actionListener = AWTEventMulticaster.remove(actionListener, l);    }        /*        public synchronized ActionListener getActionListener() {            return actionListener;        }     */        public void mouseClicked(MouseEvent e) {        requestFocusInWindow();    }        public void mousePressed(MouseEvent e) {    }        public void mouseReleased(MouseEvent e) {    }        public void mouseEntered(MouseEvent e) {    }        public void mouseExited(MouseEvent e) {    }    }/** * DisableImageFilter - an RGBImageFilter that "greys out" an image by "blanking out" * every other pixel. */class DisableImageFilter        extends RGBImageFilter {    /**     * Constructs a DisableImageFilter.  The canFilterIndexColorModel is set to false     * because the pixel index is important during filtering.     */    public DisableImageFilter() {        canFilterIndexColorModel = false;    }        /**     * Called when a disabled image is created to alter the pixels to be blanked out.     *     * @param   x   the x position of the pixel     * @param   y   the y position of the pixel     * @param   rgb the rgb value of the pixel     */    public int filterRGB(int x, int y, int rgb) {        if ( ( (x % 2) ^ (y % 2)) == 1) {            return (rgb & 0xffffff);        } else {            return rgb;        }    }}/** * DefaultJUMPGuiAMSImageButtonBorder - a Border, subclassed to set the default border values. */class DefaultJUMPGuiAMSImageButtonBorder        extends SimpleBasisAMSBorder {        public DefaultJUMPGuiAMSImageButtonBorder(boolean armed) {        setJUMPGuiAMSBorderThickness(2);        if (armed) {            setType(THREED_IN);            setMargins(4, 4, 2, 2);        } else {            setType(THREED_OUT);            setMargins(3);        }    }}

⌨️ 快捷键说明

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