积分规则 网站地图 帮助中心    
嵌入式软件 单 片 机 DSP 存储器 传感控制 光电显示
嵌入式硬件 CPLD/FPGA SOPC AD/DA 接口电路 模拟设计
I C设计 通信产品 汽车电子 电源产品 消费电子 数控系统
工业控制 军工/航天 安防产品 医疗电子 计算机外设 测试测量
供应 I C
求购 公司库

  IC 求购 销售 公司 论文 DATASHEET 参考设计 论坛
当前位置: 电子技术 >> 嵌入式软件 >> JAVA
  相关分类: LINUX | WINCE | UC/OS | Bootloader | 下载 | VXWORKS | 网络协议 | JAVA | 汇编 | 驱动设计 | Symbian | XP Embedded | Nucleus | 新产品 | 相关文章 | 综合技术 |
2D绘画操作中的坐标系统变换源代码
 
作者:未知   来源:J2ME开发网    点击数:994   更新时间:2006-9-12
您可以添加到网摘 让更多人关注此文章:

    

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class Translate extends MIDlet
{
  private Display  display;     // The display
  private TranslateCanvas canvas;   // Canvas 
  public Translate()
  {
    display = Display.getDisplay(this);
    canvas  = new TranslateCanvas(this);
  }
  protected void startApp()
  {
    display.setCurrentcanvas );
  }
  protected void pauseApp()
  { }

  protected void destroyAppboolean unconditional )
  { }
  public void exitMIDlet()
  {
    destroyApp(true);
    notifyDestroyed();
  }
}

/*--------------------------------------------------
* Class Translate
*
* Draw image using translated coordinates
*-------------------------------------------------*/
class TranslateCanvas extends Canvas implements CommandListener
{
  private Command cmExit;  // Exit midlet
  private Translate midlet;
  private Image im = null;
  private int translatex = 0, translatey = 0;
  public TranslateCanvas(Translate midlet)
  {
    this.midlet = midlet;
    // Create exit command & listen for events
    cmExit = new Command("Exit", Command.EXIT, 1);
    addCommand(cmExit);
    setCommandListener(this);

    try
    {
      // Create immutable image
      im = Image.createImage("/bolt.png");
    }
    catch (java.io.IOException e)
    {
      System.err.println("Unable to locate or read .png file");
    }    
  

  protected void paint(Graphics g)
  {
    if (im != null)
    {
      // Clear the background
      g.setColor(255255255);
      g.fillRect(00, getWidth(), getHeight());
      // Translate coordinates
      g.translate(translatex, translatey);      
      // Always draw at 0,0
      g.drawImage(im, 00, Graphics.LEFT | Graphics.TOP);
    }
  }

  public void commandAction(Command c, Displayable d)
  {
    if (c == cmExit)
      midlet.exitMIDlet();
  }
  protected void keyPressed(int keyCode)
  {
    switch (getGameAction(keyCode))
    {
      case UP: 
        // If scrolling off the top, roll around to bottom
        if (translatey - im.getHeight() 0)
          translatey = getHeight() - im.getHeight();
        else
          translatey -= im.getHeight();          
        break;
      case DOWN:

        // If scrolling off the bottom, roll around to top
        if ((translatey + im.getHeight() + im.getHeight()) > getHeight())
          translatey = 0;
        else
          translatey += im.getHeight();          
        break;
      case LEFT:
        // If scrolling off the left, bring around to right
        if (translatex - im.getWidth() 0)
          translatex = getWidth() - im.getWidth();
        else
          translatex -= im.getWidth();          
        break;

      case RIGHT:
        // If scrolling off the right, bring around to left
        if ((translatex + im.getWidth() + translatex> getWidth())
          translatex = 0;
        else
          translatex += im.getWidth();          
        break;
    }        
    repaint();
  }
}



相关文章
· 科技奥运与计算机技术的应用[405]
· Electromedical[2669]
· 患者监控[2726]
· 基于TMS320LF2407A DSP的心电监护系统研究[3166]
· 用S3C2410实现三导联远程心电监护系统[3083]
热门评论排行
·VHDL设计中电路简化问题的
·ARM嵌入式系统基础教程(N
·江苏嵌入式Linux教育培训
·ARM处理器应用开发4步骤
·锐极LINUX驱动培训班定于

文章评论
    没有任何评论
*只显示最新10条评论。评论内容只代表网友观点,与本站立场无关。更多评论
发表评论
  * 请先[登陆]再进行评论,谢谢。
评分: 1分 2分 3分 4分 5分
内容: *
发帖须知:
一.所发文章必须遵守《互联网电子公告服务管理规定》;
二.严禁发布供求代理信息,公司介绍,产品信息等广告宣传信息;
三.严禁恶意重复发帖;
四.严禁对个人,实体,民族,国家等进行漫骂,污蔑,诽谤。
 
热点新闻 [更多]
 
避免危及半导体业 德出手挽
HP实验室展示集CMOS电路与忆阻器
全球第二大代工巨头伟创力瘦身应对金融
Vishay Silico
奥地利微电子发布全球首款具有嵌入式比
采用 4mm x
未来MEMS产业恐缩水 车
iSuppli发布08年半导体厂商初
飞兆半导体指控英飞凌专利侵权
全球三大晶圆代工巨头齐遇冷 
 
热门下载 [更多]
 
[ PCB设计] Protel99教程下载
[ ] 手把手学单片机20个例
[ ] 单片机做的智能台灯
[ ] 单片机入门书
[ ] linux系统移植开发文档
[ ] IC卡的读写程序
[ ] 8051单片机C语言彻底应用
[ 常用软件] 555定时器电路设计软件V1.2
[ 常用软件] 51定时器计算软件
[ ] ARM处理器应用开发4步骤
 
论坛新帖 [更多]
 
嵌入式十三法则...
基于CPLD和单片机的任意波形...
电子行业的发展方向...
单片机-超低价专业PCB打样...
超低价专业PCB打样 双面板...
[原创]主题:移动开发平台的建...
[原创]正弦脉宽调制(SPWM...
[推荐]Agilent8590...
[推荐]HP8591E HP8...
[推荐]Agilent8711...

 
赞助商 [更多]
 

ICP许可证号:[粤 05056597]
联系电话:010-82517432 82517615 传真: 010-82517615

版权所有 Copyright © 2006 嵌入式技术网