www.pudn.com > WordTip.zip > AddNewWord.java
/*
* Created on 2005-1-27
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package net.hyweb.ui;
import javax.microedition.lcdui.*;
import net.hyweb.wordmodel.*;
/**
* @author user
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class AddNewWord extends Form implements CommandListener, ItemStateListener{
private UIController uicontroller;
private Command okCommand;
private Command exitCommand;
private TextField enwordField;
private TextField cnwordField;
private TextField detailField;
private ChoiceGroup detailGroup;
private Alert alertEnWord;
private int detaillNumber;
/**
* @param arg0
*/
public AddNewWord(UIController uicontroller) {
super("AddNewWord");
this.uicontroller = uicontroller;
enwordField = new TextField("English Word", "", 20, TextField.ANY);
cnwordField = new TextField("Explaination", "", 20, TextField.ANY);
detailField = new TextField("Details", "", 60, TextField.ANY);
detailGroup = new ChoiceGroup("Detail Information?", Choice.MULTIPLE);
detailGroup.append("Yes", null);
this.append(enwordField);
this.append(cnwordField);
this.append(detailGroup);
okCommand = new Command("Save", Command.OK, 1);
exitCommand = new Command("Back", Command.BACK, 2);
this.addCommand(okCommand);
this.addCommand(exitCommand);
setCommandListener(this);
setItemStateListener(this);
}
public void commandAction(Command command, Displayable display) {
if(command == okCommand){
String enword = enwordField.getString().trim();
String cnword = cnwordField.getString().trim();
if(enword.equals("")){
uicontroller.EventController(EventID.ALERT_ENWORD);
enword = null;
}else if(cnword.equals("")){
uicontroller.EventController(EventID.ALERT_CNWORD);
cnword = null;
}else if(detailField.getString() == null){
detailField.setString("");
}else{
//±£´æ¼Ç¼
this.save(enwordField.getString().trim(), cnwordField.getString().trim(), detailField.getString().trim());
}
}else if(command == exitCommand){
uicontroller.EventController(EventID.UI_MAIN);
}
}
public void save(String enword, String cnword, String detail){
Word word = new Word(enword, cnword, detail);
uicontroller.EventController(EventID.SAVE_WORD, new Object[]{word});
}
public void clearScreen(){
this.enwordField.setString("");
this.cnwordField.setString("");
this.detailField.setString("");
}
public void itemStateChanged(Item item) {
if(item == detailGroup){
if(detailGroup.isSelected(0)){
detaillNumber = append(detailField);
}else{
this.delete(detaillNumber);
}
}
}
}