黑莓 - 按任意键关闭启动屏幕

发布于 2024-08-12 15:00:02 字数 2480 浏览 4 评论 0原文

我正在尝试改编一段现有代码。我正在尝试删除飞溅上的计时器 屏幕并将其更改为“按任意键继续”类型屏幕。我需要一些有关推送/弹出屏幕逻辑以及监听启动屏幕上的按键的帮助。这是代码的摘录。

public class MenuMain_Pca extends UiApplication {
    public static void main(String[] args) {
        MenuMain_Pca myStart = new MenuMain_Pca();
        myStart.enterEventDispatcher();
    }
    public MenuMain_Pca() {
        Screen_Splash_Screen wScreen = new Screen_Splash_Screen();
        this.pushScreen(wScreen);
        this.popScreen(wScreen);
        MenuMain_Pca.this.pushScreen(new HomeScreen());
    }
}

class Screen_Splash_Screen extends MainScreen implements KeyListener {
    public Screen_Splash_Screen() {
        super(DEFAULT_MENU | DEFAULT_CLOSE);
        Bitmap b240 = new Bitmap(240, 163);
        b240 = Bitmap.getBitmapResource("image1.png");
        BitmapField bf = new BitmapField(b240);
        bf.setSpace(Display.getWidth() / 2 - b240.getWidth() / 2, 0);
        add(bf);
    }
    public boolean keyChar(char key, int status, int time) {
        return true;
    }
    public boolean keyDown(int keycode, int time) {
        return true;
    }
    public boolean keyRepeat(int keycode, int time) {
        return true;
    }
    public boolean keyStatus(int keycode, int time) {
        return true;
    }
    public boolean keyUp(int keycode, int time) {
        return true;
    }
}

class HomeScreen extends MainScreen implements FieldChangeListener {
    private ButtonField button1 = null;
    public HomeScreen() {
        super(DEFAULT_MENU | DEFAULT_CLOSE);
        setTitle(new LabelField("label1", LabelField.ELLIPSIS
                | LabelField.USE_ALL_WIDTH));
        int screenWidth = Display.getWidth() * 95 / 100;
        button1 = new ButtonField("Button1");
        button1.setChangeListener(this);
        add(button1);
    }

    public void fieldChanged(Field field, int context) {
        if (field == (Field) button1)
            UiApplication.getUiApplication().pushScreen(new menu1(1));
    }

    // ask user if he really wants to leave...
    public boolean onClose() {
        boolean retval = false;
        String label = "Are you sure you want to Exit now?";
        int response = Dialog.ask(Dialog.D_YES_NO, label, Dialog.YES);
        if (response == Dialog.YES) {
            System.exit(0);
            retval = true;
        }
        return retval;
    }
}

I am trying to adapt a piece of existing code. I am trying to remove a timer on a splash
screen and change it to "press any key to continue" type screen. I need some help with the push/popscreen logic and listening for a keystroke on the splash screen. Here is extract from the code.

public class MenuMain_Pca extends UiApplication {
    public static void main(String[] args) {
        MenuMain_Pca myStart = new MenuMain_Pca();
        myStart.enterEventDispatcher();
    }
    public MenuMain_Pca() {
        Screen_Splash_Screen wScreen = new Screen_Splash_Screen();
        this.pushScreen(wScreen);
        this.popScreen(wScreen);
        MenuMain_Pca.this.pushScreen(new HomeScreen());
    }
}
class Screen_Splash_Screen extends MainScreen implements KeyListener {
    public Screen_Splash_Screen() {
        super(DEFAULT_MENU | DEFAULT_CLOSE);
        Bitmap b240 = new Bitmap(240, 163);
        b240 = Bitmap.getBitmapResource("image1.png");
        BitmapField bf = new BitmapField(b240);
        bf.setSpace(Display.getWidth() / 2 - b240.getWidth() / 2, 0);
        add(bf);
    }
    public boolean keyChar(char key, int status, int time) {
        return true;
    }
    public boolean keyDown(int keycode, int time) {
        return true;
    }
    public boolean keyRepeat(int keycode, int time) {
        return true;
    }
    public boolean keyStatus(int keycode, int time) {
        return true;
    }
    public boolean keyUp(int keycode, int time) {
        return true;
    }
}
class HomeScreen extends MainScreen implements FieldChangeListener {
    private ButtonField button1 = null;
    public HomeScreen() {
        super(DEFAULT_MENU | DEFAULT_CLOSE);
        setTitle(new LabelField("label1", LabelField.ELLIPSIS
                | LabelField.USE_ALL_WIDTH));
        int screenWidth = Display.getWidth() * 95 / 100;
        button1 = new ButtonField("Button1");
        button1.setChangeListener(this);
        add(button1);
    }

    public void fieldChanged(Field field, int context) {
        if (field == (Field) button1)
            UiApplication.getUiApplication().pushScreen(new menu1(1));
    }

    // ask user if he really wants to leave...
    public boolean onClose() {
        boolean retval = false;
        String label = "Are you sure you want to Exit now?";
        int response = Dialog.ask(Dialog.D_YES_NO, label, Dialog.YES);
        if (response == Dialog.YES) {
            System.exit(0);
            retval = true;
        }
        return retval;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

女中豪杰 2024-08-19 15:00:03

尝试在启动屏幕中使用 keyDown 事件,如下所示:

public boolean keyDown(int keycode, int time) {
        getUiEngine().pushScreen(new HomeScreen());
        getUiEngine().popScreen(this);
    return true;
}

Try to use keyDown event in splash screen, like this:

public boolean keyDown(int keycode, int time) {
        getUiEngine().pushScreen(new HomeScreen());
        getUiEngine().popScreen(this);
    return true;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文