📄 viewnoteform.java
字号:
/*
* ViewNoteForm.java
*
* Created on 2007年3月15日, 上午10:09
*
* 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.Choice;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.DateField;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemStateListener;
import javax.microedition.lcdui.TextField;
import net.bccn.account.model.Note;
import net.bccn.account.util.Record;
import net.bccn.account.util.Util;
/**
*
* @author hadeslee
*/
public class ViewNoteForm extends Form implements CommandListener,ItemStateListener{
private static ViewNoteForm me;
private Command ok,back,reset,viewAll;
private DateField from,to;
private TextField content;
private ChoiceGroup dateSelect;
/** Creates a new instance of ViewNoteForm */
public ViewNoteForm() {
super("查询笔记");
initWindow();
}
private void initWindow(){
viewAll=new Command("查看所有",Command.OK,3);
ok=new Command("确定",Command.OK,1);
back=new Command("返回",Command.BACK,0);
reset=new Command("重置",Command.SCREEN,2);
from=new DateField("起始日期",DateField.DATE);
to=new DateField("结束日期",DateField.DATE);
from.setDate(new Date());
to.setDate(new Date());
content=new TextField("关键字:",null,10,TextField.ANY);
dateSelect=new ChoiceGroup("日期类型",Choice.POPUP,
new String[]{"不限","按日期","按期间"},null);
this.addCommand(ok);
this.addCommand(back);
this.addCommand(reset);
this.addCommand(viewAll);
this.append(content);
this.append(dateSelect);
this.setCommandListener(this);
this.setItemStateListener(this);
}
public static ViewNoteForm getInstance(){
if(me==null){
me=new ViewNoteForm();
}
return me;
}
private Note getCurrentNote(){
Note n=new Note();
n.setContent(content.getString());
int index=dateSelect.getSelectedIndex();
if(index==0){
n.setDate(null);
n.setFromDate(null);
}else if(index==1){
n.setDate(to.getDate());
n.setFromDate(null);
}else if(index==2){
n.setDate(to.getDate());
n.setFromDate(from.getDate());
}
return n;
}
public void commandAction(Command command, Displayable displayable) {
if(command==ok){
Record[] rds=Util.getAllRecords(getCurrentNote());
if(rds!=null){
Note[] ns=new Note[rds.length];
for(int i=0;i<ns.length;i++){
ns[i]=(Note)rds[i];
}
ViewNote.showViewNote(ns);
Util.changeTo(Util.VIEW_NOTE);
}
}else if(command==back){
Util.changeTo(Util.MAIN_FORM);
}else if(command==reset){
this.deleteAll();
dateSelect.setSelectedIndex(0,true);
this.append(content);
this.append(dateSelect);
this.content.setString(null);
}else if(command==viewAll){
Note note=new Note();
Record[] rds=Util.getAllRecords(note);
if(rds!=null){
Note[] ns=new Note[rds.length];
for(int i=0;i<ns.length;i++){
ns[i]=(Note)rds[i];
}
ViewNote.showViewNote(ns);
Util.changeTo(Util.VIEW_NOTE);
}
}
}
public void itemStateChanged(Item item){
if(item==dateSelect){
int index=dateSelect.getSelectedIndex();
if(index==0){
this.deleteAll();
this.append(content);
this.append(dateSelect);
}else if(index==1){
this.deleteAll();
this.append(content);
this.append(dateSelect);
to.setLabel("选择日期");
this.append(to);
to.setDate(new Date());
}else if(index==2){
this.deleteAll();
this.append(content);
this.append(dateSelect);
to.setLabel("结束日期");
this.append(from);
this.append(to);
from.setDate(new Date());
to.setDate(new Date());
}
}
if(dateSelect.getSelectedIndex()==2&&(item==to||item==from)){
Date fromD=from.getDate();
Date toD=to.getDate();
if(fromD.getTime()/86400000>toD.getTime()/86400000){
Util.showINFO(AlertType.ERROR,"起始日期不能大于结束日期!!");
if(item==to){
to.setDate(new Date());
}else{
from.setDate(new Date());
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -