0

我正在制作一个 lwuit 应用程序。我希望在其中使用索引。

例如。如何在 LWUIT 中显示 2(raise to)3?有什么办法吗?

4

1 回答 1

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);
       ...
    }
    ...
}
于 2012-04-16T08:04:25.653 回答