centerstring.java
来自「《精通JAVA手机游戏与应用程序设计》随书光盘」· Java 代码 · 共 45 行
JAVA
45 行
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class CenterString extends MIDlet implements CommandListener {
private Command exitCommand;
private CenterStringCanvas sg;
public CenterString() {
exitCommand = new Command("Exit", Command.EXIT, 1);
sg = new CenterStringCanvas();
sg.addCommand(exitCommand);
sg.setCommandListener(this);
Display.getDisplay(this).setCurrent(sg);
}
protected void startApp(){
}
protected void pauseApp() {
}
protected void destroyApp(boolean arg0){
}
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
}
class CenterStringCanvas extends Canvas{
protected void paint(Graphics g) {
g.drawString("Center String", this.getWidth()/2, this.getHeight()/2,
Graphics.BOTTOM|Graphics.HCENTER);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?