LWUIT 1.4:为什么此 TextArea 中有时会出现重复项?

发布于 2024-12-21 01:35:31 字数 2020 浏览 3 评论 0原文

我从 Dialog 创建了一个类,其中包含一个 TextArea :

public class Alert extends Dialog {
    private Container c = new Container(new BorderLayout());
    private Label titre = new Label("Mobile Banking");
    private TextArea chp;
    private Command[] comms;
    public Alert(String text, Command[] comms)
    {
        super();
        titre.setUIID("titre_alert");
        titre.setAlignment(Label.CENTER);
        this.comms = comms;
        setAutoDispose(true);
        for (int cmd=0; cmd<comms.length; cmd++)
            addCommand(comms[cmd]);
        chp = new TextArea();
        chp.setEditable(false);
        chp.setAlignment(Label.CENTER);
        chp.getSelectedStyle().setBorder(null);
        chp.getUnselectedStyle().setBorder(null);
        chp.getSelectedStyle().setBgColor(this.getStyle().getBgColor());
        chp.getUnselectedStyle().setBgColor(this.getStyle().getBgColor());
        if (text.length() % 2 != 0)
            text = " ".concat(text);
        while (text.substring(0, (text.length()/2)+1).length() < chp.getMaxSize()/2)
        {
            text = " ".concat(text);
        }
        chp.setText(text);
        c.addComponent(BorderLayout.NORTH, titre);
        c.addComponent(BorderLayout.CENTER, chp);
    }
    public Command affiche()
    {
        return show(null, c, comms);
    }
}

在表单内,我启动一个线程来进行 HttpConnection 调用和其他任务。如果任务成功结束,那么我调用上述类 Alertaffiche() 方法:

alert = new Alert("Chargement effectué avec succès !", new Command[]{ok});
cntnr.removeComponent(cPatienter); // container displaying the "please wait..."
repaint(); // repainting the Form
if (alert.affiche() == ok) // showing the confirmation of successfullness of the task
{
     alert.dispose();
     controller.displayScreen("Menuprincipale");
}

问题是,有时,调用 affiche 时显示的文本() 方法是重复的:它应该只显示文本 Chargementeffectué avec succès! 但有时它会显示文本和 Chargementeffectué

那么如何做到只显示文本参数而不重复呢?

I created a class from Dialog which contains a TextArea :

public class Alert extends Dialog {
    private Container c = new Container(new BorderLayout());
    private Label titre = new Label("Mobile Banking");
    private TextArea chp;
    private Command[] comms;
    public Alert(String text, Command[] comms)
    {
        super();
        titre.setUIID("titre_alert");
        titre.setAlignment(Label.CENTER);
        this.comms = comms;
        setAutoDispose(true);
        for (int cmd=0; cmd<comms.length; cmd++)
            addCommand(comms[cmd]);
        chp = new TextArea();
        chp.setEditable(false);
        chp.setAlignment(Label.CENTER);
        chp.getSelectedStyle().setBorder(null);
        chp.getUnselectedStyle().setBorder(null);
        chp.getSelectedStyle().setBgColor(this.getStyle().getBgColor());
        chp.getUnselectedStyle().setBgColor(this.getStyle().getBgColor());
        if (text.length() % 2 != 0)
            text = " ".concat(text);
        while (text.substring(0, (text.length()/2)+1).length() < chp.getMaxSize()/2)
        {
            text = " ".concat(text);
        }
        chp.setText(text);
        c.addComponent(BorderLayout.NORTH, titre);
        c.addComponent(BorderLayout.CENTER, chp);
    }
    public Command affiche()
    {
        return show(null, c, comms);
    }
}

Inside a Form I start a thread which makes a HttpConnection call and other tasks. If the tasks end successfully then I call the affiche() method of the above class Alert :

alert = new Alert("Chargement effectué avec succès !", new Command[]{ok});
cntnr.removeComponent(cPatienter); // container displaying the "please wait..."
repaint(); // repainting the Form
if (alert.affiche() == ok) // showing the confirmation of successfullness of the task
{
     alert.dispose();
     controller.displayScreen("Menuprincipale");
}

The problem is that , sometimes , the text shown when calling the affiche() method is duplicated : it should show only the text Chargement effectué avec succès ! but sometimes it shows the text and also Chargement effectué.

So how to make it that only the text parameter is only shown but not duplicated ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩人痒 2024-12-28 01:35:31

您在单独的线程上调用 LWUIT,这是非法的。您需要使用 Display.callSerially 来避免文本布局代码中的竞争条件。像这样的事情:

Display.getInstance().callSerially(new Runnable() {
   public void run() {
       // your LWUIT code here, no need for repaints 
   }
});

更好的方法是使用 LWUIT4IO 进行网络连接,因为它可以无缝地为您完成此操作。

You are invoking LWUIT on a separate thread which is illegal. You need to use Display.callSerially to avoid a race condition in the text layout code. Something like this:

Display.getInstance().callSerially(new Runnable() {
   public void run() {
       // your LWUIT code here, no need for repaints 
   }
});

A better approach is to use LWUIT4IO for your networking since it does this seamlessly for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文