Advertisement
Guest User

GUI

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