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

📄 imagecomponent.java

📁 j2me下的1套UI框架.包含j2me开发中会应用的各种低级组件
💻 JAVA
字号:
package com.jmobilecore.ui.core;

import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Graphics;

/**
 * Provides an image for display on the screen. An image is not focusable.
 *
 * @author Greg Gridin
 */
public class ImageComponent extends Component {

    /**
     * The iame of this <code>ImageComponent</code>.
     */
    public Image image;

    /**
     * Constructs a new <code>ImageComponent</code> with the specified image,
     * left justified.
     *
     * @param image the image that this <code>ImageComponent</code> presents.
     *              A <code>null</code> value will be accepted without causing a NullPointerException
     *              to be thrown.
     */
    public ImageComponent(Image image) {

        this(image, LEFT);
    }

    /**
     * Constructs a new <code>ImageComponent</code> with the specified image,
     * and alignment.
     * Possible values for <code>alignment</code> are <code>Component.LEFT</code>,
     * <code>Component.RIGHT</code>, and <code>Component.CENTER</code>.
     *
     * @param image     the string that the label presents.
     *                  A <code>null</code> value will be accepted without causing a NullPointerException
     *                  to be thrown.
     * @param alignment the alignment value.
     */
    public ImageComponent(Image image, int alignment) {

        this.image = image;
        this.alignment = alignment;
        this.width = image.getWidth();
        setHeight();
    }

    /**
     * Paints this component.
     *
     * @param g the graphics context to use for painting
     */
    public void paint(Graphics g) {
        if (image != null) {
            paintBackground(g);
            int y = screenY + Style.V_GAP;
            if (alignment == LEFT) {
                g.drawImage(image, Style.H_GAP, y, Graphics.TOP | Graphics.LEFT);
            } else if (alignment == RIGHT) {
                g.drawImage(image, getWidth() - Style.H_GAP, y, Graphics.TOP | Graphics.RIGHT);
            } else if (alignment == CENTER) {
                g.drawImage(image, getWidth() / 2, y, Graphics.TOP | Graphics.HCENTER);
            }
        }
        super.paint(g);
    }

    /**
     * Calculates the component height
     */
    protected void setHeight() {
        if (image != null) {
            height = image.getHeight() + 2 * Style.V_GAP;
        } else
            height = 0;
    }

    /**
     * Class destructor. Helps VM to perform garbage collection
     */
    public void destructor() {
        image = null;
    }

} // class ImageComponent

⌨️ 快捷键说明

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