📄 midlet4.java
字号:
package prj9_1;
/*
* 界面上有两个StringItem,要求第一个上面的数字每隔1秒钟变化,第二个上面的数字每隔两秒钟变化
* */
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class MIDlet4 extends MIDlet {
private Form frm = new Form("这是一个线程测试");
private StringItem si1 = new StringItem("StringItem1:","");
private StringItem si2 = new StringItem("StringItem2:","");
private Display dis;
protected void startApp() throws MIDletStateChangeException {
dis = Display.getDisplay(this);
dis.setCurrent(frm);
frm.append(si1);
frm.append(si2);
new Thread1().start();
new Thread(new Thread2()).start();
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
class Thread1 extends Thread{
private int i=1;
public void run(){
while(true){
si1.setText(Integer.toString(i));
i++;
try{
Thread.currentThread().sleep(1000);
}catch(Exception ex){}
}
}
}
class Thread2 implements Runnable{
private int i=1;
public void run(){
while(true){
si2.setText(Integer.toString(i));
i++;
try{
Thread.currentThread().sleep(2000);
}catch(Exception ex){}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -