2011-11-12 97 views
1

我有很多內容和所有內容,如LabelfieldButtonfieldBitmapfield等。獲取黑莓主屏幕中buttonfield的XY座標

所有這些內容加入MainScreen

我想從屏幕上獲得特定的Buttonfield XY位置。
我已經嘗試buttonField.getContentTop();,但我越來越0

所以,我怎樣才能獲得黑莓的主屏幕ButtonField字段的XY座標?

回答

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()); 
    } 

}