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

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

為TextBox組件創建簡單的剪貼板

2019-11-18 13:12:26
字體:
來源:轉載
供稿:網友

  在Core J2ME Technology and MIDP一書中許多的可以在多個多行編輯組件(multiple TextBox)中共享剪貼板數據的例子。
  
  注重:這個例子基于MIDP與CLDC 1.0.3版
  本文得到作者John W. MUChow的答應,部分引用了Core J2ME Technology and MIDP, Sun Microsystems與PRentice Hall出版社 2002 Sun Microsystems Inc, 的內容。
  
  源代碼:
  [code]/*--------------------------------------------------
  * SimpleClipBoard.java
  *
  * Example from the book:   Core J2ME Technology
  * Copyright John W. Muchow  http://www.CoreJ2ME.com
  * You may use/modify for any non-commercial purpose
  *-------------------------------------------------*/
  import javax.microedition.midlet.*;
  import javax.microedition.lcdui.*;
  
  public class SimpleClipBoard extends MIDlet implements CommandListener
  {
  private Display display;   // 對顯示對象的引用Reference to Display object
  private TextBox tbClip;   // 主TextBox組件Main textbox
  private Command cmExit;   // 退出命令Command to exit
  private Command cmStartMark; // 開始標記命令Command to start marking a block
  private Command cmCopy;   // 復制剪貼板命令Command to copy to clipboard
  private Command cmPaste;   // 粘貼剪貼板命令Command to paste into textbox
  private int beginOffset = 0; // 復制的開始索引The start index of copy
  private char[] clipBoard = null; // 剪貼板The clipboard
  private int clipBoardChars = 0; // 記錄剪貼板中的字符Number of chars in clipboard
  
  public SimpleClipBoard()
  {
  display = Display.getDisplay(this);
  
  // Create the Commands. Notice the priorities assigned
  cmExit = new Command("Exit", Command.EXIT, 1);
  cmStartMark = new Command("Mark", Command.SCREEN, 2);
  cmCopy = new Command("Copy", Command.SCREEN, 3);
  cmPaste = new Command("Paste", Command.SCREEN, 4);
  
  tbClip = new TextBox("Clip Board", "Tee to grn", 15, TextField.ANY);
  tbClip.addCommand(cmExit);
  tbClip.addCommand(cmStartMark);
  tbClip.addCommand(cmCopy);
  tbClip.addCommand(cmPaste);
  tbClip.setCommandListener(this);
  
  // Allocate a clipboard big enough to hold the entire textbox
  clipBoard = new char[tbClip.getMaxSize()];
  }
  
  public void startApp()
  {
  display.setCurrent(tbClip);
  }
  
  public void pauseApp()
  {
  }
  
  public void destroyApp(boolean unconditional)
  {
  }
  
  public void commandAction(Command c, Displayable s)
  {
  if (c == cmStartMark)
  {
  beginOffset = tbClip.getCaretPosition();
  }
  else if (c == cmCopy && (tbClip.getCaretPosition() > beginOffset))
  {
  // Allocate an array to hold the current textbox contents
  char[] chr = new char[tbClip.size()];
  
  // Get the current textbox contents
  tbClip.getChars(chr);
  
  // The count of characters in the clipboard
  clipBoardChars = tbClip.getCaretPosition() - beginOffset;
  
  // Copy the text into the clipboard
  // arraycopy(source, sourceindex, dest, destindex, count)
  System.arraycopy(chr, beginOffset, clipBoard, 0, clipBoardChars);
  }
  else if (c == cmPaste)
  {
  // Make sure the paste will not overrun the textbox length.
  if ((tbClip.size() + clipBoardChars) <= tbClip.getMaxSize())
  tbClip.insert(clipBoard, 0, clipBoardChars, tbClip.getCaretPosition());
  }
  else if (c == cmExit)
  {
  destroyApp(false);
  notifyDestroyed();
  }
  }
  }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 潮安县| 南康市| 鸡西市| 焉耆| 静乐县| 长丰县| 讷河市| 墨玉县| 昆明市| 精河县| 宜昌市| 固始县| 泊头市| 化隆| 长垣县| 卫辉市| 呼伦贝尔市| 延安市| 常熟市| 建瓯市| 沾益县| 榆中县| 周口市| 抚松县| 兴仁县| 丹寨县| 乌拉特前旗| 吴川市| 白城市| 奈曼旗| 淅川县| 夏河县| 石门县| 高唐县| 娄烦县| 清河县| 微博| 宝丰县| 宜城市| 安宁市| 鄂托克旗|