Java Reference
In-Depth Information
iterated, and the TextField s are filled according to the corresponding content of the contact. If the
user confirms the dialog, the FieldInfo objects are iterated again, and the contents of the
TextField s, possibly altered by the user, are transferred back to the contact. Note that the transfer to
a contact object always needs to be committed to the database in order to become persistent.
Figure 7.2. The ContactDialog showing a sample contact.
The addField() method of the FieldPane inner class is not accessed in the ContactDialog
directly, but ContactDialog has its own addField() method. Depending on the given type
parameter, the STRING fields are added directly to the main FieldPane , whereas fields with
MULTIPLE subtypes are distributed to all corresponding panels. For this purpose, the subtypes
supported by the platform are queried using the getSupportedTypes() method. Then, for each
type, addSub() is called. In addSub() , the addField() method of the corresponding
FieldPane is called. Additional panels and choice entries are created as needed.
Note that the given add method supports string and multitype fields only, but no date or binary fields.
However, it should not be a problem to support those types by adding corresponding constants and user
interface elements.
Listing 7.1 ContactDialog.java —A Dialog for a Single Contact
import java.awt.*;
import java.awt.event.*;
import javax.microedition.pim.*;
import java.util.Hashtable;
import java.util.Vector;
public class ContactDialog extends Dialog
implements ItemListener, ActionListener {
Hashtable cards = new Hashtable();
Contact contact;
ContactList contactList;
Panel cardPane = new Panel(new CardLayout());
Choice typeChoice = new Choice();
Button okButton = new Button("ok");
Button cancelButton = new Button("cancel");
 
 
Search WWH ::




Custom Search