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

📄 progkeys.java

📁 sudoku j2me手机游戏主要有游戏主类和闪屏类菜单类和模型类等
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        currentItem=scroll;
        for (screenpos=0; screenpos < usableHeight/fh && currentItem<funcStr.length; screenpos++) {
            // If item = currentItem then draw in inverse colours
            if (item == currentItem) {
			    g.setColor(0x00,0x00,0x00);  g.fillRect(0,fh*screenpos,w,fh);
			    g.setColor(0xff,0xff,0xff);  
            } else {
			    g.setColor(0x00,0x00,0x00);  
            }
            // print current string
            if (currentItem == RETURN_TO_MENU) {
                buffer = new StringBuffer("Return to Menu");
            } else if (currentItem == USE_FULL_SCREEN) {
                buffer = new StringBuffer("Use Full Screen");
                if (useFullScreen) {
                    buffer = buffer.append(": YES");
                } else {
                    buffer = buffer.append(": NO");
                }
            } else if (currentItem == AUTO_WORKING) {
                buffer = new StringBuffer("Auto-Calc Working");
                if (autoWorking) {
                    buffer = buffer.append(": YES");
                } else {
                    buffer = buffer.append(": NO");
                }
            } else if (currentItem == WORKING_IN_CELL) {
                buffer = new StringBuffer("In-Cell Working Displ.");
                if (workingInCell) {
                    buffer = buffer.append(": YES");
                } else {
                    buffer = buffer.append(": NO");
                }
            } else if (currentItem == BLANK_WORKING) {
                buffer = new StringBuffer("Auto-Blank Working");
                if (blankWorking) {
                    buffer = buffer.append(": YES");
                } else {
                    buffer = buffer.append(": NO");
                }
            } else {
                buffer = new StringBuffer().append(funcStr[currentItem]).append(": ");
                if (item == currentItem && programming) {
                    if (shift) {
                        buffer = buffer.append("SHIFT+");
                    }
                    buffer = buffer.append("<<press key>>");
                } else if (bool_funcKeyCommand[currentItem]) {
                    buffer = buffer.append("Command soft key");
                } else if (funcKeyCode[currentItem] != 0) {
                    if (funcKeyShifted[currentItem] == true) {
                        buffer = buffer.append("SHIFT+");
                    }
                    buffer = buffer.append(getKeyName(funcKeyCode[currentItem]));
                    /* For debug, also print keycode */
                    buffer = buffer.append(" (").append(funcKeyCode[currentItem]).append(")");
                }
            }

			g.drawString(buffer.toString(), 2+horizScroll, fh * screenpos , 0);
            if (g.getFont().stringWidth(buffer.toString()) > maxLineWidth) {
                maxLineWidth = g.getFont().stringWidth(buffer.toString());
            }
            // return if we printed all strings
            currentItem++;
        }
        if (maxLineWidth + 2 < w - horizScroll ) {
            // we are scrolling more than we need - reduce horizScroll for the next paint()
            horizScroll = w - maxLineWidth - 2;
            if (horizScroll > 0) {
                horizScroll = 0;
            }
        }
    }

    // return the first found match of keycode & shift 
    public int findKeyCode(int keyCode, boolean shift) {
        int item;
        for (item = 0; item < funcStr.length; item++) {
            if (funcKeyCode[item] == keyCode && funcKeyShifted[item] == shift) {
                return item;
            }
        }
        return -1;
    }

	public void keyPressed(int keyCode) {
        int num_rows = getHeight()/fh - (useFullScreen?1:0) ;
        int oldItem = item;
        // if programming - capture key (pay attention to shift!) and return to list
        if (programming) {
            if (item != SHIFT && item < LEFT_SOFT && keyCode == funcKeyCode[SHIFT]) {
                shift = true;
            } else {
                // Some checks - if the keycode is used for the Menu, refuse it with an alert.
                // If the keycode is used elsewhere, clear the other keycode unless co-existence is
                // allowed (ie with working_lock and undo/lock) or between soft keys and others.
                if ((oldItem = findKeyCode(keyCode, shift))  >=0) {
                    if (oldItem == MENU && item < LEFT_SOFT) {
                        Alert alert;
                        alert = new Alert("Warning", "This key is used by MENU and cannot be used for this function too. Change the key assigned to MENU or choose a different combination for this function", null, AlertType.WARNING);
                        alert.setTimeout(4000);
                        SudokuME.display.setCurrent(alert,SudokuME.display.getCurrent());
                        keyCode = 0; shift = false;
                    } else if (((   item == LOCK_WORKING ) && (    item == INCREMENT || oldItem == LOCK_CELL || oldItem == UNDO)) ||
                               ((oldItem == LOCK_WORKING ) && ( oldItem == INCREMENT ||    item == LOCK_CELL ||    item == UNDO)) ||
                               (   item >= LEFT_SOFT && oldItem < LEFT_SOFT) ||
                               (oldItem >= LEFT_SOFT &&    item < LEFT_SOFT)) {
                        // This is not a clash!
                    } else {
                        funcKeyCode[oldItem] = 0;
                        funcKeyShifted[oldItem] = false;;
                    }
                }
                funcKeyCode[item] = keyCode;
                funcKeyShifted[item] = shift;
                if (       (funcKeyCode[LEFT_SOFT] == funcKeyCode[MID_SOFT]   && funcKeyCode[LEFT_SOFT] != 0) 
                        || (funcKeyCode[LEFT_SOFT] == funcKeyCode[RIGHT_SOFT] && funcKeyCode[LEFT_SOFT] != 0) 
                        || (funcKeyCode[MID_SOFT]  == funcKeyCode[RIGHT_SOFT] && funcKeyCode[MID_SOFT] != 0)) {
                    Alert alert;
                    alert = new Alert("Warning", "You have programmed 2 soft keys with the same code - this cannot be accepted. Please clear or reprogram one of them", null, AlertType.WARNING);
                    alert.setTimeout(4000);
                    SudokuME.display.setCurrent(alert,SudokuME.display.getCurrent());
                }

                programming=false;
		        setCommandListener(this);
                addCommand(programKeyCode);
                addCommand(clearKeyCode);
                addCommand(setCommand);
            }
        } else {
            // otherwise, capture up and down to change item.  Check scroll and update if necessary
			switch(getGameAction(keyCode)) {	
                case Canvas.LEFT :
                    horizScroll=horizScroll+HORIZ_SCROLL_DIST;
                    if (horizScroll > 0) {
                        horizScroll = 0;
                    }
                    break;
                case Canvas.RIGHT :
                    horizScroll=horizScroll-HORIZ_SCROLL_DIST;
                    break;
                case Canvas.UP :
                    if (item > RETURN_TO_MENU) {
                        item--;
                    }

                    if (scroll >= item - 1) {
                        scroll = item - 2;
                    }
                    if (scroll < RETURN_TO_MENU) {
                        scroll = RETURN_TO_MENU;
                    }

					break;
				case Canvas.DOWN :
                    if (item < funcStr.length-1) {
                        item++;
                    }
                    // If the last row on the display (scroll+num_rows) is less than the item we
                    // want to display, increase it
                    if (scroll+num_rows <= item + 1) {
                        scroll = item + 2 - num_rows;
                    }
                    if (scroll < RETURN_TO_MENU) {
                        scroll = RETURN_TO_MENU;
                    }
					break;
			}
            if (item != oldItem) {
                if (item == RETURN_TO_MENU) {
                    if (oldItem == USE_FULL_SCREEN) {
                        removeCommand(yesCommand);
                        removeCommand(noCommand);
                    }
                    addCommand(exitCommand);
                } else if (item == USE_FULL_SCREEN) {
                    if (oldItem == RETURN_TO_MENU) {
                        removeCommand(exitCommand);
                        if (SudokuME.hasMIDP2) {
                            addCommand(yesCommand);
                        }
                        addCommand(noCommand);
                    } else if (oldItem == AUTO_WORKING) {
                        if (!SudokuME.hasMIDP2) {
                            removeCommand(yesCommand);
                        }
                    }
                } else if (item == AUTO_WORKING) {
                    if (oldItem == USE_FULL_SCREEN) {
                        if (!SudokuME.hasMIDP2) {
                            addCommand(yesCommand);
                        }
                    }
                } else if (item == BLANK_WORKING) {
                    if (oldItem == MENU) {
                        removeCommand(programKeyCode);
                        removeCommand(setCommand);
                    }
                    addCommand(yesCommand);
                    addCommand(noCommand);
                } else if (item == MENU) {
                    if (oldItem == BLANK_WORKING) {
                        removeCommand(yesCommand);
                        removeCommand(noCommand);
                    } else {
                        removeCommand(clearKeyCode);
                    }
                    addCommand(programKeyCode);
                    addCommand(setCommand);
                } else if (item >= LEFT_SOFT) {
                    if (oldItem < LEFT_SOFT) {
                        removeCommand(setCommand);
                    }
                } else {
                    if (oldItem == MENU) {
                        addCommand(clearKeyCode);
                    }
                    if (oldItem >= LEFT_SOFT) {
                        addCommand(setCommand);
                    }
                }
            }
        }
        repaint();
    }

	public void keyReleased(int keyCode) {
        if (keyCode == funcKeyCode[SHIFT]) {
            shift = false;
            repaint();
        }
    }

    private void _fillFuncKeyCommandArray() {
        int i;
        int commandType = 3; // 3 = Command.CANCEL, increment after each command is defined to spread them over different keys
        for (i=0; i<funcStr.length; i++) {
            if (bool_funcKeyCommand[i]) {
                funcKeyCommand[i] = new Command(funcStr[i], commandType, 1);
                commandType++;
            } else {
                funcKeyCommand[i] = null;
            }
        }
    }

	public void commandAction(Command c,Displayable d) {
        if (c == exitCommand) {
            removeCommand(exitCommand);
            if (SudokuME.hasMIDP2) {
                setFullScreenMode(false);
            }
            _fillFuncKeyCommandArray();
            display.setCurrent(parent);
        } else if (c == programKeyCode) {
            programming = true;        
            shift = false;
            bool_funcKeyCommand[item] = false;
		    setCommandListener(null);
            removeCommand(programKeyCode);
            removeCommand(setCommand);
            removeCommand(clearKeyCode);
        } else if (c == clearKeyCode) {
            funcKeyCode[item] = 0;
            bool_funcKeyCommand[item] = false;
        } else if (c == setCommand) {
            funcKeyCode[item] = 0;
            bool_funcKeyCommand[item] = true;
        } else if (c == yesCommand) {
            if (item == USE_FULL_SCREEN) {
                if (SudokuME.hasMIDP2) {
                    useFullScreen=true;
                    setFullScreenMode(true);
                }
            } else if (item == AUTO_WORKING) {
                autoWorking = true;
            } else if (item == WORKING_IN_CELL) {
                workingInCell = true;
            } else if (item == BLANK_WORKING) {
                blankWorking = true;
            } else {
                // ERROR
                removeCommand(yesCommand);
            }
        } else if (c == noCommand) {
            if (item == USE_FULL_SCREEN) {
                if (SudokuME.hasMIDP2) {
                    useFullScreen=false;
                    setFullScreenMode(false);
                }
            } else if (item == AUTO_WORKING) {
                autoWorking = false;
            } else if (item == WORKING_IN_CELL) {
                workingInCell = false;
            } else if (item == BLANK_WORKING) {
                blankWorking = false;
            } else {
                // ERROR
                removeCommand(noCommand);
            }
        }

        repaint();
    }

}

⌨️ 快捷键说明

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