在Blackberry的主屏幕中获取按钮字段的XY坐标

时间:2011-11-12 09:03:16

标签: blackberry field coordinate-transformation

我有很多内容和所有内容,例如Labelfield ButtonfieldBitmapfield等等。

所有这些内容都添加到MainScreen

我想从此屏幕获取特定的Buttonfield XY位置 我已经尝试了buttonField.getContentTop();,但我得到了0。

那么,如何在Blackberry主屏幕中获取按钮区域的XY坐标?

1 个答案:

答案 0 :(得分:1)

package mypackage;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;

public class sample extends MainScreen implements FieldChangeListener
{
    ButtonField click;
    LabelField x,y;
    public sample()
    {  

    x=new LabelField("Left(x) position: ");
    add(x);
    y=new LabelField("right(y) position: ");
    add(y);
    click=new ButtonField("Get My Positions",Field.FOCUSABLE);
    click.setChangeListener(this);
    add(click);
    }
    public void fieldChanged(Field field, int context) {
        System.out.println("============================"+click.getLeft()+"     "+click.getTop());
        x.setText("Left(x) position: "+click.getLeft());
        y.setText("right(y) position: "+click.getTop());
    }

}