向BlackBerry PopUp屏幕添加字段

向BlackBerry PopUp屏幕添加字段,blackberry,java-me,Blackberry,Java Me,我想在BlackBerry中添加字段和按钮。您想像这样自定义弹出屏幕吗 public class CustomPopUpScreen extends PopupScreen { public CustomPopUpScreen() { super(new VerticalFieldManager(CustomPopUpScreen.NO_HORIZONTAL_SCROLL)); add(new ButtonField()); add(new

我想在BlackBerry中添加字段和按钮。

您想像这样自定义弹出屏幕吗

public class CustomPopUpScreen extends PopupScreen {
    public CustomPopUpScreen() {
        super(new VerticalFieldManager(CustomPopUpScreen.NO_HORIZONTAL_SCROLL));
        add(new ButtonField());
        add(new ButtonField());
    }
}

此代码将帮助您

在这里,我创建类型为
PopupScreen
的对象,并调用方法
givePopup

PopupScreen popup1=givePopup();
PopupScreen givePopup(){
    VerticalFieldManager popvfm =new VerticalFieldManager();
    ButtonField ok=new ButtonField("ok");
    ButtonField cancel=new ButtonField("cancel");
    popvfm.add(ok);
    popvfm.add(cancel);
    PopupScreen popup=new PopupScreen(popvfm);
    return popup;
}
此方法返回一个
PopupScreen
实例,该实例有一个垂直字段管理器,我在此管理器上添加了两个按钮字段

public class FriendPopupScreen extends MainScreen{
    int dialogWidth;
    int dialogHeight;
    LabelField lblTitle;

    HorizontalFieldManager hfmTitle;

    Vector data;

    public FriendPopupScreen() {

        dialogWidth = 300;
        dialogHeight = 150;

        lblTitle = newLabelField("Choose option");

        hfmTitle = new HorizontalFieldManager(USE_ALL_WIDTH){

            protected void sublayout(int maxWidth, int maxHeight) {
                // TODO Auto-generated method stub
                maxWidth= Display.getWidth();
                maxHeight=40;
                super.sublayout(maxWidth, maxHeight);
                setExtent(maxWidth, maxHeight);
            }

            protected void paint(Graphics graphics) {
                // TODO Auto-generated method stub

                graphics.setBackgroundColor(Color.BLACK);
                graphics.clear();
                super.paint(graphics);
            }

        };

        hfmTitle.add(lblTitle);
        lblTitle.setMargin(10,0,0,10);
        add(hfmTitle);
    }
     protected void sublayout( int width, int height ) {
            setExtent( dialogWidth, dialogHeight );
            setPosition( Display.getWidth()/2-(dialogWidth/2), Display.getHeight()/2 - (dialogHeight/2));
            layoutDelegate( dialogWidth, dialogHeight );
        }
}
并称之为:

FriendPopupScreen popup = new FriendPopupScreen();
UiApplication.getUiApplication().pushModalScreen(popup);