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

📄 sdaimage.java

📁 很好的UI界面源码..还有自己的输入法,可以更换风格.可以学习和使用
💻 JAVA
字号:
package cn.sda.ui;

import java.io.*;
import javax.microedition.lcdui.*;

/**
 * @author not attributable
 * @version 1.0
 */
public class SDAImage extends SDABaseControl {

    private Image image = null;
    private Image scaleImage = null;
    private boolean stretch = false;
    private boolean autoSize = false;
    private boolean center = false;

    public SDAImage() {
        this.tabStop = false;
        this.width = 50;
        this.height = 50;
    }

    private void DrawImage(Graphics g) {
        if (this.autoSize) {
            this.setWidth(image.getWidth());
            this.setHeight(image.getHeight());
            drawImage(g, image, 0, 0, 0);
            return;
        }
        if (this.stretch) {
            if (scaleImage == null || scaleImage.getWidth() != this.getWidth() ||
                    scaleImage.getHeight() != this.getHeight()) {
                scaleImage = SDAImageUtils.processImage(image, this.width, this.height, SDAImageUtils.MODE_STRETCH);
            }
            drawImage(g, scaleImage, 0, 0, 0);
            return;
        }
        if (this.center) {
            int cx = (this.getWidth() - image.getWidth()) / 2;
            int cy = (this.getHeight() - image.getHeight()) / 2;
            drawImage(g, image, cx, cy, 0);
            return;
        }
        drawImage(g, image, 0, 0, 0);
    }

    /**
     * paint
     *
     * @todo Implement this cn.sdaui.cldc.SDABaseControl method
     */
    public void paint() {
        if (!IsCanPaint()) {
            return;
        }
        Graphics g = form.getGraphics();
        SetClip(g);
        if (!transparent) {
            g.setColor(backColor);
            fillRect(g, 0, 0, width, height);
        }
        if (image != null) {
            DrawImage(g);
            System.out.println("w:"+image.getWidth());
            System.out.println("h:"+image.getHeight());
        }
        PaintChilds();
    }

    public boolean LoadImage(String imageName) {
        try {
            image = Image.createImage(imageName);
            //this.paint();
            return true;
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return false;
    }

    public void LoadImage(byte[] imageData, int imageOffset, int imageLength) {
        image = Image.createImage(imageData, imageOffset, imageLength);
        this.paint();
    }

    public void LoadImage(Image image) {
        this.image = image;
        this.paint();
    }

    public void CreateEmptyImage(int width, int height) {
        image = Image.createImage(width, height);
        this.paint();
    }

    public Image getImage() {
        return image;
    }

    public boolean isAutoSize() {
        return autoSize;
    }

    public boolean isStretch() {
        return stretch;
    }

    public boolean isCenter() {
        return center;
    }

    public void setStretch(boolean stretch) {
        this.stretch = stretch;
    }

    public void setAutoSize(boolean autoSize) {
        this.autoSize = autoSize;
        if (autoSize) {
            if (getParent() != null) {
                getParent().paint();
            }
        }
        paint();
    }

    public void setCenter(boolean center) {
        this.center = center;
    }
}

⌨️ 快捷键说明

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