⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 confirmationdialog.java

📁 J2ME开发精解程序的源码 很好的学习资料
💻 JAVA
字号:
package com.j2medev.chapter3.dialog;

import javax.microedition.lcdui.*;

public class ConfirmationDialog extends Dialog implements CommandListener {
    
    //定义两个常量代表用户的选择
    public static final int YES = 0;
    public static final int NO = 1;
    protected Form wait;//用于实现对话框的组件
    protected Command noCommand;
    protected Command yesCommand;
    private String message;
    private String yesLabel;
    private String noLabel;
    
    public ConfirmationDialog(Display display, String message) {
        this(display, message, null, null);
    }
    
    public ConfirmationDialog(Display display, String amessage,
            String ayesLabel, String anoLabel) {
        super(display);
        this.message = (amessage == null) ? "继续操作?" : amessage;
        this.yesLabel = (yesLabel == null) ? "确定" : ayesLabel;
        this.noLabel = (noLabel == null) ? "返回" : anoLabel;
        yesCommand = new Command(yesLabel, Command.OK, 1);
        noCommand = new Command(noLabel, Command.CANCEL, 1);
        wait = new Form("对话框");
        wait.append(message);
        wait.addCommand(yesCommand);
        wait.addCommand(noCommand);
        wait.setCommandListener(this);
    }
    
    public void commandAction(Command c, Displayable d) {
        if (c == yesCommand) {
            dismiss(YES);
        } else if (c == noCommand) {
            dismiss(NO);
        }
    }
    //实现Dialog的抽象方法,返回wait。
    protected Displayable getDisplayable() {
        return wait;
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -