1 18 19 package sync4j.syncclient.demo; 20 21 import java.awt.BorderLayout ; 22 import java.awt.Button ; 23 import java.awt.GridLayout ; 24 import java.awt.Label ; 25 import java.awt.Panel ; 26 import java.awt.event.ActionEvent ; 27 import java.awt.event.ActionListener ; 28 29 import sync4j.foundation.pdi.contact.Contact; 30 31 38 public class ContactNew 39 extends Panel 40 implements ActionListener , ConfigurationParameters { 41 42 44 46 private MainWindow mw = null ; 50 51 private ContactForm form = null ; 52 private CheckContactFields cfields = null ; 53 54 private Language ln = new Language() ; 55 56 58 63 public ContactNew(MainWindow mw) { 64 65 Button butOk = null ; 66 Button butCancel = null ; 67 Panel buttonPanel = null ; 68 Label title = null ; 69 70 this.mw = mw; 71 72 setLayout (new BorderLayout () ) ; 73 title = new Label (ln.getString ("new_contact") ) ; 74 form = new ContactForm (mw ) ; 75 76 butOk = new Button (ln.getString ("ok") ) ; 77 butOk.setActionCommand ("ok" ) ; 78 butOk.addActionListener (this ) ; 79 80 butCancel = new Button (ln.getString ("cancel" ) ) ; 81 butCancel.setActionCommand ("cancel" ) ; 82 butCancel.addActionListener (this ) ; 83 84 buttonPanel = new Panel (); 85 buttonPanel.setLayout(new GridLayout (1, 2)); 86 buttonPanel.add (butOk ) ; 87 buttonPanel.add (butCancel ) ; 88 89 add(title , BorderLayout.NORTH ) ; 90 add(form , BorderLayout.CENTER ) ; 91 add(buttonPanel , BorderLayout.SOUTH ) ; 92 93 } 94 95 100 public void actionPerformed(ActionEvent evt) { 101 if (evt.getActionCommand().equals("ok")) { 102 103 cfields = new CheckContactFields(mw, form); 104 if (!cfields.areFieldsRight()) { 105 cfields.show(); 106 mw.setEnabled(false); 107 } else { 108 saveContact(); 109 } 110 } else if (evt.getActionCommand().equals("cancel")) { 111 mw.show(KEY_CONTACTLIST); 112 } 113 } 114 115 117 121 protected void blankFields() { 122 form.blankFields(); 123 } 124 125 127 130 private void saveContact() { 131 mw.writeNewContact(form.getFields()); 132 mw.show(KEY_CONTACTLIST); 133 } 134 135 } | Popular Tags |