spacerdemo.java

来自「《精通JAVA手机游戏与应用程序设计》随书光盘」· Java 代码 · 共 53 行

JAVA
53
字号
//spacerDemo.java file
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class spacerDemo extends MIDlet implements CommandListener
{
    private Command exitCommand, spacerCommand;
    private Form mainForm;
    public spacerDemo()
    {
        exitCommand =new Command("Exit",Command.EXIT,1);
        spacerCommand =new Command("addSpacer",Command.SCREEN,1);
        
        mainForm = new Form("spacerDemo");
        mainForm.addCommand(exitCommand);
        mainForm.addCommand(spacerCommand);
        //设置命令监听对象
        mainForm.setCommandListener(this);
        //添加Item对象
        mainForm.append("Login");
        mainForm.append(new TextField("Name","",10,TextField.ANY));
        mainForm.append(new TextField("Password","",6,TextField.PASSWORD));
    }
    protected void startApp(  ) throws MIDletStateChangeException
    {
        Display.getDisplay(this).setCurrent(mainForm);
    }

    protected void pauseApp(  )
    {
    }

    protected void destroyApp( boolean p1 )
    {
    }

    public void commandAction(Command c,Displayable d)
    {
        if (c ==exitCommand)
        {
            destroyApp(false);
            notifyDestroyed();
        }
        else if (c ==spacerCommand)
        {
            mainForm.removeCommand(spacerCommand);
            //插入屏幕宽度,高度为5和20象素的Spacer对象
            mainForm.insert(2,new Spacer(mainForm.getWidth(), 5));
            mainForm.insert(1,new Spacer(mainForm.getWidth(),20));
        }

    }
}

⌨️ 快捷键说明

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