UI インタラクションを管理する 3 つの方法の違いを理解しようとしています。
実際のケースでそれらを理解しようとするとき、私はこれらの3つの用語と本当に混乱しています.
以下のコードは、invokeAndWait メソッドの機能を示していますが、invokeLater または getEventLock() に置き換えると、プログラムはまったく同じように動作します。
UI を更新するための 3 つの方法の違いを示すために、コードを修正していただけませんか?
public final class HelloWorldMainScreen extends MainScreen
{
private LabelField labelField;
public HelloWorldMainScreen()
{
labelField = new LabelField("Hello World");
add(labelField);
MainScreenUpdaterThread thread = new MainScreenUpdaterThread(this);
thread.start();
}
public void appendLabelText(String text){
labelField.setText(labelField.getText()+"\n"+text);
}
}
public class MainScreenUpdaterThread extends Thread {
HelloWorldMainScreen mainScreen;
public MainScreenUpdaterThread(HelloWorldMainScreen mainScreen){
this.mainScreen = mainScreen;
}
public void run(){
for (int i = 0; i < 10; i++) {
try{
Thread.sleep(5000);
}catch(InterruptedException ex){};
UiApplication.getUiApplication().invokeAndWait(new Runnable() {
public void run() {
mainScreen.appendLabelText("Update");
}
});
}
}
}
これらの 3 つの概念は、多くの初心者にとって非常に紛らわしいので、それらの機能を説明する説明的なソース コードは誰にとっても非常に役立つと思います。
前もって感謝します!