import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.midlet.MIDlet;
public class Exec extends MIDlet {
private Display display;
public Exec() {
display = Display.getDisplay(this);
}
public void startApp() {
display.setCurrent(new DrawPanel());
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
class DrawPanel extends Canvas {
int startX = 0;
int startY = 0;
int endX = 0;
int endY = 0;
Image image = Image.createImage(getWidth(), getHeight());
protected void paint(Graphics g) {
g.drawImage(image, 0, 0, 0);
g.setColor(0,0,0);
g.drawLine(startX, startY, endX, endY);
}
protected void pointerPressed(int x, int y) {
startX = x;
startY = y;
}
protected void pointerReleased(int x, int y) {
endX = x;
endY = y;
Graphics gOfImage = image.getGraphics();
gOfImage.drawLine(startX, startY, endX, endY);
repaint();
}
protected void pointerDragged(int x, int y) {
endX = x;
endY = y;
repaint();
}
}
[此贴子已经被作者于2010-12-12 18:35:24编辑过]