日期:2014-05-20 浏览次数:20754 次
import javax.microedition.lcdui.*; public class ThreadWait implements Runnable { private int sec; private Form form; private String msg; public ThreadWait(int sec, Form form, String msg) { this.sec = sec; this.form = form; this.msg = msg; new Thread(this).start(); } public void run() { try { if (form != null) { Gauge gauge = new Gauge(msg, false, 100, Gauge.CONTINUOUS_IDLE); form.append(msg); int k = form.append(gauge); while (gauge.getValue() != gauge.getMaxValue()) { gauge.setValue(gauge.getValue() + 1); Thread.sleep(10 * sec); } form.delete(k); } } catch (Exception e) { System.out.println(e); } } }
------解决方案--------------------
package prj10_2;
import javax.microedition.lcdui.*
public class frm_MIDLet1 extends Form implements CommandListener,
ItemStateListener, ItemCommandListener {
private static frm_MIDLet1 frm;
private TextField tf_id = new TextField("用户名", "", 20, TextField.ANY);
private TextField tf_pw = new TextField("密 码", "", 20, TextField.NUMERIC
| TextField.PASSWORD);
private Command Cmd_login = new Command("登陆", Command.SCREEN, 1);
private Command Cmd_del = new Command("删除", Command.BACK, 1);
public frm_MIDLet1() {
super("登陆界面");
frm = this;
this.append(tf_id);
this.append(tf_pw);
this.addCommand(Cmd_login);
this.setCommandListener(this);
this.setItemStateListener(this);
}
public void commandAction(Command c, Displayable d) {
if (c == Cmd_login) {
Gauge g = new Gauge("登陆验证", false, 100, 0);
frm.append(g);
thread_gauge tg = new thread_gauge(g);
tg.start();
try {
tg.join();
} catch (Exception ex) {
ex.printStackTrace();
}
System.out.println("验证完毕");
}
}
public void commandAction(Command c, Item i) {
TextField tf = (TextField) i;
int p = tf.getCaretPosition();