confirmationdialog.java

来自「这是我们学校教的j2me程序开发实例从入门到精通自带关盘的源代码」· Java 代码 · 共 77 行

JAVA
77
字号
package com.north.phonebook.ui;

import javax.microedition.lcdui.*;

//Defines a dialog that displays a text
//message and "Yes" and "No" buttons.

public class ConfirmationDialog extends Dialog implements CommandListener
{

    public static final int YES = 0;
    public static final int NO = 1;
    protected WaitCanvas canvas;
    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);

        canvas = new WaitCanvas(message, true);
        canvas.addCommand(yesCommand);
        canvas.addCommand(noCommand);
        canvas.setCommandListener(this);
    }

    /**
     * @return Returns the message.
     */
    public String getMessage()
    {
        return message;
    }

    /**
     * @param message
     *            The message to set.
     */
    public void setMessage(String message)
    {
        canvas.setMMessage(message);
    }

    public void commandAction(Command c, Displayable d)
    {
        if (c == yesCommand)
        {
            dismiss(YES);
        } else if (c == noCommand)
        {
            dismiss(NO);
        }
    }

    protected Displayable getDisplayable()
    {
        return canvas;
    }

}

⌨️ 快捷键说明

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