<4D F736F F F696E74202D20B8DFBCB6D3C3BBA7BDE7C3E6D3EBB6E0CFDFB3CC2E707074>

Similar documents
Chapter 9: Objects and Classes

untitled

詞 彙 表 編 號 詞 彙 描 述 1 預 約 人 資 料 中 文 姓 名 英 文 姓 名 身 份 證 字 號 預 約 人 電 話 性 別 2 付 款 資 料 信 用 卡 別 信 用 卡 號 信 用 卡 有 效 日 期 3 住 房 條 件 入 住 日 期 退 房 日 期 人 數 房 間 數 量 入

OOP with Java 通知 Project 4: 4 月 18 日晚 9 点 关于抄袭 没有分数

OOP with Java 通知 Project 3: 3 月 29 日晚 9 点 4 月 1 日上课

2009年3月全国计算机等级考试二级Java语言程序设计笔试试题

OOP with Java 通知 Project 4: 4 月 19 日晚 9 点

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

OOP with Java 通知 Project 4: 5 月 2 日晚 9 点

<4D F736F F F696E74202D20332D322E432B2BC3E6CFF2B6D4CFF3B3CCD0F2C9E8BCC6A1AAD6D8D4D8A1A2BCCCB3D0A1A2B6E0CCACBACDBEDBBACF2E707074>

SDK 概要 使用 Maven 的用户可以从 Maven 库中搜索 "odps-sdk" 获取不同版本的 Java SDK: 包名 odps-sdk-core odps-sdk-commons odps-sdk-udf odps-sdk-mapred odps-sdk-graph 描述 ODPS 基


Microsoft Word - 01.DOC

(TestFailure) JUnit Framework AssertionFailedError JUnit Composite TestSuite Test TestSuite run() run() JUnit

EJB-Programming-4-cn.doc

用手機直接傳值不透過網頁連接, 來當作搖控器控制家電 ( 電視遙控器 ) 按下按鍵發送同時會回傳值來確定是否有送出 問題 :1. 應該是使用了太多 thread 導致在傳值上有問題 2. 一次按很多次按鈕沒辦法即時反應

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

软件工程文档编制

untitled

Java

untitled

第四期:加强服务在内地港人及吸引人才

chp11.ppt

Microsoft Word - 第3章.doc

Chapter 9: Objects and Classes

使 用 Java 语 言 模 拟 保 险 箱 容 量 门 板 厚 度 箱 体 厚 度 属 性 锁 具 类 型 开 保 险 箱 关 保 险 箱 动 作 存 取 款

9, : Java 19., [4 ]. 3 Apla2Java Apla PAR,Apla2Java Apla Java.,Apla,,, 1. 1 Apla Apla A[J ] Get elem (set A) A J A B Intersection(set A,set B) A B A B

1.JasperReport ireport JasperReport ireport JDK JDK JDK JDK ant ant...6

OOP with Java 通知 Project 4: 5 月 2 日晚 9 点

PowerPoint 簡報

<4D F736F F D20AC4FBDBDA4FBB67DA96CAABA2DA743A67EAFC5AAA95FA7B9BD5A5F2E646F63>

ex

Java java.lang.math Java Java.util.Random : ArithmeticException int zero = 0; try { int i= 72 / zero ; }catch (ArithmeticException e ) { // } 0,

, 即 使 是 在 昏 暗 的 灯 光 下, 她 仍 然 可 以 那 么 耀 眼 我 没 有 地 方 去, 你 会 带 着 我 么 杜 晗 像 是 在 嘲 笑 一 般, 嘴 角 的 一 抹 冷 笑 有 着 不 适 合 这 个 年 龄 的 冷 酷 和 无 情, 看 着 江 华 的 眼 神 毫 无 温

javaexample-02.pdf

1.5招募说明书(草案)

PowerPoint Presentation

Swing-02.pdf

使用Cassandra和Spark 2.0实现Rest API服务

epub83-1

Microsoft PowerPoint - ch02

2009年9月全国计算机等级考试二级Java真题及答案

Microsoft Word - ch04三校.doc

JBuilder Weblogic

Microsoft PowerPoint - 14Threads.ppt


【主持人】:给大家介绍一下,这次的培训是我们画刊部的第三次培训,当然今天特别有幸请来著吊的摄影家李少白老师给我们讲课

chp6.ppt

附 件 :2015 年 度 普 通 高 等 学 校 本 科 专 业 备 案 和 审 批 结 果 教 育 部 2016 年 2 月 16 日 抄 送 : 国 家 发 展 改 革 委 财 政 部 国 家 卫 生 计 生 委 国 家 中 医 药 管 理 局 部 内 发 送 : 有 关 部 领 导, 办 公

Copyright 2007 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. 版 權 所 有 Sun Microsystems, Inc. 對 本 文 件 所 述 產 品 所 採 用

JavaIO.PDF

untitled

任務二 : 產生 20 個有炸彈的磚塊, 放在隨機的位置編輯 Block 類別的程式碼 import greenfoot.; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) Write a description of class

1: public class MyOutputStream implements AutoCloseable { 3: public void close() throws IOException { 4: throw new IOException(); 5: } 6:

拦截器(Interceptor)的学习

untitled

untitled

无类继承.key

MIDP 学习笔记

PowerPoint Presentation

没 有 多 余 的 Contruol 或 Action 了 原 来 Domain 层 被 服 务 层 Service layer 遮 挡, 在 右 边 图 中, 则 Domain 层 直 接 暴 露 给 前 台 了, 没 有 被 遮 挡, 裸 露 了 这 样 一 步 到 位 实 现 领 域 模 型

Java Access 5-1 Server Client Client Server Server Client 5-2 DataInputStream Class java.io.datainptstream (extends) FilterInputStream InputStream Obj

mvc

EJB-Programming-3.PDF

untitled

Microsoft Word - 新1-12.doc

建模与图形思考

untitled

RxJava

计 算 机 系 统 应 用 年 第 25 卷 第 4 期 线 程 的 复 用 [2,3]. 通 常 情 况 下, 服 务 器 端 程 序 在 启 动 时 创 建 若 干 数 量 的 线 程 对 象 并 缓 存 起 来, 此 时 它 们 处 于

Microsoft PowerPoint - L17_Inheritance_v4.pptx

内 容 简 介 本 书 是 一 本 关 于 语 言 程 序 设 计 的 教 材, 涵 盖 了 语 言 的 基 本 语 法 和 编 程 技 术, 其 中 包 含 了 作 者 对 语 言 多 年 开 发 经 验 的 总 结, 目 的 是 让 初 学 的 读 者 感 受 到 语 言 的 魅 力, 并 掌

1 1 大概思路 创建 WebAPI 创建 CrossMainController 并编写 Nuget 安装 microsoft.aspnet.webapi.cors 跨域设置路由 编写 Jquery EasyUI 界面 运行效果 2 创建 WebAPI 创建 WebAPI, 新建 -> 项目 ->

手机游戏的图形设计与动画制作

在 ongodb 中实现强事务

雲端 Cloud Computing 技術指南 運算 應用 平台與架構 10/04/15 11:55:46 INFO 10/04/15 11:55:53 INFO 10/04/15 11:55:56 INFO 10/04/15 11:56:05 INFO 10/04/15 11:56:07 INFO

《大话设计模式》第一章


J2ME.PDF

D getinitparameternames() 9 下 列 选 项 中, 属 于 Servlet API 中 提 供 的 request 对 象 的 包 装 类 的 是 ( ) A HttpServletRequestWrapper B HttpServletRequest C HttpServ

untitled

主程式 : public class Main3Activity extends AppCompatActivity { ListView listview; // 先整理資料來源,listitem.xml 需要傳入三種資料 : 圖片 狗狗名字 狗狗生日 // 狗狗圖片 int[] pic =new

2 Java 语 言 程 序 设 计 教 程 简 单 性 Java 语 言 的 语 法 与 C 语 言 和 C++ 语 言 很 接 近, 使 得 大 多 数 程 序 员 很 容 易 学 习 和 使 用 Java 另 一 方 面,Java 丢 弃 了 C++ 中 很 少 使 用 的 很 难

OOP with Java 通知 Project 3 提交时间 3 月 29 日晚 9 点 Piazza Project 2 投票

Spyder Anaconda Spyder Python Spyder Python Spyder Spyder Spyder 開始 \ 所有程式 \ Anaconda3 (64-bit) \ Spyder Spyder IPython Python IPython Sp

Microsoft Word - JAVA Programming Language Homework VI_ans.doc

提纲 1 2 OS Examples for 3

第一章 概论

Microsoft PowerPoint - plan08.ppt

c_cpp

第一章

穨文件1

Microsoft Word - Broker.doc

VB程序设计教程

Android Service

新版 明解C++入門編

untitled

Adobe® Flash® 的 Adobe® ActionScript® 3.0 程式設計

Learning Java

(6) 要 求 付 款 管 理 员 从 预 订 表 中 查 询 距 预 订 的 会 议 时 间 两 周 内 的 预 定, 根 据 客 户 记 录 给 满 足 条 件 的 客 户 发 送 支 付 余 款 要 求 (7) 支 付 余 款 管 理 员 收 到 客 户 余 款 支 付 的 通 知 后, 检

Transcription:

高级用户界面与多线程

LCDUI 高级 LCDUI

LCDUI 与多线程 多线程在手机编程中尤为重要 手机游戏开发中, 通常由游戏主线程负责游戏的基本控制, 除此之外还会由一个或者多个线程用于播放背景音乐或声效 网络接受数据时, 传输速度通常都比较慢, 因此可以使用一个独立的线程负责接收数据, 另外一个线程负责 UI 界面和与用户的交互

LCDUI 与多线程 J2ME 是通过线程体来实现多线程的 线程体就是用于实现线程活动的主体, 由 run() 方法来实现 实现线程体的方法主要有 : (1) 通过继承 Thread 类构造线程体 (2) 通过实现 Runnable 接口构造线程体

LCDUI 与多线程 Thread 类 除了实现 Runnable 接口外,CLDC 包中还提供了通过继承 Thread 类来实现线程的方法, Thread 类直接继承了 Object 类, 可以用来实现一个具体的线程 构造方法 Thread(); Thread(String name); Thread(Runnable target); Thread(Runnable target, String name);

LCDUI 与多线程 Thread 类 主要方法 start(), 启动线程并转入就绪状态 run() 定义线程被调度之后所执行的动作, 系统自动调用, 用户不得引用, 由于 Thread 类的 run() 方法没有具体的内容, 所以用户需要创建 Thread 类的子类, 并定义新的 run() 方法 sleep(): 通常在 run() 方法中调用 sleep() 方法使自己放弃 CPU 资源 要停止线程往往通过标识符实现

LCDUI 与多线程 Thread 类 import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class mymidlet extends MIDlet{. public void startapp(){. ThreadDemo th = new ThreadDemo(); th.start();. // 添加类中类 public class ThreadDemo extends Thread{ public void run() {

LCDUI 与多线程 Runnable 接口 创建一个线程时必须实现 Runnable 接口, Runnable 接口为实现多线程提供了通用的协议, 使得对象被激活时可自动执行特定代码 实现 Runnable 接口必须实现其中的 run() 方法,run() 方法是线程的主体,Run() 方法中通常使用 sleep() 方法使线程 适当 休息, 为其它线程让出 CPU 资源

LCDUI 与多线程 Runnable 接口 import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class mymidlet extends MIDlet{. public void startapp(){. Thread th = new Thread(new RunnableDemo()); th.start();. // 添加类中类 public class RunnableDemo implements Runnable{ public void run() {

LCDUI 与多线程 Runnable 接口 import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class mymidlet extends MIDlet implements Runnable{. public void startapp(){. Thread th = new Thread(this); th.start();. // 重写 run() public void run() {

实例 1 在控制台循环打印字符串 hello 和 others

实例 1 public class mymidlet extends MIDlet { private Display dis; private Form fm = new Form("test"); public void startapp() { dis = Display.getDisplay(this); dis.setcurrent(fm); mythread mt1 = new mythread(); Thread mt2 = new Thread(new myrunable()); mt1.start(); mt2.start();

实例 1 public class mythread extends Thread { public void run(){ while(true){ System.out.println("hello"); Thread.sleep(1000); public class myrunnable implements Runnable { public void run(){ while(true){ System.out.println( others"); Thread.sleep(1000);

实例 2 实例 2: 界面上有 1 个 StringItem, 要求它上面的数字每隔 1 秒钟变化

public class MidletString extends MIDlet { private Display dis; private Form fm = new Form("String test"); private StringItem si = new StringItem("String1",""); int i=0; public void startapp() { dis = Display.getDisplay(this); dis.setcurrent(fm); fm.append(si); mythread th = new mythread(); th.start(); class mythread extends Thread{ public void run(){ while(true){ si.settext(integer.tostring(i)); i++; try{ Thread.sleep(1000); catch(exception ex){

实例 3 实例 3: 界面上有 2 个 StringItem, 要求第一个上面的数字每隔 1 秒钟变化, 第二个上面的数字每隔 2 秒钟变化

public class MidletString extends MIDlet { private Display dis; private Form fm = new Form("String test"); private StringItem si1 = new StringItem("String1",""); private StringItem si2 = new StringItem("String2",""); public void startapp() { dis = Display.getDisplay(this); dis.setcurrent(fm); fm.append(si1); fm.append(si2); mythread1 th1 = new mythread1(); th1.start(); Thread th2 = new Thread(new mythread2()); th2.start(); System.out.println("other things");

class mythread1 extends Thread{ private int i=0; public void run(){ while(true){ si1.settext(integer.tostring(i)); i++; try{ Thread.sleep(1000); catch(exception ex){ class mythread2 implements Runnable{ private int i=0; public void run(){ while(true){ si2.settext(integer.tostring(i)); i++; try{ Thread.sleep(2000); catch(exception ex){

实例 4 秒表

public class midlet2 extends MIDlet implements CommandListener { private Display dis; private Form frm; private Command exit,ok,exitwatch,start,stop; private Watch watch; public midlet2() { frm=new Form(" 秒表 "); exit=new Command("exit",Command.EXIT,1); ok=new Command("ok",Command.OK,1); exitwatch=new Command("exitwatch",Command.CANCEL,1); start=new Command("start",Command.OK,1); stop=new Command("stop",Command.STOP,1); protected void startapp(){ dis=display.getdisplay(this); dis.setcurrent(frm); frm.addcommand(exit); frm.addcommand(ok); frm.setcommandlistener(this); frm.append(" 争分夺秒 ");

public void commandaction(command c, Displayable d){ String str=c.getlabel(); if(str.equals("ok")){ watch=new Watch(); watch.addcommand(exitwatch); watch.addcommand(start); watch.setcommandlistener(this); dis.setcurrent(watch); else if(str.equals("start")){ watch.removecommand(start); watch.addcommand(stop); watch.startwatch(); else if(str.equals("stop")){ watch.removecommand(stop); watch.addcommand(start); watch.stop(); else if(str.equals("exitwatch")){ dis.setcurrent(frm); else if(str.equals("exit")){ this.notifydestroyed();

public class Watch extends Form implements Runnable { private TextField text; private boolean flag; private int count=-1; public Watch() { super(""); flag=true; text=new TextField("","",50,TextField.UNEDITABLE); this.append(text); public void startwatch(){ flag=true; text.setstring(""); Thread th = new Thread(this); th.start(); public void stop(){ flag=false;

public void run(){ while(true){ if(flag){ count++; try{ int ms=count%10; int s=count/10%60; int m = s/60%60; int h =m/60; text.setstring(h+""+m+""+s+""+ms); Thread.sleep(100);catch(Exception e){ else break;