0

I am making a lwuit app. and i wish to use indices in it.

For eg. how can i show 2(raise to)3 in LWUIT? Is there any way to do it?

Nikhil
  • 1,279
  • 2
  • 23
  • 43

1 Answers1

4

Create a class deriving Container containing the base expression, in your example it is 2, and the power ( here 3 ) :

public class Power extends Container {
    private Label pow = new Label(), base = new Label();
    public Power(String base, String power)
    {
        super(new BoxLayout(BoxLayout.Y_AXIS));
        getStyle().setPadding(0, 0, 0, 0);
        this.base.setText(base);
        String temp = "";
        while (temp.length() < base.length())
        {
            temp = temp.concat(" ");
        }
        temp = temp.concat(power);
        pow.setText(temp);
        pow.setTextPosition(Label.BOTTOM);
        Font font = Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
        pow.getStyle().setFont(font, false);
        pow.getStyle().setPadding(Component.BOTTOM, 0, false);
        pow.getStyle().setMargin(Component.BOTTOM, 0, false);
        this.base.getStyle().setMargin(Component.TOP, 0, false);
        addComponent(pow);
        addComponent(this.base);
    }
}

Then instanciate it in your Form and add it ( addComponent ) :

public class yourForm extends Form
{
    ...
    private Power expr = new Power("2","3");
    ...
    public yourForm()
    {
       ...
       addComponent(expr);
       ...
    }
    ...
}
pheromix
  • 18,213
  • 29
  • 88
  • 158