1 6 7 package addressbook; 8 9 13 public class AddPersonDialog extends javax.swing.JDialog { 14 15 private static final int ACTION_CANCEL = 0; 16 private static final int ACTION_ADD = 1; 17 18 private int action; 19 private Person p; 20 21 22 public AddPersonDialog(java.awt.Frame parent, boolean modal) { 23 super(parent, modal); 24 initComponents(); 25 action = ACTION_CANCEL; 26 } 27 28 33 private void initComponents() { 35 jLabel1 = new javax.swing.JLabel (); 36 jLabel2 = new javax.swing.JLabel (); 37 jLabel4 = new javax.swing.JLabel (); 38 jLabel5 = new javax.swing.JLabel (); 39 jLabel6 = new javax.swing.JLabel (); 40 nameTxt = new javax.swing.JTextField (); 41 surnameTxt = new javax.swing.JTextField (); 42 streetTxt = new javax.swing.JTextField (); 43 cityTxt = new javax.swing.JTextField (); 44 countryTxt = new javax.swing.JTextField (); 45 jButton1 = new javax.swing.JButton (); 46 jButton2 = new javax.swing.JButton (); 47 48 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 49 setTitle("Add..."); 50 jLabel1.setText("Name:"); 51 52 jLabel2.setText("Surname:"); 53 54 jLabel4.setText("Street:"); 55 56 jLabel5.setText("City:"); 57 58 jLabel6.setText("Country:"); 59 60 jButton1.setText("Add"); 61 jButton1.addActionListener(new java.awt.event.ActionListener () { 62 public void actionPerformed(java.awt.event.ActionEvent evt) { 63 jButton1ActionPerformed(evt); 64 } 65 }); 66 67 jButton2.setText("Cancel"); 68 jButton2.addActionListener(new java.awt.event.ActionListener () { 69 public void actionPerformed(java.awt.event.ActionEvent evt) { 70 jButton2ActionPerformed(evt); 71 } 72 }); 73 74 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); 75 getContentPane().setLayout(layout); 76 layout.setHorizontalGroup( 77 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 78 .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup() 79 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 80 .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup() 81 .addContainerGap() 82 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 83 .add(jLabel1) 84 .add(jLabel2) 85 .add(jLabel4) 86 .add(jLabel5) 87 .add(jLabel6)) 88 .add(14, 14, 14) 89 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) 90 .add(countryTxt) 91 .add(cityTxt) 92 .add(streetTxt) 93 .add(surnameTxt) 94 .add(org.jdesktop.layout.GroupLayout.LEADING, nameTxt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 134, Short.MAX_VALUE))) 95 .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() 96 .add(70, 70, 70) 97 .add(jButton1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE) 98 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 99 .add(jButton2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE))) 100 .addContainerGap()) 101 ); 102 layout.setVerticalGroup( 103 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 104 .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup() 105 .addContainerGap() 106 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 107 .add(jLabel1) 108 .add(nameTxt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 109 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 110 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 111 .add(jLabel2) 112 .add(surnameTxt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 113 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 114 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 115 .add(jLabel4) 116 .add(streetTxt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 117 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 118 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 119 .add(jLabel5) 120 .add(cityTxt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 121 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 122 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 123 .add(jLabel6) 124 .add(countryTxt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 125 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 27, Short.MAX_VALUE) 126 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 127 .add(jButton1) 128 .add(jButton2)) 129 .addContainerGap()) 130 ); 131 pack(); 132 } 133 135 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { setVisible(false); 137 setAction(ACTION_ADD); 138 dispose(); 139 } 141 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { setVisible(false); 144 setAction(ACTION_CANCEL); 145 } 147 public Person getPerson() { 148 return p; 149 } 150 151 private void setAction(int i) { 152 action = i; 153 switch (i) { 154 case ACTION_CANCEL: 155 p = null; 156 break; 157 case ACTION_ADD: 158 p = new Person(); 159 p.setName(nameTxt.getText()); 160 p.setSurname(surnameTxt.getText()); 161 Address a = new Address(); 162 a.setCity(cityTxt.getText()); 163 a.setStreet(streetTxt.getText()); 164 a.setCountry(countryTxt.getText()); 165 p.setAddress(a); 166 break; 167 default: 168 } 169 } 170 171 public javax.swing.JTextField cityTxt; 173 public javax.swing.JTextField countryTxt; 174 public javax.swing.JButton jButton1; 175 public javax.swing.JButton jButton2; 176 public javax.swing.JLabel jLabel1; 177 public javax.swing.JLabel jLabel2; 178 public javax.swing.JLabel jLabel4; 179 public javax.swing.JLabel jLabel5; 180 public javax.swing.JLabel jLabel6; 181 public javax.swing.JTextField nameTxt; 182 public javax.swing.JTextField streetTxt; 183 public javax.swing.JTextField surnameTxt; 184 186 } 187 | Popular Tags |