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

📄 menucontainer.java

📁 一个完全的j2me斜视角地图的rpg游戏
💻 JAVA
字号:
//import java.lang.IllegalArgumentException;
import javax.microedition.lcdui.Graphics;
public class MenuContainer {
        private MenuOption [] list;
        private int current, totalOptions;
        private boolean vertical;                       //used for key input
        public MenuContainer(int length, boolean vert) {
                        totalOptions = length;
                        list = new MenuOption[length];
                        vertical = vert;
                        current = 0;
        }
        public boolean isVertical() {
                return vertical;
        }
        public MenuOption getCurrent() {
                return list[current];
        }
        public void setCurrent(int i) {
                current = i;
        }
        
        public void init() {
                for (int i = 0; i < totalOptions; i++) {
                        if (i == current)
                                list[i].setFrame(1);
                        else
                                list[i].setFrame(0);
                }
        }
        public void addOption(MenuOption option, int x, int y) {
//                if (current < list.length) {
                        list[current] = option;
                        list[current].setRefPixelPosition(x, y);
                        current++;
                        if (current == totalOptions) {
                                current = 0;
                                list[current].setFrame(1);
                        }
//                }
        }
        private void updateOptions() {
                for (int i = 0; i < totalOptions; i++) {
                        if (list[i].getFrame() == 1)    //was the previously selected
                                list[i].setFrame(0);
                        else if (i == current)          //was not but is the selected now
                                list[i].setFrame(1);
                        
                }
        }
        public void next() {
		if (current + 1 < totalOptions)
			current++;
		else
			current = 0;
                updateOptions();
        }
        public void previous() {
		if (current == 0)
			current = totalOptions - 1;
		else
			current--;
                updateOptions();
        }
        public void hide() {
                for (int i = 0; i < totalOptions; i++) {
                        list[i].setVisible(false);
                }
        }
        public void show(Graphics g) {
                for (int i = 0; i < totalOptions; i++) {
                        list[i].setVisible(true);
                        list[i].paint(g);
                }
        }
}

⌨️ 快捷键说明

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