我想了解J2ME代碼告訴我這段代碼會發生什麼?
Thread aaa = new Thread(pb) { private final ProgressBar val$pb;
public void run() { while (this.val$pb.getValue() < 100) {
try {
this.val$pb.setValue(this.val$pb.getValue() + 1);
Thread.sleep(10L); } catch (InterruptedException ex) {
}
this.val$pb.repaint();
}
mainForm.homeScreen = new HomeScreen();
mainForm.homeScreen.show();
}
};
aaa.start();
請告訴我這是什麼pb
在Thread
構造函數來完成。如果我將new Thread(pb)
更改爲new Thread()
,此代碼的外觀如何?它會影響val$pb
?上面的代碼無法編譯,所以我編輯這樣
Thread aaa = new Thread() { private final ProgressBar val=null ;//new Thread(pb) ProgressBar val$pb;
public void run() { try {while (this.val.getValue() < 100) { //try added by me
try {
this.val.setValue(this.val.getValue() + 1);
Thread.sleep(10L); } catch (InterruptedException ex) {
}
this.val.repaint(); //draws progress bar as a loading screen before showing home screen
}
}catch(Exception e){
mainForm.homeScreen = new HomeScreen();
mainForm.homeScreen.show(); // draws home screen
}
}
};
aaa.start();
編輯: - 它使用J4ME library。
對於您自己運行代碼並進行這些更改並查看會發生什麼,可能是最容易的。 – Spags 2012-02-20 17:00:51