📄 bufferimage.java
字号:
/*
* 双缓存显示图片
*/
import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class bufferImage extends MIDlet implements CommandListener {
private Command exitCommand;
private bufferImageCanvas sg;
public bufferImage() {
exitCommand = new Command("Exit", Command.EXIT, 1);
sg = new bufferImageCanvas();
sg.addCommand(exitCommand);
sg.setCommandListener(this);
Display.getDisplay(this).setCurrent(sg);
}
protected void startApp(){
}
protected void pauseApp() {
}
protected void destroyApp(boolean arg0){
}
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
}
class bufferImageCanvas extends Canvas{
Image source; //缓冲区要绘画的图像
Image copy;//缓冲区对象
protected bufferImageCanvas(){
try {
source = Image.createImage("/house.png");
//指定缓冲区域为屏幕大小
copy =Image.createImage(this.getWidth(),this.getHeight());
Graphics g = copy.getGraphics();// 获得一个新的Graphics对象
g.drawImage(source,this.getWidth()/2,this.getHeight()/2,
Graphics.BOTTOM|Graphics.HCENTER);
} catch (IOException e) {
e.printStackTrace();
}
}
protected void paint(Graphics g) {
//显示缓存区的可变Image对象
g.drawImage(copy,0,0,Graphics.TOP|Graphics.LEFT);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -