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

📄 choiceform.java

📁 Programming java 2 micro edition on symbian os 一书中作者写的使用了MMAPI的小拼图游戏
💻 JAVA
字号:
/*
 * Copyright 2003, 2004 Symbian Ltd.
 * For License terms see http://www.symbian.com/developer/techlib/codelicense.html
 */

package picturepuzzle;
import javax.microedition.lcdui.*;
import java.io.*;

/**
 * Displays names of images stored in the record store and provides the
 * user with the option to create a new image.
 */
public class ChoiceForm extends Form implements CommandListener {
    
    private GameMIDlet midlet;
    private ChoiceGroup cg;
    private Command startCommand;
    private Command deleteCommand;
    private Command exitCommand;
    
    /**
     * Creates the ChoiceForm. Adds Commands and a ChoiceGroup.
     * @param midlet Facilitates a call-back to the midlet.
     */
    public ChoiceForm(GameMIDlet midlet){
        super("Saved Images");
        this.midlet = midlet;
        startCommand = new Command("Start" , Command.SCREEN , 2);
        deleteCommand = new Command("Delete" , Command.SCREEN , 3);
        exitCommand = new Command("Exit", Command.EXIT, 1);
        addCommand(exitCommand);
        addCommand(startCommand);
        setCommandListener(this);
        cg = new ChoiceGroup("Choose image option:" , ChoiceGroup.EXCLUSIVE);
        append(cg);
        cg.append("Create new image", null);
    }
    
    /**
     * Adds the names of the stored images to the ChoiceGroup.
     * @param imageNames An array of the names of the stored images.
     */
    public void setImageNames(String[] imageNames) {
        for(int i = 1; i < cg.size(); i++){
            cg.delete(i);
        }
        cg.setSelectedIndex(0, true);
        if (imageNames != null) {
            for (int i = 1 ; i <= imageNames.length ; i++) {
                cg.append(imageNames[i - 1] , null);
            }
            addCommand(deleteCommand);
        }
    }
    
    public void commandAction(Command command , Displayable displayable) {
        if (command == exitCommand) {
            midlet.exit();
        } else if(command == startCommand) {
            if (cg.getSelectedIndex() == 0) {
                midlet.displayCaptureCanvas();
            }else {
                String imageName = cg.getString(cg.getSelectedIndex());
                midlet.loadAndDisplayImage(imageName);
            }
        }else if(command == deleteCommand) {
            int index = cg.getSelectedIndex();
            String imageName = cg.getString(index);
            cg.setSelectedIndex(index - 1, true);
            cg.delete(index);
            midlet.deleteImage(imageName);
            if(cg.size() == 1) {
                removeCommand(deleteCommand);
            }
        }
    }
    
}

⌨️ 快捷键说明

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