1
    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.

bharath
  • 14,283
  • 16
  • 57
  • 95
fyzil
  • 25
  • 1
  • 4
  • I can't understand your question. What is the exact issue? – bharath Nov 22 '11 at 10:00
  • The issue is i dont know how to add another label under the first label "The Mairuwa Portal",and i also dont know how to centralize the buttons "Report Problem" and "Request Information".i hope this makes u understand better.thanks for the help – fyzil Nov 22 '11 at 10:24
  • You need to master LWUIT layouts. There are BoxLayout which can be X or Y based, there are also gridlayout. You can nest these layouts by using `Container` ! Look at the javadoc ! – pheromix Nov 22 '11 at 10:32

1 Answers1

1

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();
bharath
  • 14,283
  • 16
  • 57
  • 95