📄 selectscreen.java
字号:
/*
* SelectScreen.java
*
* Created on 2005年12月2日, 下午1:06
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/
package com.j2medev.maze;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Gauge;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemStateListener;
/**
* This is the screen that allows the user to modify the
* width of the maze walls..
*
* @author Carol Hamer
*/
class SelectScreen extends Form
implements ItemStateListener, CommandListener {
//----------------------------------------------------------------
// fields
/**
* The "Done" button to exit this screen and return to the maze.
*/
private Command myExitCommand = new Command("完成", Command.EXIT, 1);
/**
* The gague that modifies the width of the maze walls.
*/
private Gauge myWidthGauge;
/**
* The gague that displays the number of columns of the maze.
*/
private Gauge myColumnsGauge;
/**
* A handle to the main game canvas.
*/
private MazeCanvas myCanvas;
//----------------------------------------------------------------
// initialization
/**
* Create the gagues and place them on the screen.
*/
public SelectScreen(MazeCanvas canvas) {
super("Size Preferences");
addCommand(myExitCommand);
setCommandListener(this);
myCanvas = canvas;
setItemStateListener(this);
myWidthGauge = new Gauge("每一列的宽度", true,
myCanvas.getMaxColWidth(),
myCanvas.getColWidth());
myColumnsGauge = new Gauge("迷宫的列数", false,
myCanvas.getMaxNumCols(),
myCanvas.getNumCols());
// Warning: the setLayout method does not exist in
// MIDP 1.4. If there is any chance that a target
// device will be using MIDP 1.4, comment out the
// following two lines:
//myWidthGauge.setLayout(Item.LAYOUT_CENTER);
//myColumnsGauge.setLayout(Item.LAYOUT_CENTER);
append(myWidthGauge);
append(myColumnsGauge);
}
//----------------------------------------------------------------
// implementation of ItemStateListener
/**
* Respond to the user changing the width.
*/
public void itemStateChanged(Item item) {
if(item == myWidthGauge) {
int val = myWidthGauge.getValue();
if(val < myCanvas.getMinColWidth()) {
myWidthGauge.setValue(myCanvas.getMinColWidth());
} else {
int numCols = myCanvas.setColWidth(val);
myColumnsGauge.setValue(numCols);
}
}
}
//----------------------------------------------------------------
// implementation of CommandListener
/*
* Respond to a command issued on this screen.
* (either reset or exit).
*/
public void commandAction(Command c, Displayable s) {
if(c == myExitCommand) {
myCanvas.newMaze();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -