Java Reference
In-Depth Information
ContactList contactList = PIM.openContactList(PIM.READ_WRITE);
Frame frame = new Frame("PimDemo");
ContactDialog contactDialog = new ContactDialog(frame,
contactList);
java.awt.List list = new java.awt.List();
Vector uids = new Vector();
Button editButton = new Button("edit");
Button addButton = new Button("add");
Button deleteButton = new Button("delete");
Button exitButton = new Button("exit");
public PimDemo() {
for (Enumeration e = contactList.elements();
e.hasMoreElements();) {
Contact c = (Contact) e.nextElement();
uids.addElement(c.getString(Contact.UID));
list.add(getLabel(c));
}
Panel buttonPane = new Panel();
buttonPane.add(editButton);
buttonPane.add(addButton);
buttonPane.add(deleteButton);
buttonPane.add(exitButton);
editButton.addActionListener(this);
addButton.addActionListener(this);
deleteButton.addActionListener(this);
exitButton.addActionListener(this);
frame.add(buttonPane, BorderLayout.SOUTH);
frame.add(list, BorderLayout.CENTER);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent ev) {
destroyApp(true);
notifyDestroyed();
}
} );
frame.pack();
}
Contact getContact(String uid) {
Contact template = contactList.createContact();
template.setString(Contact.UID, uid);
Enumeration e = contactList.elements(template);
return (Contact) e.nextElement();
}
String getLabel(Contact c) {
String label = c.getString(Contact.FORMATTED_NAME);
if (label == null)
label =
"" + c.getString(Contact.NAME_FAMILY) + ", " +
getString(Contact.NAME_GIVEN);
return label;
}
public void actionPerformed(ActionEvent ev) {
System.out.println("ev: " + ev);
if (ev.getSource() == addButton) {
Contact c = contactList.createContact();
if (contactDialog.edit(c, "New Contact")) {
list.add(getLabel(c));
uids.addElement(c.getString(Contact.UID));
Search WWH ::




Custom Search