📄 newphoneui.java
字号:
/*
* Created on 2004-6-20
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.north.phonebook.ui;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
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 javax.microedition.lcdui.AlertType;
import com.north.phonebook.model.*;
/**
* @author P2800
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class NewPhoneUI extends Form implements CommandListener,
ItemStateListener
{
private UIController uicontroller;
private TextField nameField;
private ChoiceGroup choice;
private TextField mobileField;
private TextField phoneField;
private TextField emailField;
private int phoneIndex;
private int emailIndex;
public static final Command saveCommand = new Command("保存", Command.OK, 2);
public static final Command backCommand = new Command("返回", Command.BACK, 3);
public NewPhoneUI(UIController uicontroller)
{
super(Title.add_record);
this.uicontroller = uicontroller;
nameField = new TextField(Title.name, null, 25, TextField.ANY);
mobileField = new TextField(Title.mobile, null, 25,
TextField.PHONENUMBER);
choice = new ChoiceGroup(null, ChoiceGroup.MULTIPLE);
phoneField = new TextField(Title.phone, null, 25, TextField.PHONENUMBER);
emailField = new TextField(Title.email, null, 25, TextField.EMAILADDR);
choice.append(Title.detail+"cccccccc", null);
this.append(nameField);
this.append(mobileField);
this.append(choice);
this.addCommand(saveCommand);
this.addCommand(backCommand);
this.setCommandListener(this);
this.setItemStateListener(this);
}
public void clear()
{
nameField.setString("");
mobileField.setString("");
if (choice.isSelected(0))
{
phoneField.setString("");
emailField.setString("");
}
}
/*
* (non-Javadoc)
*
* @see javax.microedition.lcdui.CommandListener#commandAction(javax.microedition.lcdui.Command,
* javax.microedition.lcdui.Displayable)
*/
public void commandAction(Command arg0, Displayable arg1)
{
// TODO Auto-generated method stub
if (arg0 == backCommand)
{
uicontroller
.handleEvent(UIController.EventID.EVENT_NEWPHONE_BACK_MAINUI);
} else if (arg0 == saveCommand)
{
String userName = nameField.getString();
if (userName.length() == 0)
{
uicontroller.showAlert(Title.userNameNull, this,
AlertType.WARNING);
return;
}
String mobilePhone = mobileField.getString();
if (mobilePhone.length() == 0)
{
uicontroller.showAlert(Title.mobilePhoneNull, this,
AlertType.WARNING);
return;
}
String phone = "";
String email = "";
if (choice.isSelected(0))
{
phone = phoneField.getString();
email = emailField.getString();
}
Account newAccount = new Account(userName, mobilePhone, phone,
email);
uicontroller.handleEvent(
UIController.EventID.EVENT_SAVE_RECORD_SELECTED,
new Object[] { newAccount });
}
}
public void itemStateChanged(Item item)
{
if (item == choice)
{
if (choice.isSelected(0))
{
phoneIndex = this.append(phoneField);
emailIndex = this.append(emailField);
} else
{
this.delete(emailIndex);
this.delete(phoneIndex);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -