📄 dbdemo.java
字号:
//dbDemo.java file
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class dbDemo extends MIDlet implements CommandListener
{
//命令对象
private Command exitCommand, createCmd, delCmd, ocCmd, ckCmd;
private TextBox tb; //通过TextBox来显示信息
private UsersRecordStore userRec; //数据操作对象
public dbDemo()
{
tb =new TextBox("OutputWindow","",120,TextField.ANY);
exitCommand =new Command("Exit",Command.EXIT,1);
createCmd =new Command("CreateDb",Command.SCREEN,1);
delCmd =new Command("DelDb",Command.SCREEN,1);
ocCmd =new Command("Open&Close",Command.SCREEN,1);
ckCmd =new Command("IsExist",Command.SCREEN,1);
tb.addCommand(exitCommand);
tb.addCommand(createCmd);
tb.addCommand(delCmd);
tb.addCommand(ocCmd);
tb.addCommand(ckCmd);
tb.setCommandListener(this);
userRec = new UsersRecordStore(Display.getDisplay(this));
}
protected void startApp( ) throws MIDletStateChangeException
{
Display.getDisplay(this).setCurrent(tb);
}
protected void pauseApp( )
{
}
protected void destroyApp( boolean p1 )
{
userRec.CloseDb();
}
public void commandAction(Command c,Displayable d)
{
if (c ==exitCommand)
{
destroyApp(false);
notifyDestroyed();
}
else if(c ==createCmd)
{
if( userRec.CreateDb())
tb.setString("Create db OK");
else
tb.setString("Create db failed");
}
else if(c ==delCmd)
{
if(userRec.DeleteDb() )
tb.setString("Delete db OK");
else
tb.setString("Delete db failed");
}
else if(c ==ocCmd)
{
if( userRec.OpenDb() )
{
if( userRec.CloseDb())
tb.setString("Open db OK & Close db OK");
else
tb.setString("Open db OK & Close db failed");
}
else
tb.setString("Open db failed");
}
else if(c ==ckCmd)
{
if( userRec.IsDbExist() )
tb.setString("Db is exist");
else
tb.setString("Db is NOT exist");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -