对话框创作黑莓(Dialog creation in Blackberry)

2019-07-29 19:49发布

您好,我想创建具有用户名和密码,并在按钮的迹象,但在用户没有输入用户名或密码的文本字段中正确的信息的弹出像图像聊天对话框应该从角落里弹出一个登录屏幕文本域的右侧显示相应的消息怎么能这个定制可以实现吗?

Answer 1:

我给你一个简单的方法。 如果它是不完美的你的问题,你就忽略这个答案。

在这里,我提出逻辑像以下。 我给你两个按钮1)登录2)删除

我想你知道如何验证您的文本字段正确或错误; 保持一个if条件,如果写权无需任何其他领域的错误,那么你有三个条件,你的逻辑

1)ID是错误的2)的密码是错误的或3)两个错

根据两块情况你可以在上面的文本字段中添加特定的提示框。

我两个错误的条件提供样品,并去除条件

让它为您的要求

资源:

chat.png图像所需的背景

示例代码:

package mypackage;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.Border;
import net.rim.device.api.ui.decor.BorderFactory;

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class MyScreen extends MainScreen implements FieldChangeListener
{
    /**
     * Creates a new MyScreen object
     */
    private BasicEditField id,password;
    private ButtonField login,cancel;
    private  VerticalFieldManager id_mgr,pass_mgr;
    private PopupField id_hint,pass_hint;
    public static Bitmap img;
    public MyScreen()
    { 
        img=Bitmap.getBitmapResource("chat.png");
        // Set the displayed title of the screen       
        setTitle("Login Page");
        Border b=BorderFactory.createRoundedBorder(new XYEdges(5, 5, 5, 5), Border.STYLE_SOLID);
        id_hint=new PopupField("Wrong Id", img);

        pass_hint=new PopupField("Wrong password", img);
        id_mgr=new VerticalFieldManager();

        id=new BasicEditField(){
            protected void layout(int width, int height) {
                super.layout(120, 40);
                setExtent(120, 40);

            }
        };
        id.setBorder(b);
        add(id_mgr);
        add(id);
        pass_mgr=new VerticalFieldManager();
        password=new BasicEditField(){
            protected void layout(int width, int height) {
                super.layout(120, 40);
                setExtent(120, 40);

            }
        };
        password.setBorder(b);
        add(pass_mgr);
        add(password);



        login=new ButtonField("Login");
        login.setChangeListener(this);
        add(login);

        cancel=new ButtonField("Remove");
        cancel.setChangeListener(this);
        add(cancel);

    }
    public void fieldChanged(Field field, int context) {
        if(field==login)
        {
            try {
//              id_mgr.add(new NullField(Field.FOCUSABLE));
                id_mgr.add(id_hint);
                id_mgr.setPadding(0, 0, 0, 50);
                pass_mgr.add(pass_hint);
                pass_mgr.setPadding(0, 0, 0, 50);
                id_hint.setFocus();
            } catch (IllegalStateException e) {
                return;
            }
        }else if(cancel==field)
        {
            synchronized (UiApplication.getEventLock()) {
                id_mgr.deleteAll();
                pass_mgr.deleteAll();
            }
        }

    }
}

和类PopupField.java是

package mypackage;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.BitmapField;

public class PopupField extends BitmapField{
    private  Bitmap img,scalled_img;
    private String message;
    private int layout_width;

    public PopupField(String message,Bitmap img)
    {
        this.message=message;
        layout_width=this.getFont().getAdvance(message)+40;
        scalled_img=new Bitmap(layout_width, img.getHeight());
        img.scaleInto(scalled_img, Bitmap.FILTER_BILINEAR);
        this.img=scalled_img;
    }

    protected void layout(int width, int height) {

        super.layout(img.getWidth(), img.getHeight());
        setExtent(img.getWidth(), img.getHeight());

    }

    protected void paint(Graphics graphics) {
        graphics.drawBitmap(0, 0, img.getWidth(), img.getHeight(), img,0,0);
        graphics.setColor(Color.RED);
        graphics.drawText(message,20,20);
        super.paint(graphics);
    }

}

输出图像:

继续帮助他人

其他的解决办法是这个链接会告诉你http://v4ks1n.wordpress.com/2011/01/28/tooltips-class-for-blackberry/



文章来源: Dialog creation in Blackberry