0

我正在处理以下代码,它有一个带有 6 个按钮的欢迎表单。

单击每个按钮时,它会打开一个新表单。

   class MyAPP extends UiApplication {
    public static void main(String[] args) {
            UiApplication instance = new MyAPP();
            instance.enterEventDispatcher();
    }
    private ButtonField btntest,btntest1,btntest2,btntest3,btntest4,btntest5;
    public MyAPP() {

            MainScreen testScreen = new MainScreen();


            final LabelField field  = new LabelField("Company",LabelField.FIELD_HCENTER | LabelField.NON_FOCUSABLE)
    {
        protected void paint(Graphics g)
            {       
                     g.clear();
                    g.drawRect(0,0, 50, 50);
                    int oldColor = g.getColor();
                    g.setColor(Color.DODGERBLUE);
                    g.fillRect(0, 0, this.getPreferredWidth(), this.getPreferredHeight());
                    g.setColor(oldColor);
                    g.drawRect(100, 100, 50, 50);
                    super.paint(g);
             }
    };
    testScreen.setTitle(field);


    //Add status field to bottom of screen in blue color

    final LabelField field1  = new LabelField(" Copyright")
    {
        protected void paint(Graphics g)
            {       
                  //   g.clear();
                    g.drawRect(0,0, 50, 50);
                    int oldColor = g.getColor();
                    g.setColor(Color.DODGERBLUE);
                    g.fillRect(0, 0, this.getPreferredWidth(), this.getPreferredHeight());
                    g.setColor(oldColor);
                    g.drawRect(100, 100, 50, 50);
                    super.paint(g);
             }

    };
    //field1.setFontColor(Color.WHITE);

        btntest1 = new ButtonField("Customer",ButtonField.FIELD_HCENTER | ButtonField.CONSUME_CLICK);  
        btntest = new ButtonField("Bills  ",ButtonField.FIELD_HCENTER | ButtonField.CONSUME_CLICK);
        btntest2 = new ButtonField("Ledger ",ButtonField.FIELD_HCENTER | ButtonField.CONSUME_CLICK); 
        btntest3 = new ButtonField("Receipts",ButtonField.FIELD_HCENTER | ButtonField.CONSUME_CLICK);


         btntest1.setChangeListener(new FieldChangeListener()
      {
           public void fieldChanged(Field field,int context) 
           {
              pushScreen(new NextScreen2());
           }
      });




     btntest.setChangeListener(new FieldChangeListener()
      {
           public void fieldChanged(Field field,int context) 
           {
              pushScreen(new NextScreen1());
           }
      });


      btntest2.setChangeListener(new FieldChangeListener()
      {
           public void fieldChanged(Field field,int context) 
           {
              pushScreen(new NextScreen4());
           }

      });

我也尝试过放置一个位于表单中心的图像位图,但它不会出现在任何地方。

在当前代码中,我添加了标题和状态字段,并且还添加了

  1. 带有欢迎标题的屏幕顶部的图像。
  2. 有 6 个按钮居中对齐。

是不是因为按钮在中心并且没有空间让颜色实现不可见?而且我无法添加一个作为整个表单背景的图像。任何知道解决方案的人请指导。谢谢

4

1 回答 1

2

试试下面的代码:

// initialize background
Bitmap bm = Bitmap.getBitmapResource("myImage");
Background bg = BackgroundFactory.createBitmapBackground(bm);

// getMainManager(), apply background
testScreen.getMainManager().setBackground(bg);
于 2012-05-12T17:36:07.940 回答