📄 friendlist.java
字号:
/**
* @(#)FriendList.java
* Copyright (c) 2004-2005 wuhua of workroom Inc. All Rights Reserved.
* @version 1.0, 10/05/2004
* @author 饶荣庆
* @author
*/
package com.j2me.phonebook;
import com.j2me.main.*;
import com.j2me.language.*;
import java.util.*;
import javax.microedition.lcdui.*;
/**
*此类的功能是用指定的方式排序用户。并把用户输出的列表上
*/
public class FriendList extends List implements CommandListener
{
private Display display = null;
private PhoneBookMenu phoneBookMenu = null;
private DetailInfoForm detailInfoForm = null;
public Command infoCommand = null;
public Command backCommand = null;
private String aString;
private PhoneBook pb = null;
private Vector vectorFriend = null;
private Enumeration enumerationVector;
private Friend friend;
private int sortBy;
public FriendList(String s, int _sortBy)
{
super(s, Choice.IMPLICIT);
this.sortBy = _sortBy; //以指定方式来列表。0为姓名,1为id
this.infoCommand = new Command("详细信息", Command.OK, 2);
this.backCommand = new Command("返回", Command.BACK, 2);
this.addCommand(backCommand);
this.addCommand(infoCommand);
this.setCommandListener(this);
}
public void showForm(Display display, PhoneBookMenu phoneBookMenu) //用来显示界面
{
this.initList();
this.display = display;
this.phoneBookMenu = phoneBookMenu;
this.display.setCurrent(this);
}
public void initList()
{
this.pb = new PhoneBook();
this.vectorFriend = pb.getAllFriends(sortBy); //根据指定的排序方式,获得Friend对象
if (vectorFriend.isEmpty())
{
this.removeCommand(infoCommand);
}
else
{
this.addCommand(infoCommand);
}
this.enumerationVector = vectorFriend.elements();
this.pb.closeRS();
while (enumerationVector.hasMoreElements()) //把存储的对象一个个读出来并显示在列表上
{
friend = (Friend)enumerationVector.nextElement();
if (friend.getID()<10)
{
this.append("00" + friend.getID() + "|" + friend.getName(), null);
}
else if (friend.getID()<100)
{
this.append("0" + friend.getID() + "|" + friend.getName(), null);
}
else
{
this.append(friend.getID() + "|" + friend.getName(), null);
}
}
}
public void commandAction(Command c,Displayable s)
{
if(c == backCommand)
{
this.display.setCurrent(phoneBookMenu);
}
if (c == infoCommand)
{
if (Language.isEnglish == true) //修改语言为英文
{
this.detailInfoForm = new DetailInfoForm("Detail Info");
this.detailInfoForm.idItem.setLabel("ID:");
this.detailInfoForm.nameItem.setLabel("Name:");
this.detailInfoForm.phoneItem.setLabel("Phone:");
this.detailInfoForm.eMailItem.setLabel("Email:");
}
else
{
this.detailInfoForm = new DetailInfoForm("详细信息");
this.detailInfoForm.idItem.setLabel("ID:");
this.detailInfoForm.nameItem.setLabel("姓名:");
this.detailInfoForm.phoneItem.setLabel("电话:");
this.detailInfoForm.eMailItem.setLabel("邮箱:");
}
this.detailInfoForm.showForm(display, phoneBookMenu, this.getString(this.getSelectedIndex()));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -