savescreenmidlet.java.svn-base
来自「example2 众多JAVA实例源码...学习java基础的好帮手」· SVN-BASE 代码 · 共 71 行
SVN-BASE
71 行
package opusmicro.demos.canvas;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.midlet.MIDlet;
public class SaveScreenMIDlet extends MIDlet implements CommandListener {
private Display display = null;
private SimpleCanvas canvas = new SimpleCanvas(true);
private Command printCommand = new Command("Print", Command.OK, 1);
public void startApp() {
if ( display == null) display = Display.getDisplay(this);
canvas.addCommand(printCommand);
canvas.setCommandListener(this);
display.setCurrent(canvas);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void commandAction(Command command, Displayable displayable) {
if(command == printCommand){
Form form = new Form("screen");
form.append(canvas.printMe());
display.setCurrent(form);
}
}
}
class SimpleCanvas extends Canvas {
int w;
int h;
private Image offImage = null;
private boolean buffered = true;
public SimpleCanvas(boolean _buffered) {
buffered = _buffered;
w = getWidth();
h = getHeight();
if ( buffered) offImage = Image.createImage(w, h);
}
protected void paint(Graphics g) {
int color = g.getColor();
g.setColor(0xFFFFFF);
g.fillRect(0, 0, w, h);
g.setColor(color);
Graphics save = g;
if ( offImage != null) g = offImage.getGraphics();
// draw the offimage
g.setColor(128, 128, 0);
g.fillRoundRect((w - 100) / 2, (h - 60) / 2, 100, 60, 5, 3);
g.setColor(0xffeebb);
g.drawString("this is buffer", (w-100)/2, (h-60)/2, 0);
// draw the offimage to the canvas
save.drawImage(offImage, 0, 0, Graphics.TOP | Graphics.LEFT);
}
public Image printMe() {
return offImage;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?