KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > addressbook > AddPersonDialog


1 /*
2  * AddPersonDialog.java
3  *
4  * Created on 19. leden 2006, 13:53
5  */

6
7 package addressbook;
8
9 /**
10  *
11  * @author jungi
12  */

13 public class AddPersonDialog extends javax.swing.JDialog JavaDoc {
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     /** Creates new form AddPersonDialog */
22     public AddPersonDialog(java.awt.Frame JavaDoc parent, boolean modal) {
23     super(parent, modal);
24     initComponents();
25     action = ACTION_CANCEL;
26     }
27     
28     /** This method is called from within the constructor to
29      * initialize the form.
30      * WARNING: Do NOT modify this code. The content of this method is
31      * always regenerated by the Form Editor.
32      */

33     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
34
private void initComponents() {
35         jLabel1 = new javax.swing.JLabel JavaDoc();
36         jLabel2 = new javax.swing.JLabel JavaDoc();
37         jLabel4 = new javax.swing.JLabel JavaDoc();
38         jLabel5 = new javax.swing.JLabel JavaDoc();
39         jLabel6 = new javax.swing.JLabel JavaDoc();
40         nameTxt = new javax.swing.JTextField JavaDoc();
41         surnameTxt = new javax.swing.JTextField JavaDoc();
42         streetTxt = new javax.swing.JTextField JavaDoc();
43         cityTxt = new javax.swing.JTextField JavaDoc();
44         countryTxt = new javax.swing.JTextField JavaDoc();
45         jButton1 = new javax.swing.JButton JavaDoc();
46         jButton2 = new javax.swing.JButton JavaDoc();
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 JavaDoc() {
62             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
63                 jButton1ActionPerformed(evt);
64             }
65         });
66
67         jButton2.setText("Cancel");
68         jButton2.addActionListener(new java.awt.event.ActionListener JavaDoc() {
69             public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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     // </editor-fold>//GEN-END:initComponents
134

135     private void jButton1ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButton1ActionPerformed
136
setVisible(false);
137     setAction(ACTION_ADD);
138     dispose();
139     }//GEN-LAST:event_jButton1ActionPerformed
140

141     private void jButton2ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButton2ActionPerformed
142
// TODO add your handling code here:
143
setVisible(false);
144     setAction(ACTION_CANCEL);
145     }//GEN-LAST:event_jButton2ActionPerformed
146

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     // Variables declaration - do not modify//GEN-BEGIN:variables
172
public javax.swing.JTextField JavaDoc cityTxt;
173     public javax.swing.JTextField JavaDoc countryTxt;
174     public javax.swing.JButton JavaDoc jButton1;
175     public javax.swing.JButton JavaDoc jButton2;
176     public javax.swing.JLabel JavaDoc jLabel1;
177     public javax.swing.JLabel JavaDoc jLabel2;
178     public javax.swing.JLabel JavaDoc jLabel4;
179     public javax.swing.JLabel JavaDoc jLabel5;
180     public javax.swing.JLabel JavaDoc jLabel6;
181     public javax.swing.JTextField JavaDoc nameTxt;
182     public javax.swing.JTextField JavaDoc streetTxt;
183     public javax.swing.JTextField JavaDoc surnameTxt;
184     // End of variables declaration//GEN-END:variables
185

186 }
187
Popular Tags