调用黑莓Java类之间 [英] Calling Between Classes in Blackberry Java

查看:108
本文介绍了调用黑莓Java类之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想推一个新的屏幕时,位图在屏幕上点击。为此,我已经从这个帖子创建了一个类:黑莓可点击BitmapField 的部分code I'已经公布如下:

 公共类CustomMenuButtonField扩展字段{
    位图正常,重点突出;    ...    保护布尔navigationClick(INT的地位,诠释时间)
    {
        //推新画面
        fieldChangeNotify(0);
        返回true;
    }    ...

我想,当用户点击该位图推一个新的屏幕。我咨询这个线程:
类之间的沟通的,但我仍然无法弄清楚的命令来调用新的屏幕命令。该的UserInterface我至今是:

 公共类的UserInterface扩展的UIApplication {
    公共静态无效的主要(字串[] args){
        的UserInterface该app =新的UserInterface();
        theApp.enterEventDispatcher();
    }
    公众的UserInterface(){
        pushScreen(新UserInterfaceScreen());
    }
}最后一类UserInterfaceScreen扩展MainScreen {
    公共UserInterfaceScreen(){
    ...

什么是命令弹出新的屏幕,更重要的是我在这里将能够进行这项工作?我知道这也许应该使用pushScreen(),但没有在该类别的认可。我将创建一个新的最后一类NewScreenFromClick扩展MainScreen ?如果是的话我将如何调用它,并把它放在EventDispatcher中。我已经经历了黑莓的网站,但他们没有太多的样本code在这个问题上,我非常新的对Java,所以这是相当混乱给我。


解决方案

 的ImageField的ImageField =新的ImageField(,Field.FOCUSABLE,image.png,image.png ,0x102839);
    加(ImageField的);
    FieldChangeListener监听器=新FieldChangeListener(){
    公共无效fieldChanged(场场,诠释上下文){
            如果(场== ImageField的){
    home首页=新家园(); //你的屏幕
    。UiApplication.getUiApplication()pushScreen(家);                  }
                }
                         };
ImageField的.setChangeListener(监听);

// ImageField的类如下

给出

 包com.pl.button;进口net.rim.device.api.ui。*;
net.rim.device.api.system数据导入*。公共类ImageField的扩展字段{私人字符串_label;
私人诠释_labelHeight;
私人诠释_labelWidth;
私人字体_font;私人位图_currentPicture;
私人位图_onPicture;
私人位图_offPicture;
INT色;公众的ImageField(字符串文本,长款式,IMG的字符串,字符串img_hvr,诠释颜色){
    超(样式);
    _offPicture = Bitmap.getBitma $ P $的PSource(IMG);
    _onPicture = Bitmap.getBitma $ P $的PSource(img_hvr);    _font =的getFont();
    _label =文本;
    _labelHeight = _onPicture.getHeight();
    _labelWidth = _onPicture.getWidth();    this.color =颜色;    _currentPicture = _offPicture;
}/ **
 返回:按钮上的文本
 * /
字符串的getText(){
    返回_label;
}/ **
 *外地执行。
 * @see net.rim.device.api.ui.Field#得到preferredHeight()
 * /
公众诠释的get preferredHeight(){
    返回_labelHeight;
}/ **
 *外地执行。
 * @see net.rim.device.api.ui.Field#得到preferredWidth()
 * /
公众诠释的get preferredWidth(){
    返回_labelWidth;
}/ **
 *外地执行。在获得焦点时更改画面。
 * @see net.rim.device.api.ui.Field#的onfocus(INT)
 * /
保护无效的onfocus(INT方向){
    _currentPicture = _onPicture;
    无效();
}/ **
 *外地执行。更改图片回来时,焦点将丢失。
 * @see net.rim.device.api.ui.Field#onUnfocus()
 * /
保护无效onUnfocus(){
    _currentPicture = _offPicture;
    无效();
}/ **
 *外地执行。
 * @see net.rim.device.api.ui.Field#DRAWFOCUS(图形,布尔)
 * /
保护无效DRAWFOCUS(图形显卡,布尔){
    // 没做什么
}/ **
 *外地执行。
 * @see net.rim.device.api.ui.Field#布局(INT,INT)
 * /
保护无效布局(INT宽度,高度INT){
    setExtent(Math.min(宽度,GET preferredWidth()),
    Math.min(身高,GET preferredHeight()));
}/ **
 *外地执行。
 * @see net.rim.device.api.ui.Field#漆(图形)
 * /
保护无效漆(图形图像){
    //首先绘制背景颜色和图像
    graphics.setColor(this.color);
    graphics.fillRect(0,0,的getWidth(),的getHeight());
    graphics.drawBitmap(0,0,的getWidth(),的getHeight(),_currentPicture,0,0);    //然后绘制文本
    graphics.setColor(Color.BLACK);
    graphics.setFont(_font);
    graphics.drawText(_label,4,2,
        (中间体)(对getStyle()及DrawStyle.ELLIPSIS | DrawStyle.HALIGN_MASK),
        的getWidth() - 6);
}/ **
 *重写,这样的事件调度线程可以赶上这个活动
 *而不是让它在这里抓到..
 * @see net.rim.device.api.ui.Field#navigationClick(INT,INT)
 * /
保护布尔navigationClick(INT的地位,诠释时间){
    fieldChangeNotify(1);
    返回true;
}

}

I am trying to push a new screen when a bitmap is "clicked" on the screen. For this I have created a Class from this post: Blackberry Clickable BitmapField whose partial code I've posted below:

public class CustomMenuButtonField extends Field{
    Bitmap normal,focused;

    ...

    protected boolean navigationClick(int status, int time)
    {
        // push new screen
        fieldChangeNotify(0);
        return true;
    }

    ...

I want to push a new screen when the user clicks the bitmap. I have consulted this thread: Communicating between classes, but I still can't figure out the commands to call the new screen command. The UserInterface I have so far is:

public class UserInterface extends UiApplication {
    public static void main(String[] args){
        UserInterface theApp = new UserInterface();
        theApp.enterEventDispatcher();
    }
    public UserInterface() {
        pushScreen(new UserInterfaceScreen());
    }
}

final class UserInterfaceScreen extends MainScreen {
    public UserInterfaceScreen() {
    ...

What would be the command to pop up the new screen, and more importantly where would I be able to work on it? I know it should probably use pushScreen() but that is not recognized in that class. Would I create a new final class NewScreenFromClick extends MainScreen? and if so how would I call it and put it in the eventDispatcher. I've been going through the blackberry site but they don't have much sample code on this issue and I am very new to Java so this is fairly confusing to me.

解决方案

    imageField imageField = new imageField ("",Field.FOCUSABLE,"image.png","image.png", 0x102839);
    add(imageField );
    FieldChangeListener listener = new FieldChangeListener() {
    public void fieldChanged(Field field, int context) {
            if (field == imageField ) {
    home home = new home();//your screen
    UiApplication.getUiApplication().pushScreen(home);

                  }
                }
                         };
imageField .setChangeListener(listener);

//imagefield class is given below

package com.pl.button;

import net.rim.device.api.ui.*;
import net.rim.device.api.system.*;

public class imagefield extends Field {

private String _label;
private int _labelHeight;
private int _labelWidth;
private Font _font;

private Bitmap _currentPicture;
private Bitmap _onPicture; 
private Bitmap _offPicture; 
int color;

public imagefield (String text, long style ,String img, String img_hvr, int color){
    super(style);


    _offPicture = Bitmap.getBitmapResource(img);
    _onPicture = Bitmap.getBitmapResource(img_hvr);

    _font = getFont();
    _label = text;
    _labelHeight = _onPicture.getHeight();  
    _labelWidth = _onPicture.getWidth();

    this.color = color;

    _currentPicture = _offPicture;
}

/**
 * @return The text on the button
 */
String getText(){
    return _label;
}

/**
 * Field implementation.
 * @see net.rim.device.api.ui.Field#getPreferredHeight()
 */
public int getPreferredHeight(){
    return _labelHeight;
}

/**
 * Field implementation.
 * @see net.rim.device.api.ui.Field#getPreferredWidth()
 */
public int getPreferredWidth(){
    return _labelWidth;
}

/**
 * Field implementation.  Changes the picture when focus is gained.
 * @see net.rim.device.api.ui.Field#onFocus(int)
 */
protected void onFocus(int direction) {
    _currentPicture = _onPicture;
    invalidate();
}

/**
 * Field implementation.  Changes picture back when focus is lost.
 * @see net.rim.device.api.ui.Field#onUnfocus()
 */
protected void onUnfocus() {
    _currentPicture = _offPicture;
    invalidate();
}

/**
 * Field implementation.  
 * @see net.rim.device.api.ui.Field#drawFocus(Graphics, boolean)
 */
protected void drawFocus(Graphics graphics, boolean on) {
    // Do nothing
}

/**
 * Field implementation.
 * @see net.rim.device.api.ui.Field#layout(int, int)
 */
protected void layout(int width, int height) {
    setExtent(Math.min( width, getPreferredWidth()), 
    Math.min( height, getPreferredHeight()));
}

/**
 * Field implementation.
 * @see net.rim.device.api.ui.Field#paint(Graphics)
 */
protected void paint(Graphics graphics){       
    // First draw the background colour and picture
    graphics.setColor(this.color);
    graphics.fillRect(0, 0, getWidth(), getHeight());
    graphics.drawBitmap(0, 0, getWidth(), getHeight(), _currentPicture, 0, 0);

    // Then draw the text
    graphics.setColor(Color.BLACK);
    graphics.setFont(_font);
    graphics.drawText(_label, 4, 2, 
        (int)( getStyle() & DrawStyle.ELLIPSIS | DrawStyle.HALIGN_MASK ),
        getWidth() - 6 );
}

/**
 * Overridden so that the Event Dispatch thread can catch this event
 * instead of having it be caught here..
 * @see net.rim.device.api.ui.Field#navigationClick(int, int)
 */
protected boolean navigationClick(int status, int time){
    fieldChangeNotify(1);
    return true;
}

}

这篇关于调用黑莓Java类之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆