黑莓中的自定义对话框

时间:2011-05-27 10:00:34

标签: blackberry-jde

如何创建自定义对话框并将侦听器添加到blackberry

对话框中的按钮

1 个答案:

答案 0 :(得分:5)

public class CustomDialog extends Screen implements FieldChangeListener 
{
private ButtonField okButton;
public void fieldChanged(Field field, int context) 
{
    if (field == okButton) 
    {
        close();

    }
}
public CustomDialog(String message) 
{
    super(new VerticalFieldManager(), Screen.DEFAULT_CLOSE);


    add(new LabelField("Search Error",LabelField.FIELD_HCENTER));
    add(new LabelField(""));
    add(new LabelField(message,LabelField.FIELD_HCENTER));
    add(new LabelField(""));        
    okButton = new ButtonField("OK",ButtonField.FIELD_HCENTER);
    okButton.setChangeListener(this);
    add(okButton);
} 
protected void paintBackground(Graphics graphics) 
{
    graphics.setColor(Color.GRAY);
    graphics.fillRoundRect(0, 0, getWidth(), getHeight(), 12, 12);
    graphics.setColor(Color.BLACK);
    graphics.drawRoundRect(0, 0, getWidth(), getHeight(), 12, 12);
}  
protected void sublayout(int width, int height) 
{
    layoutDelegate(width - 80, height - 80);
    setPositionDelegate(10, 10);
    setExtent(width - 60, Math.min(height - 60, getDelegate().getHeight() + 20));
    setPosition(30, (height - getHeight())/2);
}
}