LWUIT按钮问题

发布于 2024-12-17 12:36:12 字数 1866 浏览 4 评论 0原文

    import com.sun.lwuit.Button;
    import com.sun.lwuit.Command;
    import com.sun.lwuit.Display;
    import com.sun.lwuit.Label;
    import com.sun.lwuit.events.ActionEvent;
    import com.sun.lwuit.events.ActionListener;
    import com.sun.lwuit.layouts.BorderLayout;
    import com.sun.lwuit.plaf.UIManager;
    import com.sun.lwuit.util.Resources;
    import java.io.IOException;


    public class Ruwwa extends javax.microedition.midlet.MIDlet implements ActionListener{

    Form f;
    Button mybutton1;
    Button mybutton2;
    Command exit;
    Command ok;


    public void startApp() {

           Display.init(this);

           f = new Form();

           try {

           Resources r = Resources.open("/mairuwa.res");
           UIManager.getInstance().setThemeProps(r.getTheme("Mairuwa Theme"));

           } catch (IOException ioe) {
             ioe.printStackTrace();
           }

           mybutton1=new Button("Report A Problem");
           mybutton2=new Button("Request Info");

           f.setLayout(new BorderLayout());
           f.addComponent(BorderLayout.CENTER, new Label("The Mairuwa Portal"));

           ok = new Command("OK");
           exit = new Command("Exit");

           f.addCommand(ok);
           f.addCommand(exit);
           f.addCommandListener(this);

           f.show();

           }

    public void pauseApp() {}

    public void destroyApp(boolean unconditional) {}

    public void actionPerformed(ActionEvent ae) {
       notifyDestroyed();
    }

}

我想在“The Mairuwa Portal”下添加另一个标签,并在其下方放置两个按钮(“报告问题”、“请求信息”)。我所描述的内容的一个例子是

label:                          The Mairuwa Portal
then another label beneath it:  I want to:

然后这个按钮下面的两个按钮:报告问题按钮:请求信息

我已经能够向项目添加“确定”和“退出”按钮,但是我谈到的上面的按钮应该如我所描述的那样。

这些按钮将承载功能。我希望这可以在 LWUIT 中完成。

    import com.sun.lwuit.Button;
    import com.sun.lwuit.Command;
    import com.sun.lwuit.Display;
    import com.sun.lwuit.Label;
    import com.sun.lwuit.events.ActionEvent;
    import com.sun.lwuit.events.ActionListener;
    import com.sun.lwuit.layouts.BorderLayout;
    import com.sun.lwuit.plaf.UIManager;
    import com.sun.lwuit.util.Resources;
    import java.io.IOException;


    public class Ruwwa extends javax.microedition.midlet.MIDlet implements ActionListener{

    Form f;
    Button mybutton1;
    Button mybutton2;
    Command exit;
    Command ok;


    public void startApp() {

           Display.init(this);

           f = new Form();

           try {

           Resources r = Resources.open("/mairuwa.res");
           UIManager.getInstance().setThemeProps(r.getTheme("Mairuwa Theme"));

           } catch (IOException ioe) {
             ioe.printStackTrace();
           }

           mybutton1=new Button("Report A Problem");
           mybutton2=new Button("Request Info");

           f.setLayout(new BorderLayout());
           f.addComponent(BorderLayout.CENTER, new Label("The Mairuwa Portal"));

           ok = new Command("OK");
           exit = new Command("Exit");

           f.addCommand(ok);
           f.addCommand(exit);
           f.addCommandListener(this);

           f.show();

           }

    public void pauseApp() {}

    public void destroyApp(boolean unconditional) {}

    public void actionPerformed(ActionEvent ae) {
       notifyDestroyed();
    }

}

I would like to add another label under the "The Mairuwa Portal" and also place two buttons("Report A Problem","Request Information") beneath this as well. An illustration of what i am describing is

label:                          The Mairuwa Portal
then another label beneath it:  I want to:

Then two buttons beneath this Button:Report Problem Button: Request Information

I have been able to add OK and EXIT button to the project,but this above buttons i talked about should as I described.

These buttons will carry functionality. I hope this can be done in LWUIT.

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

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

发布评论

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

评论(1

倾城月光淡如水﹏ 2024-12-24 12:36:12

很简单。将 BoxLayout.Y_AXIS 用于 Form 并将标签添加到表单。使用 BoxLayout.Y_AXIS (或 x_AXIS,根据您的需要)创建 Container 并将按钮添加到此 Container并设置Container的边距。请参阅示例代码了解如何操作,

Form form = new Form("form");
form.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
Label label1 = new Label("Label 1");
Label label2 = new Label("Label 2");
form.addComponent(label1);
form.addComponent(label2);
Container c = new Container(new BoxLayout(BoxLayout.X_AXIS));
int center = Display.getInstance().getDisplayWidth()/2;
c.getStyle().setMargin(0, 0, center , 0);    
Button b1 = new Button("button 1");
Button b2 = new Button("button 2");
c.addComponent(b1);
c.addComponent(b2);
form.addComponent(c);
form.show();

It just simple. Use the BoxLayout.Y_AXIS for Form and add the labels to the form. Create the Container with BoxLayout.Y_AXIS (or x_AXIS, Its your needs) and add the buttons to this Container and set the margin for the Container. See the sample code for how to do,

Form form = new Form("form");
form.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
Label label1 = new Label("Label 1");
Label label2 = new Label("Label 2");
form.addComponent(label1);
form.addComponent(label2);
Container c = new Container(new BoxLayout(BoxLayout.X_AXIS));
int center = Display.getInstance().getDisplayWidth()/2;
c.getStyle().setMargin(0, 0, center , 0);    
Button b1 = new Button("button 1");
Button b2 = new Button("button 2");
c.addComponent(b1);
c.addComponent(b2);
form.addComponent(c);
form.show();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文