Navigatable画布 : 油画 « 基于J2ME « Java 教程

En
Java 教程
1. 语言基础
2. 数据类型
3. 操作符
4. 流程控制
5. 类定义
6. 开发相关
7. 反射
8. 正则表达式
9. 集合
10. 线
11. 文件
12. 泛型
13. 本土化
14. Swing
15. Swing事件
16. 二维图形
17. SWT
18. SWT 二维图形
19. 网络
20. 数据库
21. Hibernate
22. JPA
23. JSP
24. JSTL
25. Servlet
26. Web服务SOA
27. EJB3
28. Spring
29. PDF
30. 电子邮件
31. 基于J2ME
32. J2EE应用
33. XML
34. 设计模式
35. 日志
36. 安全
37. Apache工具
38. 蚂蚁编译
39. JUnit单元测试
Java
Java 教程 » 基于J2ME » 油画 
31. 24. 6. Navigatable画布
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.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.midlet.MIDlet;

public class NavigateMIDlet extends MIDlet implements CommandListener {

  int stepX;

  int stepY;

  private Command leftCommand;

  private Command rightCommand;

  private Display display;

  Displayable nd;

  Image image = null;

  public NavigateMIDlet() {
    try {
      image = Image.createImage("/M.png");
    catch (Exception e) {
    }

    Display display = Display.getDisplay(this);

    nd = new NavigateCanvas(image);
    stepX = ((NavigateCanvasnd).getWidth() 4;
    stepY = ((NavigateCanvasnd).getHeight() 4;
    leftCommand = new Command("<Left", Command.SCREEN, 1);
    rightCommand = new Command("Right>", Command.SCREEN, 1);

    nd.addCommand(rightCommand);
    nd.addCommand(leftCommand);
    nd.setCommandListener(this);
    display.setCurrent(nd);
  }

  public void startApp() {
  }

  public void pauseApp() {
  }

  public void destroyApp(boolean unconditional) {
  }

  public void commandAction(Command c, Displayable d) {
    if (d == nd && c == leftCommand) {
      ((NavigateCanvasnd).steppingXY(stepX, 0);
      ((NavigateCanvasnd).repaint();
    else if (d == nd && c == rightCommand) {
      ((NavigateCanvasnd).steppingXY(-stepX, 0);
      ((NavigateCanvasnd).repaint();
    }
  }
}

class NavigateCanvas extends Canvas {
  private Image image;

  private int newX = 0;

  private int newY = 0;

  public NavigateCanvas(Image image) {
    this.image = image;
    newX = 0;
    newY = 0;
  }

  public void steppingXY(int x, int y) {
    newX += x;
    newY += y;
  }

  public void paint(Graphics g) {
    int width = this.getWidth();
    int height = this.getHeight();

    g.setGrayScale(255);
    g.fillRect(00, width - 1, height - 1);
    g.setGrayScale(0);
    g.drawRect(00, width - 1, height - 1);

    g.translate(newX, newY);
    g.drawImage(image, 00, g.TOP | g.LEFT);
  }
}
31. 24. 油画
31. 24. 1. 扩展画布创建自己的drawable区扩展画布创建自己的drawable区
31. 24. 2. 获得画布属性获得画布属性
31. 24. 3. 画布键盘事件
31. 24. 4. 使用帆布画时钟使用帆布画时钟
31. 24. 5. 画布大小画布大小
31. 24. 6. Navigatable画布
31. 24. 7. 画布箭头键
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.