你閱讀開發人員指南:http://www.codenameone.com/developer-guide.html
的JavaDoc:https://codenameone.googlecode.com/svn/trunk/CodenameOne/javadoc/index.html
你應該得到組件和覆蓋塗料,注意到這個代碼是非常糟糕的,因爲它沒有消除重複或做任何事巧:
class Draw extends Component {
private ArrayList<Point> points = new ArrayList<Point>();
public Draw() {
setFocusable(true);
}
public void pointerPressed(int x, int y) {
points.add(new Point(x, y, 0xff0000));
}
public void pointerDragged(int x, int y) {
points.add(new Point(x, y, 0xff0000));
}
public void pointerReleased(int x, int y) {
points.add(new Point(x, y, 0xff0000));
}
public void paint(Graphics g) {
Point lastPoint = null;
for(Point p : points) {
if(lastPoint != null) {
g.setColor(p.color);
g.drawLine(lastPoint.x, lastPoint.y, p.x, p.y);
}
lastPoint = p;
}
}
}
class Point {
int x;
int y;
int color;
public Point(int x, int y, int color) {
this.x = x; this.y = y; this.color = color;
}
}