首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LWUIT按钮问题

LWUIT按钮问题
EN

Stack Overflow用户
提问于 2011-11-22 17:17:49
回答 1查看 514关注 0票数 1
代码语言:javascript
复制
    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();
    }

}

我想在“Mairuwa Portal”下面添加另一个标签,并在下面放置两个按钮(“Report A Problem","Request Information")。下面是我所描述的内容的一个示例

代码语言:javascript
复制
label:                          The Mairuwa Portal
then another label beneath it:  I want to:

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

我已经能够添加OK和退出按钮到项目中,但上面我所说的按钮应该如我所描述的那样。

这些按钮将提供功能。我希望这可以在LWUIT完成。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-11-22 19:17:01

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

代码语言:javascript
复制
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();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8224391

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档