gpt4 book ai didi

java - Blackberry Java 类之间的调用

转载 作者:行者123 更新时间:2023-11-30 06:32:11 26 4
gpt4 key购买 nike

当在屏幕上“单击”位图时,我试图推送一个新屏幕。为此,我从这篇文章中创建了一个类:Blackberry Clickable BitmapField我在下面发布了其部分代码:

public class CustomMenuButtonField extends Field{
Bitmap normal,focused;

...

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

...

我想在用户点击位图时推送一个新屏幕。我咨询过这个线程: Communicating between classes ,但我仍然无法弄清楚调用新屏幕命令的命令。到目前为止,我的用户界面是:

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() {
...

弹出新屏幕的命令是什么,更重要的是我可以在哪里工作?我知道它可能应该使用 pushScreen() 但在该类中不被识别。我会创建一个新的 final class NewScreenFromClick extends MainScreen 吗?如果是这样,我将如何调用它并将其放入 eventDispatcher 中。我一直在浏览黑莓网站,但他们没有太多关于这个问题的示例代码,而且我对 Java 还很陌生,所以这让我很困惑。

最佳答案

    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类如下所示

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 - Blackberry Java 类之间的调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9035987/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com