SHOW:
|
|
- or go back to the newest paste.
1 | package cartedetelefon.GUI; | |
2 | ||
3 | import cartedetelefon.CarteDeTelefon; | |
4 | import cartedetelefon.NrTel; | |
5 | import java.awt.Component; | |
6 | import java.awt.HeadlessException; | |
7 | import java.awt.event.ActionEvent; | |
8 | import java.awt.event.ActionListener; | |
9 | import java.io.File; | |
10 | import java.io.FileFilter; | |
11 | import java.io.IOException; | |
12 | import java.net.URL; | |
13 | import java.text.SimpleDateFormat; | |
14 | import java.util.Arrays; | |
15 | import java.util.Calendar; | |
16 | import java.util.GregorianCalendar; | |
17 | import java.util.List; | |
18 | import java.util.Timer; | |
19 | import java.util.TimerTask; | |
20 | import java.util.logging.Level; | |
21 | import java.util.logging.Logger; | |
22 | import javax.swing.ImageIcon; | |
23 | import javax.swing.JFileChooser; | |
24 | import javax.swing.JOptionPane; | |
25 | import javax.swing.table.TableRowSorter; | |
26 | ||
27 | public class GUI extends javax.swing.JFrame { | |
28 | ||
29 | private static final long serialVersionUID = 1L; | |
30 | ||
31 | private List<File> poze; | |
32 | private Timer timer1 = new Timer(); | |
33 | ||
34 | CarteDeTelefon model = new CarteDeTelefon(); | |
35 | ||
36 | @SuppressWarnings("unchecked") | |
37 | TableRowSorter sorter = new TableRowSorter(model); | |
38 | ||
39 | ||
40 | /** | |
41 | * Creates new form GUI | |
42 | */ | |
43 | @SuppressWarnings({"unchecked", "unchecked"}) | |
44 | public GUI() { | |
45 | initComponents(); | |
46 | jTable.setModel(model); | |
47 | ||
48 | try { | |
49 | jTable.setRowSorter(new TableRowSorter(model)); | |
50 | } catch (Exception e) { | |
51 | } | |
52 | ||
53 | jTable.setRowSorter(sorter); | |
54 | ||
55 | open.setEnabled(false); | |
56 | save.setEnabled(false); | |
57 | ||
58 | ||
59 | ||
60 | javax.swing.Timer timer2 = new javax.swing.Timer(1000, new ActionListener() { | |
61 | ||
62 | @Override | |
63 | public void actionPerformed(ActionEvent ae) { | |
64 | ||
65 | } | |
66 | }); | |
67 | timer2.start(); | |
68 | ||
69 | TimerTask task = new TimerTask() { | |
70 | ||
71 | @Override | |
72 | public void run() { | |
73 | displayBanner(); | |
74 | } | |
75 | }; | |
76 | ||
77 | ||
78 | timer1.schedule(task, 1000, 4000); | |
79 | ||
80 | ||
81 | } | |
82 | ||
83 | /** | |
84 | * This method is called from within the constructor to initialize the form. | |
85 | * WARNING: Do NOT modify this code. The content of this method is always | |
86 | * regenerated by the Form Editor. | |
87 | */ | |
88 | @SuppressWarnings("unchecked") | |
89 | // <editor-fold defaultstate="collapsed" desc="Generated Code"> | |
90 | private void initComponents() { | |
91 | ||
92 | jScrollPane2 = new javax.swing.JScrollPane(); | |
93 | jTable = new javax.swing.JTable(); | |
94 | tfNume = new javax.swing.JTextField(); | |
95 | jLabel1 = new javax.swing.JLabel(); | |
96 | jLabel2 = new javax.swing.JLabel(); | |
97 | tfPrenume = new javax.swing.JTextField(); | |
98 | jLabel3 = new javax.swing.JLabel(); | |
99 | tfCNP = new javax.swing.JTextField(); | |
100 | jLabel4 = new javax.swing.JLabel(); | |
101 | tfTel = new javax.swing.JTextField(); | |
102 | adauga = new javax.swing.JButton(); | |
103 | tfFilter = new javax.swing.JTextField(); | |
104 | cauta = new javax.swing.JButton(); | |
105 | iesire = new javax.swing.JButton(); | |
106 | sterge = new javax.swing.JButton(); | |
107 | modifica = new javax.swing.JButton(); | |
108 | jBan = new javax.swing.JLabel(); | |
109 | jMenuBar1 = new javax.swing.JMenuBar(); | |
110 | jMenu1 = new javax.swing.JMenu(); | |
111 | open = new javax.swing.JMenuItem(); | |
112 | save = new javax.swing.JMenuItem(); | |
113 | jSeparator1 = new javax.swing.JPopupMenu.Separator(); | |
114 | iesireM = new javax.swing.JMenuItem(); | |
115 | jMenu2 = new javax.swing.JMenu(); | |
116 | adaugaM = new javax.swing.JMenuItem(); | |
117 | cautaM = new javax.swing.JMenuItem(); | |
118 | modificaM = new javax.swing.JMenuItem(); | |
119 | stergeM = new javax.swing.JMenuItem(); | |
120 | jMenu3 = new javax.swing.JMenu(); | |
121 | inregistrare = new javax.swing.JMenuItem(); | |
122 | jSeparator2 = new javax.swing.JPopupMenu.Separator(); | |
123 | about = new javax.swing.JMenuItem(); | |
124 | ||
125 | setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); | |
126 | ||
127 | jTable.setModel(new javax.swing.table.DefaultTableModel( | |
128 | new Object [][] { | |
129 | {null, null, null, null}, | |
130 | {null, null, null, null}, | |
131 | {null, null, null, null}, | |
132 | {null, null, null, null} | |
133 | }, | |
134 | new String [] { | |
135 | "Title 1", "Title 2", "Title 3", "Title 4" | |
136 | } | |
137 | )); | |
138 | jScrollPane2.setViewportView(jTable); | |
139 | ||
140 | jLabel1.setText("Nume"); | |
141 | ||
142 | jLabel2.setText("Prenume"); | |
143 | ||
144 | jLabel3.setText("CNP"); | |
145 | ||
146 | jLabel4.setText("Telefon"); | |
147 | ||
148 | adauga.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N | |
149 | adauga.setMnemonic('A'); | |
150 | adauga.setText("Adauga"); | |
151 | adauga.setToolTipText("Adauga un contact nou"); | |
152 | adauga.addActionListener(new java.awt.event.ActionListener() { | |
153 | public void actionPerformed(java.awt.event.ActionEvent evt) { | |
154 | adaugaActionPerformed(evt); | |
155 | } | |
156 | }); | |
157 | ||
158 | tfFilter.addActionListener(new java.awt.event.ActionListener() { | |
159 | public void actionPerformed(java.awt.event.ActionEvent evt) { | |
160 | tfFilterActionPerformed(evt); | |
161 | } | |
162 | }); | |
163 | ||
164 | cauta.setMnemonic('c'); | |
165 | cauta.setText("Cauta"); | |
166 | cauta.addMouseListener(new java.awt.event.MouseAdapter() { | |
167 | public void mouseClicked(java.awt.event.MouseEvent evt) { | |
168 | cautaMouseClicked(evt); | |
169 | } | |
170 | }); | |
171 | cauta.addActionListener(new java.awt.event.ActionListener() { | |
172 | public void actionPerformed(java.awt.event.ActionEvent evt) { | |
173 | cautaActionPerformed(evt); | |
174 | } | |
175 | }); | |
176 | ||
177 | iesire.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N | |
178 | iesire.setForeground(new java.awt.Color(255, 0, 0)); | |
179 | iesire.setText("Iesire"); | |
180 | iesire.setToolTipText("Inchide aplicatie"); | |
181 | iesire.addActionListener(new java.awt.event.ActionListener() { | |
182 | public void actionPerformed(java.awt.event.ActionEvent evt) { | |
183 | iesireActionPerformed(evt); | |
184 | } | |
185 | }); | |
186 | ||
187 | sterge.setMnemonic('q'); | |
188 | sterge.setText("Sterge"); | |
189 | sterge.setToolTipText("Sterge contact"); | |
190 | sterge.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); | |
191 | sterge.addActionListener(new java.awt.event.ActionListener() { | |
192 | public void actionPerformed(java.awt.event.ActionEvent evt) { | |
193 | stergeActionPerformed(evt); | |
194 | } | |
195 | }); | |
196 | ||
197 | modifica.setMnemonic('m'); | |
198 | modifica.setText("Modifica"); | |
199 | modifica.setToolTipText("Modifica numar telefon"); | |
200 | modifica.addActionListener(new java.awt.event.ActionListener() { | |
201 | public void actionPerformed(java.awt.event.ActionEvent evt) { | |
202 | modificaActionPerformed(evt); | |
203 | } | |
204 | }); | |
205 | ||
206 | jBan.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); | |
207 | ||
208 | jMenu1.setMnemonic('f'); | |
209 | jMenu1.setText("File"); | |
210 | ||
211 | open.setMnemonic('o'); | |
212 | open.setText("Open"); | |
213 | open.setToolTipText("Deschide fiser contacte"); | |
214 | open.addActionListener(new java.awt.event.ActionListener() { | |
215 | public void actionPerformed(java.awt.event.ActionEvent evt) { | |
216 | openActionPerformed(evt); | |
217 | } | |
218 | }); | |
219 | jMenu1.add(open); | |
220 | ||
221 | save.setMnemonic('s'); | |
222 | save.setText("Save"); | |
223 | save.setToolTipText("Salveaza contactele"); | |
224 | save.addActionListener(new java.awt.event.ActionListener() { | |
225 | public void actionPerformed(java.awt.event.ActionEvent evt) { | |
226 | saveActionPerformed(evt); | |
227 | } | |
228 | }); | |
229 | jMenu1.add(save); | |
230 | jMenu1.add(jSeparator1); | |
231 | ||
232 | iesireM.setMnemonic('i'); | |
233 | iesireM.setText("Iesire"); | |
234 | iesireM.setToolTipText("Inchide aplicatia"); | |
235 | iesireM.addActionListener(new java.awt.event.ActionListener() { | |
236 | public void actionPerformed(java.awt.event.ActionEvent evt) { | |
237 | iesireMActionPerformed(evt); | |
238 | } | |
239 | }); | |
240 | jMenu1.add(iesireM); | |
241 | ||
242 | jMenuBar1.add(jMenu1); | |
243 | ||
244 | jMenu2.setText("Abonati"); | |
245 | ||
246 | adaugaM.setMnemonic('a'); | |
247 | adaugaM.setText("Adauga"); | |
248 | adaugaM.addActionListener(new java.awt.event.ActionListener() { | |
249 | public void actionPerformed(java.awt.event.ActionEvent evt) { | |
250 | adaugaMActionPerformed(evt); | |
251 | } | |
252 | }); | |
253 | jMenu2.add(adaugaM); | |
254 | ||
255 | cautaM.setMnemonic('c'); | |
256 | cautaM.setText("Cauta"); | |
257 | cautaM.addActionListener(new java.awt.event.ActionListener() { | |
258 | public void actionPerformed(java.awt.event.ActionEvent evt) { | |
259 | cautaMActionPerformed(evt); | |
260 | } | |
261 | }); | |
262 | jMenu2.add(cautaM); | |
263 | ||
264 | modificaM.setMnemonic('m'); | |
265 | modificaM.setText("Modifica"); | |
266 | modificaM.addActionListener(new java.awt.event.ActionListener() { | |
267 | public void actionPerformed(java.awt.event.ActionEvent evt) { | |
268 | modificaMActionPerformed(evt); | |
269 | } | |
270 | }); | |
271 | jMenu2.add(modificaM); | |
272 | ||
273 | stergeM.setMnemonic('q'); | |
274 | stergeM.setText("Sterge"); | |
275 | stergeM.addActionListener(new java.awt.event.ActionListener() { | |
276 | public void actionPerformed(java.awt.event.ActionEvent evt) { | |
277 | stergeMActionPerformed(evt); | |
278 | } | |
279 | }); | |
280 | jMenu2.add(stergeM); | |
281 | ||
282 | jMenuBar1.add(jMenu2); | |
283 | ||
284 | jMenu3.setMnemonic('h'); | |
285 | jMenu3.setText("Help"); | |
286 | ||
287 | inregistrare.setText("Inregistrare"); | |
288 | inregistrare.addActionListener(new java.awt.event.ActionListener() { | |
289 | public void actionPerformed(java.awt.event.ActionEvent evt) { | |
290 | inregistrareActionPerformed(evt); | |
291 | } | |
292 | }); | |
293 | jMenu3.add(inregistrare); | |
294 | jMenu3.add(jSeparator2); | |
295 | ||
296 | about.setText("About"); | |
297 | about.addActionListener(new java.awt.event.ActionListener() { | |
298 | public void actionPerformed(java.awt.event.ActionEvent evt) { | |
299 | aboutActionPerformed(evt); | |
300 | } | |
301 | }); | |
302 | jMenu3.add(about); | |
303 | ||
304 | jMenuBar1.add(jMenu3); | |
305 | ||
306 | setJMenuBar(jMenuBar1); | |
307 | ||
308 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); | |
309 | getContentPane().setLayout(layout); | |
310 | layout.setHorizontalGroup( | |
311 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
312 | .addGroup(layout.createSequentialGroup() | |
313 | .addContainerGap() | |
314 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) | |
315 | .addComponent(jScrollPane2) | |
316 | .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() | |
317 | .addComponent(tfFilter, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE) | |
318 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) | |
319 | .addComponent(cauta, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) | |
320 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) | |
321 | .addComponent(sterge, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) | |
322 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) | |
323 | .addComponent(modifica, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) | |
324 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | |
325 | .addComponent(iesire, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)) | |
326 | .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() | |
327 | .addComponent(jLabel1) | |
328 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) | |
329 | .addComponent(tfNume, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE) | |
330 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) | |
331 | .addComponent(jLabel2) | |
332 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) | |
333 | .addComponent(tfPrenume, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE) | |
334 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) | |
335 | .addComponent(jLabel3) | |
336 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) | |
337 | .addComponent(tfCNP, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE) | |
338 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) | |
339 | .addComponent(jLabel4) | |
340 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) | |
341 | .addComponent(tfTel, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE) | |
342 | .addGap(18, 18, 18) | |
343 | .addComponent(adauga, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)) | |
344 | .addComponent(jBan, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) | |
345 | .addContainerGap(19, Short.MAX_VALUE)) | |
346 | ); | |
347 | layout.setVerticalGroup( | |
348 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
349 | .addGroup(layout.createSequentialGroup() | |
350 | .addContainerGap() | |
351 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) | |
352 | .addComponent(jLabel1) | |
353 | .addComponent(tfNume, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) | |
354 | .addComponent(jLabel2) | |
355 | .addComponent(tfPrenume, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) | |
356 | .addComponent(jLabel3) | |
357 | .addComponent(tfCNP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) | |
358 | .addComponent(jLabel4) | |
359 | .addComponent(tfTel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) | |
360 | .addComponent(adauga)) | |
361 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) | |
362 | .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 397, javax.swing.GroupLayout.PREFERRED_SIZE) | |
363 | .addGap(27, 27, 27) | |
364 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) | |
365 | .addComponent(tfFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) | |
366 | .addComponent(cauta) | |
367 | .addComponent(sterge) | |
368 | .addComponent(modifica) | |
369 | .addComponent(iesire)) | |
370 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) | |
371 | .addComponent(jBan, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE) | |
372 | .addContainerGap()) | |
373 | ); | |
374 | ||
375 | pack(); | |
376 | }// </editor-fold> | |
377 | ||
378 | private void adaugaActionPerformed(java.awt.event.ActionEvent evt) { | |
379 | ||
380 | try { | |
381 | String nume = tfNume.getText(); | |
382 | String prenume = tfPrenume.getText(); | |
383 | String cnp = tfCNP.getText(); | |
384 | String nrtel = tfTel.getText(); | |
385 | ||
386 | for (int i = 0; i < jTable.getRowCount(); ++i) { | |
387 | if (cnp.equals(jTable.getValueAt(i, 2))) { | |
388 | JOptionPane.showMessageDialog(this, "CNP deja utilizat.", "Eroare", JOptionPane.ERROR_MESSAGE); | |
389 | return; | |
390 | } | |
391 | if (nrtel.equals(jTable.getValueAt(i, 3).toString())) { | |
392 | JOptionPane.showMessageDialog(this, "Numar telefon deja utilizat", "Eroare", JOptionPane.ERROR_MESSAGE); | |
393 | return; | |
394 | } | |
395 | ||
396 | } | |
397 | ||
398 | model.adaugareContact(nume, prenume, cnp, nrtel); | |
399 | ||
400 | tfNume.setText(""); | |
401 | tfPrenume.setText(""); | |
402 | tfCNP.setText(""); | |
403 | tfTel.setText(""); | |
404 | ||
405 | } catch (HeadlessException e) { | |
406 | } | |
407 | ||
408 | } | |
409 | ||
410 | private void openActionPerformed(java.awt.event.ActionEvent evt) { | |
411 | ||
412 | try { | |
413 | final JFileChooser fc = new JFileChooser(); | |
414 | ||
415 | if (evt.getSource() == open) { | |
416 | int returnVal = fc.showOpenDialog(GUI.this); | |
417 | ||
418 | if (returnVal == JFileChooser.APPROVE_OPTION) { | |
419 | try { | |
420 | try { | |
421 | model.incarcareContacte(); | |
422 | } catch (ClassNotFoundException ex) { | |
423 | Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex); | |
424 | } | |
425 | } catch (IOException ex) { | |
426 | Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex); | |
427 | } | |
428 | } | |
429 | } | |
430 | } catch (HeadlessException headlessException) { | |
431 | } | |
432 | ||
433 | } | |
434 | ||
435 | private void cautaMActionPerformed(java.awt.event.ActionEvent evt) { | |
436 | ||
437 | try { | |
438 | if (model.getRowCount() > 0) { | |
439 | for (int i = 0; i < model.getRowCount(); i++) { | |
440 | ||
441 | if (tfFilter.getText().equalsIgnoreCase((String) model.getValueAt(i, 0))) { | |
442 | jTable.setRowSelectionInterval(i, i); | |
443 | } else if (tfFilter.getText().equalsIgnoreCase((String) model.getValueAt(i, 1))) { | |
444 | jTable.setRowSelectionInterval(i, i); | |
445 | } else if (tfFilter.getText().equals(model.getValueAt(i, 2))) { | |
446 | jTable.setRowSelectionInterval(i, i); | |
447 | } else if (tfFilter.getText().equals(model.getValueAt(i, 3).toString())) { | |
448 | jTable.setRowSelectionInterval(i, i); | |
449 | } | |
450 | } | |
451 | } | |
452 | } catch (Exception e) { | |
453 | } | |
454 | ||
455 | } | |
456 | ||
457 | private void stergeMActionPerformed(java.awt.event.ActionEvent evt) { | |
458 | ||
459 | try { | |
460 | int selRow = jTable.getSelectedRow(); | |
461 | if (selRow != -1) { | |
462 | model.stergeContact(selRow); | |
463 | } | |
464 | ||
465 | tfNume.setText(""); | |
466 | tfPrenume.setText(""); | |
467 | tfCNP.setText(""); | |
468 | tfTel.setText(""); | |
469 | } catch (Exception e) { | |
470 | } | |
471 | ||
472 | } | |
473 | ||
474 | private void iesireMActionPerformed(java.awt.event.ActionEvent evt) { | |
475 | System.exit(0); | |
476 | } | |
477 | ||
478 | private void saveActionPerformed(java.awt.event.ActionEvent evt) { | |
479 | ||
480 | try { | |
481 | model.salvareContacte(); | |
482 | } catch (IOException ex) { | |
483 | Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex); | |
484 | } | |
485 | ||
486 | } | |
487 | ||
488 | private void aboutActionPerformed(java.awt.event.ActionEvent evt) { | |
489 | try { | |
490 | Component frame = null; | |
491 | JOptionPane.showMessageDialog(frame, "Agenda telefonica v1.1"); | |
492 | } catch (HeadlessException headlessException) { | |
493 | } | |
494 | } | |
495 | ||
496 | private void adaugaMActionPerformed(java.awt.event.ActionEvent evt) { | |
497 | ||
498 | try { | |
499 | String nume = tfNume.getText(); | |
500 | String prenume = tfPrenume.getText(); | |
501 | String cnp = tfCNP.getText(); | |
502 | String nrtel = tfTel.getText(); | |
503 | ||
504 | for (int i = 0; i < jTable.getRowCount(); ++i) { | |
505 | if (cnp.equals(jTable.getValueAt(i, 2))) { | |
506 | JOptionPane.showMessageDialog(this, "CNP deja utilizat.", "Eroare", JOptionPane.ERROR_MESSAGE); | |
507 | return; | |
508 | } | |
509 | if (nrtel.equals(jTable.getValueAt(i, 3).toString())) { | |
510 | JOptionPane.showMessageDialog(this, "Numar telefon deja utilizat", "Eroare", JOptionPane.ERROR_MESSAGE); | |
511 | return; | |
512 | } | |
513 | ||
514 | } | |
515 | ||
516 | model.adaugareContact(nume, prenume, cnp, nrtel); | |
517 | ||
518 | tfNume.setText(""); | |
519 | tfPrenume.setText(""); | |
520 | tfCNP.setText(""); | |
521 | tfTel.setText(""); | |
522 | ||
523 | } catch (HeadlessException e) { | |
524 | } | |
525 | ||
526 | } | |
527 | ||
528 | private void stergeActionPerformed(java.awt.event.ActionEvent evt) { | |
529 | ||
530 | try { | |
531 | int selRow = jTable.getSelectedRow(); | |
532 | if (selRow != -1) { | |
533 | model.stergeContact(selRow); | |
534 | } | |
535 | ||
536 | tfNume.setText(""); | |
537 | tfPrenume.setText(""); | |
538 | tfCNP.setText(""); | |
539 | tfTel.setText(""); | |
540 | } catch (Exception e) { | |
541 | } | |
542 | ||
543 | } | |
544 | ||
545 | private void modificaActionPerformed(java.awt.event.ActionEvent evt) { | |
546 | ||
547 | try { | |
548 | String cnp = JOptionPane.showInputDialog("Modifica CNP"); | |
549 | ||
550 | model.setValueAt(cnp, jTable.getSelectedRow(), 2); | |
551 | ||
552 | String tel = JOptionPane.showInputDialog("Modifica numarul de telefon"); | |
553 | ||
554 | NrTel nrtel = new NrTel(Integer.parseInt(tel)); | |
555 | jTable.getModel().setValueAt(nrtel, 0, 3); | |
556 | } catch (NumberFormatException numberFormatException) { | |
557 | } | |
558 | ||
559 | } | |
560 | ||
561 | private void iesireActionPerformed(java.awt.event.ActionEvent evt) { | |
562 | System.exit(0); | |
563 | } | |
564 | ||
565 | private void tfFilterActionPerformed(java.awt.event.ActionEvent evt) { | |
566 | try { | |
567 | if (model.getRowCount() > 0) { | |
568 | for (int i = 0; i < model.getRowCount(); i++) { | |
569 | ||
570 | if (tfFilter.getText().equalsIgnoreCase((String) model.getValueAt(i, 0))) { | |
571 | jTable.setRowSelectionInterval(i, i); | |
572 | } else if (tfFilter.getText().equalsIgnoreCase((String) model.getValueAt(i, 1))) { | |
573 | jTable.setRowSelectionInterval(i, i); | |
574 | } else if (tfFilter.getText().equals(model.getValueAt(i, 2))) { | |
575 | jTable.setRowSelectionInterval(i, i); | |
576 | } else if (tfFilter.getText().equals(model.getValueAt(i, 3).toString())) { | |
577 | jTable.setRowSelectionInterval(i, i); | |
578 | } | |
579 | } | |
580 | } | |
581 | } catch (Exception e) { | |
582 | } | |
583 | } | |
584 | ||
585 | private void cautaActionPerformed(java.awt.event.ActionEvent evt) { | |
586 | try { | |
587 | if (model.getRowCount() > 0) { | |
588 | for (int i = 0; i < model.getRowCount(); i++) { | |
589 | ||
590 | if (tfFilter.getText().equalsIgnoreCase((String) model.getValueAt(i, 0))) { | |
591 | jTable.setRowSelectionInterval(i, i); | |
592 | } else if (tfFilter.getText().equalsIgnoreCase((String) model.getValueAt(i, 1))) { | |
593 | jTable.setRowSelectionInterval(i, i); | |
594 | } else if (tfFilter.getText().equals(model.getValueAt(i, 2))) { | |
595 | jTable.setRowSelectionInterval(i, i); | |
596 | } else if (tfFilter.getText().equals(model.getValueAt(i, 3).toString())) { | |
597 | jTable.setRowSelectionInterval(i, i); | |
598 | } | |
599 | } | |
600 | } | |
601 | } catch (Exception e) { | |
602 | } | |
603 | } | |
604 | ||
605 | private void cautaMouseClicked(java.awt.event.MouseEvent evt) { | |
606 | ||
607 | } | |
608 | ||
609 | private void modificaMActionPerformed(java.awt.event.ActionEvent evt) { | |
610 | try { | |
611 | String cnp = JOptionPane.showInputDialog("Modifica CNP"); | |
612 | ||
613 | model.setValueAt(cnp, jTable.getSelectedRow(), 2); | |
614 | ||
615 | String tel = JOptionPane.showInputDialog("Modifica numarul de telefon"); | |
616 | ||
617 | NrTel nrtel = new NrTel(Integer.parseInt(tel)); | |
618 | jTable.getModel().setValueAt(nrtel, 0, 3); | |
619 | } catch (NumberFormatException numberFormatException) { | |
620 | } | |
621 | } | |
622 | ||
623 | private void inregistrareActionPerformed(java.awt.event.ActionEvent evt) { | |
624 | ||
625 | - | if (!cheie.equals("ticu")) { |
625 | + | |
626 | String cheie = JOptionPane.showInputDialog(this, "Cod de inregistrare:", "Inregistrare", JOptionPane.OK_CANCEL_OPTION); | |
627 | ||
628 | if (!cheie.equals("titi")) { | |
629 | - | t1.cancel(); |
629 | + | |
630 | } else { | |
631 | JOptionPane.showMessageDialog(this, "Cod acceptat!", "Corect", JOptionPane.PLAIN_MESSAGE); | |
632 | timer1.cancel(); | |
633 | jBan.setVisible(false); | |
634 | ||
635 | inregistrare.setEnabled(false); | |
636 | open.setEnabled(true); | |
637 | save.setEnabled(true); | |
638 | } | |
639 | } catch (HeadlessException headlessException) { | |
640 | } | |
641 | } | |
642 | ||
643 | private void displayBanner(){ | |
644 | URL url = getClass().getResource("/img"); | |
645 | File dir = new File(url.getPath()); | |
646 | ||
647 | File[] fisiere = dir.listFiles(new FileFilter() { | |
648 | ||
649 | @Override | |
650 | public boolean accept(File f) { | |
651 | return f.getName().toLowerCase().endsWith(".jpg"); | |
652 | } | |
653 | ||
654 | }); | |
655 | ||
656 | poze = Arrays.<File>asList(fisiere); | |
657 | ||
658 | int pic = (int) (Math.random()*3); | |
659 | ||
660 | File f = poze.get(pic); | |
661 | ImageIcon i = new ImageIcon(f.getAbsolutePath()); | |
662 | jBan.setText(""); | |
663 | jBan.setIcon(i); | |
664 | ||
665 | } | |
666 | ||
667 | /** | |
668 | * @param args the command line arguments | |
669 | */ | |
670 | public static void main(String args[]) { | |
671 | /* Set the Nimbus look and feel */ | |
672 | //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> | |
673 | /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. | |
674 | * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html | |
675 | */ | |
676 | try { | |
677 | for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { | |
678 | if ("Nimbus".equals(info.getName())) { | |
679 | javax.swing.UIManager.setLookAndFeel(info.getClassName()); | |
680 | break; | |
681 | } | |
682 | } | |
683 | } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) { | |
684 | java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
685 | } | |
686 | //</editor-fold> | |
687 | ||
688 | /* Create and display the form */ | |
689 | java.awt.EventQueue.invokeLater(new Runnable() { | |
690 | ||
691 | public void run() { | |
692 | try { | |
693 | Thread.sleep(3000); | |
694 | } catch (InterruptedException ex) { | |
695 | Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex); | |
696 | } | |
697 | new GUI().setVisible(true); | |
698 | } | |
699 | }); | |
700 | } | |
701 | ||
702 | // Variables declaration - do not modify | |
703 | private javax.swing.JMenuItem about; | |
704 | private javax.swing.JButton adauga; | |
705 | private javax.swing.JMenuItem adaugaM; | |
706 | private javax.swing.JButton cauta; | |
707 | private javax.swing.JMenuItem cautaM; | |
708 | private javax.swing.JButton iesire; | |
709 | private javax.swing.JMenuItem iesireM; | |
710 | private javax.swing.JMenuItem inregistrare; | |
711 | private javax.swing.JLabel jBan; | |
712 | private javax.swing.JLabel jLabel1; | |
713 | private javax.swing.JLabel jLabel2; | |
714 | private javax.swing.JLabel jLabel3; | |
715 | private javax.swing.JLabel jLabel4; | |
716 | private javax.swing.JMenu jMenu1; | |
717 | private javax.swing.JMenu jMenu2; | |
718 | private javax.swing.JMenu jMenu3; | |
719 | private javax.swing.JMenuBar jMenuBar1; | |
720 | private javax.swing.JScrollPane jScrollPane2; | |
721 | private javax.swing.JPopupMenu.Separator jSeparator1; | |
722 | private javax.swing.JPopupMenu.Separator jSeparator2; | |
723 | private javax.swing.JTable jTable; | |
724 | private javax.swing.JButton modifica; | |
725 | private javax.swing.JMenuItem modificaM; | |
726 | private javax.swing.JMenuItem open; | |
727 | private javax.swing.JMenuItem save; | |
728 | private javax.swing.JButton sterge; | |
729 | private javax.swing.JMenuItem stergeM; | |
730 | private javax.swing.JTextField tfCNP; | |
731 | private javax.swing.JTextField tfFilter; | |
732 | private javax.swing.JTextField tfNume; | |
733 | private javax.swing.JTextField tfPrenume; | |
734 | private javax.swing.JTextField tfTel; | |
735 | // End of variables declaration | |
736 | } |