?? addnote.java
字號:
/*
* AddNote.java
*
* Created on 2007年3月15日, 上午10:10
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package net.bccn.account.ui;
import java.util.Date;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;
import net.bccn.account.model.Note;
import net.bccn.account.util.Util;
/**
*
* @author hadeslee
*/
public class AddNote extends TextBox implements CommandListener {
private static AddNote me;
private Command ok,back,reset;
private boolean isModify;//是否可修改
private Note temp;//一個暫時變量
/** Creates a new instance of AddNote */
public AddNote() {
super("請輸入內容:(最多1000字)",null,1000,TextField.ANY);
initWindow();
}
private void initWindow(){
ok=new Command("確定",Command.OK,1);
back=new Command("返回",Command.BACK,0);
reset=new Command("重置",Command.SCREEN,2);
this.addCommand(ok);
this.addCommand(back);
this.addCommand(reset);
this.setCommandListener(this);
}
public static AddNote getInstance(){
if(me==null){
me=new AddNote();
}
me.reset();
return me;
}
public static AddNote getInstance(Note note,boolean isModify){
if(me==null){
me=new AddNote();
}
me.temp=note;
me.isModify=isModify;
if(isModify){
me.setTitle("修改筆記");
me.addCommand(me.ok);
me.addCommand(me.back);
me.removeCommand(me.reset);
}else{
me.removeCommand(me.ok);
me.removeCommand(me.reset);
me.setTitle("查看筆記");
}
me.setString(note.getContent());
return me;
}
private Note getNote(){
Note n=new Note();
n.setContent(this.getString());
n.setDate(new Date());
if(isModify){
n.setID(temp.getID());
}
return n;
}
public void commandAction(Command command, Displayable displayable) {
if(command==ok){
String s=this.getString();
if(s==null||s.equals("")){
Util.showINFO(AlertType.ERROR,"內容不能為空!!");
}else{
if(isModify){
temp.setContent(s);
boolean b=Util.updateRecord(temp);
if(b){
Util.showINFO(AlertType.INFO,"修改筆記成功!請返回",ViewNote.getInstance());
this.setString(null);
ViewNote.updateList(temp);
}else{
Util.showINFO(AlertType.ERROR,"修改筆記失敗!");
}
}else{
boolean b=Util.saveRecord(getNote());
if(b){
Util.showINFO(AlertType.INFO,"保存筆記成功!");
this.setString(null);
}else{
Util.showINFO(AlertType.ERROR,"保存筆記失敗!");
}
}
}
}else if(command==back){
if(temp!=null){
temp=null;
this.setString(null);
Util.changeTo(Util.VIEW_NOTE);
}else{
Util.changeTo(Util.MAIN_FORM);
}
}else if(command==reset){
reset();
this.setString(null);
}
}
private void reset(){
isModify=false;
temp=null;
this.setTitle("請輸入內容:(最多1000字)");
this.addCommand(ok);
this.addCommand(back);
this.addCommand(reset);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -