国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

使用指針事件在Canvas上繪畫

2019-11-18 16:06:11
字體:
來源:轉載
供稿:網友
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class Doodle extends MIDlet
{
  PRivate Display  display;       // The display
  private DoodleCanvas canvas;   // Canvas 
  public Doodle()
  {
    display = Display.getDisplay(this);
    canvas  = new DoodleCanvas(this);
  }
  protected void startApp()
  {
    display.setCurrent( canvas );
  }
  protected void pauseApp()
  { }

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

/*--------------------------------------------------
* Class DoodleCanvas
*
* Pointer event handling
*-------------------------------------------------*/
class DoodleCanvas extends Canvas implements CommandListener
{
  private Command cmExit;          // Exit midlet
  private Command cmClear;         // Clear display
  private int startx = 0,   // Where pointer was clicked
              starty = 0,
              currentx = 0, // Current location
              currenty = 0;
  private Doodle midlet;
  private boolean clearDisplay = false;

  /*--------------------------------------------------
  * ConstrUCtor
  *-------------------------------------------------*/
  public DoodleCanvas(Doodle midlet)
  {
    this.midlet = midlet;
    // Create exit command & listen for events
    cmExit = new Command("Exit", Command.EXIT, 1);
    cmClear = new Command("Clear", Command.SCREEN, 1);    
    addCommand(cmExit);
    addCommand(cmClear);
    setCommandListener(this);
  } 

  /*--------------------------------------------------
  * Paint the text representing the key code 
  *-------------------------------------------------*/
  protected void paint(Graphics g)
  {
    // Clear the background (to white)
    if (clearDisplay)
    {
      g.setColor(255, 255, 255);
      g.fillRect(0, 0, getWidth(), getHeight());
      clearDisplay = false;
      startx = currentx = starty = currenty = 0;
      return;
    }
    // Draw with black pen
    g.setColor(0, 0, 0);
    // Draw line
    g.drawLine(startx, starty, currentx, currenty);
    // New starting point is the current position
    startx = currentx;
    starty = currenty;
  }

  /*--------------------------------------------------
  * Command event handling
  *-------------------------------------------------*/  
  public void commandAction(Command c, Displayable d)
  {
    if (c == cmExit)
      midlet.exitMIDlet();
    else if (c == cmClear)
    {
      clearDisplay = true
      repaint();
    }
  }

  /*--------------------------------------------------
  * Pointer pressed
  *-------------------------------------------------*/  
  protected void pointerPressed(int x, int y)
  {
    startx = x;
    starty = y;
  }

  /*--------------------------------------------------
  * Pointer moved
  *-------------------------------------------------*/  
  protected void pointerDragged(int x, int y)
  {
    currentx = x;
    currenty = y;       
    repaint();
  } 
}

(出處:http://www.survivalescaperooms.com)



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 泸州市| 荥经县| 五寨县| 宝兴县| 平谷区| 彰化市| 雷波县| 梨树县| 西安市| 沈阳市| 福泉市| 满城县| 明光市| 泸定县| 革吉县| 绵阳市| 马龙县| 林周县| 临颍县| 遂川县| 海安县| 蒲江县| 德惠市| 卓尼县| SHOW| 加查县| 山西省| 乐安县| 津市市| 曲阳县| 福贡县| 廉江市| 洛阳市| 云阳县| 汝阳县| 紫金县| 栖霞市| 莲花县| 榕江县| 沈丘县| 庄河市|