Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package Ekon; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.TreeMap; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.table.DefaultTableModel; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; /** * * @author George */ public class PanelVypisZamestnancu extends javax.swing.JPanel { private VytvoreniFirmy vytvorFirmy; private Firma aktualniFirma; private String aktualniNazev; private String aktualniPrijmeni; public PanelVypisZamestnancu(VytvoreniFirmy vytvorFirmy) { initComponents(); this.vytvorFirmy = vytvorFirmy; aktualniFirma = null; aktualniNazev = null; aktualniPrijmeni = null; } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel14 = new javax.swing.JLabel(); panelVyhledani = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); txtFVyhledatF = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); lblNalezenoF = new javax.swing.JLabel(); btnVyhledatF = new javax.swing.JButton(); panelOvladani = new javax.swing.JPanel(); panelUkladani = new javax.swing.JPanel(); btnNactiZeSouboru = new javax.swing.JButton(); btnNactiXLS = new javax.swing.JButton(); btnUlozDoSouboru = new javax.swing.JButton(); btnUlozXLS = new javax.swing.JButton(); btnEditace = new javax.swing.JButton(); btnVypis = new javax.swing.JButton(); panelEditace = new javax.swing.JPanel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); jLabel10 = new javax.swing.JLabel(); jLabel11 = new javax.swing.JLabel(); jLabel12 = new javax.swing.JLabel(); jLabel13 = new javax.swing.JLabel(); jLabel15 = new javax.swing.JLabel(); jLabel16 = new javax.swing.JLabel(); jLabel17 = new javax.swing.JLabel(); txtFJmeno = new javax.swing.JTextField(); txtFPrijmeni = new javax.swing.JTextField(); txtFTitul = new javax.swing.JTextField(); txtFMesto = new javax.swing.JTextField(); txtFUlice = new javax.swing.JTextField(); txtFPSC = new javax.swing.JTextField(); cmbKraj = new javax.swing.JComboBox(); txtFDatumNar = new javax.swing.JTextField(); txtFRodneC = new javax.swing.JTextField(); txtFEmail = new javax.swing.JTextField(); txtFTelefon = new javax.swing.JTextField(); txtFNarodnost = new javax.swing.JTextField(); cmbPozice = new javax.swing.JComboBox(); btnUloz = new javax.swing.JButton(); btnSmaz = new javax.swing.JButton(); panelTabulka = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); tableZamestnanci = new javax.swing.JTable(); jLabel14.setText("jLabel14"); setLayout(new java.awt.BorderLayout()); panelVyhledani.setBorder(javax.swing.BorderFactory.createEtchedBorder()); jLabel1.setText("Nazev firmy :"); jLabel2.setText("Stav : "); btnVyhledatF.setText("Vyhledat"); btnVyhledatF.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnVyhledatFActionPerformed(evt); } }); javax.swing.GroupLayout panelVyhledaniLayout = new javax.swing.GroupLayout(panelVyhledani); panelVyhledani.setLayout(panelVyhledaniLayout); panelVyhledaniLayout.setHorizontalGroup( panelVyhledaniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelVyhledaniLayout.createSequentialGroup().addContainerGap() .addGroup(panelVyhledaniLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(panelVyhledaniLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(lblNalezenoF, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txtFVyhledatF, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent( btnVyhledatF, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE))); panelVyhledaniLayout.setVerticalGroup( panelVyhledaniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelVyhledaniLayout.createSequentialGroup().addContainerGap() .addGroup(panelVyhledaniLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(txtFVyhledatF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnVyhledatF)) .addGap(18, 18, 18) .addGroup(panelVyhledaniLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2).addComponent(lblNalezenoF)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); add(panelVyhledani, java.awt.BorderLayout.PAGE_START); panelOvladani.setBorder(javax.swing.BorderFactory.createEtchedBorder()); panelUkladani.setBorder(javax.swing.BorderFactory.createEtchedBorder()); btnNactiZeSouboru.setText("Nacti"); btnNactiZeSouboru.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnNactiZeSouboruActionPerformed(evt); } }); btnNactiXLS.setText("Nacti z xls"); btnNactiXLS.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnNactiXLSActionPerformed(evt); } }); btnUlozDoSouboru.setText("Uloz"); btnUlozDoSouboru.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnUlozDoSouboruActionPerformed(evt); } }); btnUlozXLS.setText("Uloz xls"); btnUlozXLS.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnUlozXLSActionPerformed(evt); } }); btnEditace.setText("Edit"); btnEditace.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnEditaceActionPerformed(evt); } }); btnVypis.setText("Vypis"); btnVypis.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnVypisActionPerformed(evt); } }); javax.swing.GroupLayout panelUkladaniLayout = new javax.swing.GroupLayout(panelUkladani); panelUkladani.setLayout(panelUkladaniLayout); panelUkladaniLayout.setHorizontalGroup( panelUkladaniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnNactiZeSouboru, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnNactiXLS, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE) .addComponent(btnUlozDoSouboru, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnUlozXLS, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnEditace, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnVypis, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); panelUkladaniLayout .setVerticalGroup(panelUkladaniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelUkladaniLayout.createSequentialGroup().addComponent(btnNactiZeSouboru) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnNactiXLS) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnUlozDoSouboru) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnUlozXLS) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnEditace) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnVypis).addGap(0, 0, Short.MAX_VALUE))); panelEditace.setBorder(javax.swing.BorderFactory.createEtchedBorder()); jLabel4.setText("Jmno :"); jLabel5.setText("Pijmen :"); jLabel6.setText("Tiitul :"); jLabel7.setText("Mesto :"); jLabel8.setText("Ulice"); jLabel9.setText("PSC :"); jLabel10.setText("Kraj :"); jLabel11.setText("Datum nar. :"); jLabel12.setText("Rodne cislo :"); jLabel13.setText("Email :"); jLabel15.setText("Telefon :"); jLabel16.setText("Narodnost :"); jLabel17.setText("Pozice :"); cmbKraj.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Hlavn msto Praha", "Jiho?esk kraj", "Jihomoravsk kraj", "Karlovarsk kraj", "Krlovehradeck kraj", "Libereck kraj", "Moravskoslezsk kraj", "Olomouck kraj", "Pardubick kraj", "Plzesk kraj", "Stedo?esk kraj", "steck kraj", "Vyso?ina", "Zlnsk kraj" })); cmbPozice.setModel(new javax.swing.DefaultComboBoxModel( new String[] { "Zamstnanec", "Sekret/ka", "Manaer", "iditel" })); btnUloz.setText("Uloz"); btnUloz.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnUlozActionPerformed(evt); } }); btnSmaz.setText("Smaz"); btnSmaz.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnSmazActionPerformed(evt); } }); javax.swing.GroupLayout panelEditaceLayout = new javax.swing.GroupLayout(panelEditace); panelEditace.setLayout(panelEditaceLayout); panelEditaceLayout.setHorizontalGroup(panelEditaceLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelEditaceLayout.createSequentialGroup() .addGroup(panelEditaceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel4).addComponent(jLabel5).addComponent(jLabel6) .addComponent(jLabel7).addComponent(jLabel8).addComponent(jLabel9) .addComponent(jLabel10).addComponent(jLabel11).addComponent(jLabel12) .addComponent(jLabel13).addComponent(jLabel15).addComponent(jLabel16) .addComponent(jLabel17)) .addGap(12, 12, 12) .addGroup(panelEditaceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(txtFJmeno).addComponent(txtFPrijmeni).addComponent(txtFTitul) .addComponent(txtFMesto).addComponent(txtFUlice).addComponent(txtFPSC) .addComponent(cmbKraj, 0, 403, Short.MAX_VALUE).addComponent(txtFDatumNar) .addComponent(txtFRodneC).addComponent(txtFEmail).addComponent(txtFTelefon) .addComponent(txtFNarodnost) .addComponent(cmbPozice, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addGroup(panelEditaceLayout.createSequentialGroup().addComponent(btnUloz) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(btnSmaz) .addGap(0, 0, Short.MAX_VALUE))); panelEditaceLayout.setVerticalGroup(panelEditaceLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelEditaceLayout.createSequentialGroup().addGroup(panelEditaceLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jLabel4) .addComponent(txtFJmeno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(panelEditaceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel5).addComponent(txtFPrijmeni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(panelEditaceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel6).addComponent(txtFTitul, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(9, 9, 9) .addGroup(panelEditaceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel7).addComponent(txtFMesto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(panelEditaceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel8) .addComponent(txtFUlice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(panelEditaceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel9).addComponent(txtFPSC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(panelEditaceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel10).addComponent(cmbKraj, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(panelEditaceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel11).addComponent(txtFDatumNar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(panelEditaceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel12) .addComponent(txtFRodneC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(panelEditaceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel13).addComponent(txtFEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(panelEditaceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel15).addComponent(txtFTelefon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(panelEditaceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel16).addComponent(txtFNarodnost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(panelEditaceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cmbPozice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel17)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE) .addGroup(panelEditaceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnUloz).addComponent(btnSmaz)))); javax.swing.GroupLayout panelOvladaniLayout = new javax.swing.GroupLayout(panelOvladani); panelOvladani.setLayout(panelOvladaniLayout); panelOvladaniLayout.setHorizontalGroup(panelOvladaniLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelOvladaniLayout.createSequentialGroup() .addComponent(panelUkladani, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(panelEditace, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); panelOvladaniLayout.setVerticalGroup(panelOvladaniLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(panelUkladani, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(panelEditace, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); add(panelOvladani, java.awt.BorderLayout.PAGE_END); panelTabulka.setBorder(javax.swing.BorderFactory.createEtchedBorder()); tableZamestnanci.setModel(new javax.swing.table.DefaultTableModel(new Object[][] { }, new String[] { "Jmeno", "Prijmeni", "Titul", "Mesto", "Ulice", "PSC", "Kraj", "Datum Narozeni", "Rodne cislo", "Email", "Telefon", "Narodnost", "Pozice" })); jScrollPane1.setViewportView(tableZamestnanci); javax.swing.GroupLayout panelTabulkaLayout = new javax.swing.GroupLayout(panelTabulka); panelTabulka.setLayout(panelTabulkaLayout); panelTabulkaLayout.setHorizontalGroup( panelTabulkaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 590, Short.MAX_VALUE)); panelTabulkaLayout.setVerticalGroup(panelTabulkaLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelTabulkaLayout.createSequentialGroup().addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))); add(panelTabulka, java.awt.BorderLayout.CENTER); }// </editor-fold>//GEN-END:initComponents private void btnVyhledatFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVyhledatFActionPerformed aktualniNazev = txtFVyhledatF.getText(); aktualniFirma = vytvorFirmy.vyhledejFirmu(aktualniNazev); if (aktualniNazev != null) { lblNalezenoF.setText("Firma nalezena : " + aktualniFirma.getNazevFirmy()); } else { lblNalezenoF.setText("Firma nenalezena "); } }//GEN-LAST:event_btnVyhledatFActionPerformed private void btnNactiZeSouboruActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNactiZeSouboruActionPerformed ArrayList<Zamestnanec> list = new ArrayList<>(); FileInputStream fis = null; ObjectInputStream in = null; JFileChooser fch = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("objects obj", "obj"); fch.setFileFilter(filter); int returnVal = fch.showOpenDialog(this); try { if (returnVal == JFileChooser.APPROVE_OPTION) { File selectedFile = fch.getSelectedFile(); System.out.println(selectedFile.getName()); fis = new FileInputStream(selectedFile.getName()); in = new ObjectInputStream(fis); list = (ArrayList<Zamestnanec>) in.readObject(); aktualniFirma.setListZamestanancu(list); JOptionPane.showMessageDialog(this, "Nahravani firem se podarilo", "Informace", 1); } else if (returnVal == JFileChooser.CANCEL_OPTION) { JOptionPane.showMessageDialog(this, "Nevybrali jste soubor", "Informace", 1); } } catch (FileNotFoundException ex) { Logger.getLogger(PanelVypisFirem.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(PanelVypisFirem.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(PanelVypisFirem.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_btnNactiZeSouboruActionPerformed private void btnNactiXLSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNactiXLSActionPerformed JFileChooser fch = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("objects xls xlsx", "xls", "xlsx"); fch.setFileFilter(filter); int returnVal = fch.showOpenDialog(this); try { File nazevSouboru = fch.getSelectedFile(); ArrayList<Zamestnanec> list = new ArrayList<>(); FileInputStream file = new FileInputStream(nazevSouboru.getAbsoluteFile()); //Create Workbook instance holding reference to .xlsx file XSSFWorkbook workbookV = new XSSFWorkbook(nazevSouboru.getAbsolutePath()); //Get first/desired sheet from the workbook XSSFSheet sheetV = workbookV.getSheetAt(0); Iterator<Row> rowIT = sheetV.iterator(); rowIT.next(); while (rowIT.hasNext()) { Row row = rowIT.next(); Iterator<Cell> cellIt = row.cellIterator(); ArrayList<String> listO = new ArrayList<>(); while (cellIt.hasNext()) { Cell cell = cellIt.next(); switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC: // System.out.print(cell.getNumericCellValue() + " "); listO.add(String.valueOf((int) cell.getNumericCellValue())); break; case Cell.CELL_TYPE_STRING: listO.add(cell.getStringCellValue()); // System.out.print(cell.getStringCellValue() + " "); break; } } aktualniFirma.pridejZamestnance(new Zamestnanec(listO.get(0), listO.get(1), listO.get(2), listO.get(3), Integer.valueOf(listO.get(4)), listO.get(5), listO.get(6), listO.get(7), listO.get(8), Integer.valueOf(listO.get(9)), Integer.valueOf(listO.get(10)), listO.get(11), listO.get(12))); } file.close(); DefaultTableModel model = (DefaultTableModel) tableZamestnanci.getModel(); while (model.getRowCount() > 0) { model.removeRow(0); } Iterator it = aktualniFirma.dejIteratorZamestnancu(); try { for (Iterator it1 = it; it1.hasNext();) { Zamestnanec z = (Zamestnanec) it1.next(); model.addRow(new Object[] { z.getJmeno(), z.getPrijmeni(), z.getTitul(), z.getMesto(), z.getUlice(), z.getPsc(), z.getKraj(), z.getDatumNarozeni(), z.getRodneCislo(), z.getEmail(), z.getTelefoniCislo(), z.getNarodnost(), z.getPozice() }); } } catch (Exception e) { JOptionPane.showMessageDialog(this, "seznam zamestnancu je prazdny", "Chyba", 1); } } catch (Exception e) { e.printStackTrace(); } Iterator itF = vytvorFirmy.dejIterator(); for (Iterator it1 = itF; it1.hasNext();) { Firma f = (Firma) it1.next(); if (aktualniFirma.getNazevFirmy().equals(f.getNazevFirmy())) { f.setListZamestanancu(aktualniFirma.getListZamestanancu()); } } }//GEN-LAST:event_btnNactiXLSActionPerformed private void btnUlozDoSouboruActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUlozDoSouboruActionPerformed ArrayList<Zamestnanec> list = new ArrayList<>(); String name = null; FileOutputStream fos; ObjectOutputStream out; JFileChooser fc = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("objekty obj", "obj"); fc.setFileFilter(filter); int resault = fc.showSaveDialog(this); try { if (resault == JFileChooser.APPROVE_OPTION) { File fileSelected = fc.getSelectedFile(); System.out.println(fileSelected.getName()); list = aktualniFirma.getListZamestanancu(); fos = new FileOutputStream(fileSelected.getName()); out = new ObjectOutputStream(fos); out.writeObject(list); out.close(); JOptionPane.showMessageDialog(this, "Ulozeni firem se podarilo ", "Informace", 1); } } catch (FileNotFoundException ex) { Logger.getLogger(PanelVypisFirem.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(PanelVypisFirem.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_btnUlozDoSouboruActionPerformed private void btnUlozXLSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUlozXLSActionPerformed XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet("Zamestnanci"); Map<String, Object[]> data = new TreeMap<>(); data.put("1", new Object[] { "Jmeno", "Prijmeni", "Mesto", "Ulice", "PSC", "Kraj", "Titul", "Datum narozeni", "Email", "Telefonni cislo", "Rodne cislo", "Narodnost", "Pozice" }); int i = 2; for (Iterator it = aktualniFirma.dejIteratorZamestnancu(); it.hasNext();) { Zamestnanec z = (Zamestnanec) it.next(); data.put(String.valueOf(i++), new Object[] { z.getJmeno(), z.getPrijmeni(), z.getMesto(), z.getUlice(), z.getPsc(), z.getKraj(), z.getTitul(), z.getDatumNarozeni(), z.getEmail(), z.getTelefoniCislo(), z.getRodneCislo(), z.getNarodnost(), z.getPozice() }); } Set<String> keySet = data.keySet(); int rowNum = 0; for (String key : keySet) { Row row = sheet.createRow(rowNum++); Object[] objArr = data.get(key); int cellNum = 0; for (Object obj : objArr) { Cell cell = row.createCell(cellNum++); if (obj instanceof String) { cell.setCellValue((String) obj); } else if (obj instanceof Integer) { cell.setCellValue((Integer) obj); } } } JFileChooser fch = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("objects xls xlsx", "xls", "xlsx"); fch.setFileFilter(filter); int returnVal = fch.showSaveDialog(this); try { File nazevSouboru = fch.getSelectedFile(); FileOutputStream out = new FileOutputStream(nazevSouboru.getAbsolutePath()); workbook.write(out); out.close(); JOptionPane.showMessageDialog(this, "Sobour XLS/XLSX vytvoren", "Informace", 1); } catch (Exception e) { } }//GEN-LAST:event_btnUlozXLSActionPerformed private void btnEditaceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditaceActionPerformed DefaultTableModel model = (DefaultTableModel) tableZamestnanci.getModel(); // DefaultTableModel model = (DefaultTableModel) tableFirmy.getModel(); if (tableZamestnanci.getSelectedRow() == -1) { if (tableZamestnanci.getRowCount() == 0) { JOptionPane.showMessageDialog(this, "tabulka je prazdna", "Informace", 1); } else { JOptionPane.showMessageDialog(this, "Zvolte firmu z tabulky", "Informace", 1); } } else { txtFJmeno.setText(tableZamestnanci.getValueAt(tableZamestnanci.getSelectedRow(), 0).toString()); txtFPrijmeni.setText(tableZamestnanci.getValueAt(tableZamestnanci.getSelectedRow(), 1).toString()); txtFTitul.setText(tableZamestnanci.getValueAt(tableZamestnanci.getSelectedRow(), 2).toString()); txtFMesto.setText(tableZamestnanci.getValueAt(tableZamestnanci.getSelectedRow(), 3).toString()); txtFUlice.setText(tableZamestnanci.getValueAt(tableZamestnanci.getSelectedRow(), 4).toString()); txtFPSC.setText(tableZamestnanci.getValueAt(tableZamestnanci.getSelectedRow(), 5).toString()); txtFDatumNar.setText(tableZamestnanci.getValueAt(tableZamestnanci.getSelectedRow(), 7).toString()); txtFRodneC.setText(tableZamestnanci.getValueAt(tableZamestnanci.getSelectedRow(), 8).toString()); txtFEmail.setText(tableZamestnanci.getValueAt(tableZamestnanci.getSelectedRow(), 9).toString()); txtFTelefon.setText(tableZamestnanci.getValueAt(tableZamestnanci.getSelectedRow(), 10).toString()); txtFNarodnost.setText(tableZamestnanci.getValueAt(tableZamestnanci.getSelectedRow(), 11).toString()); } }//GEN-LAST:event_btnEditaceActionPerformed private void btnUlozActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUlozActionPerformed Iterator it = aktualniFirma.dejIteratorZamestnancu(); aktualniPrijmeni = txtFPrijmeni.getText(); for (Iterator it1 = it; it1.hasNext();) { Zamestnanec z = (Zamestnanec) it1.next(); if (aktualniPrijmeni.equals(z.getPrijmeni())) { z.setJmeno(txtFJmeno.getText()); z.setPrijmeni(txtFPrijmeni.getText()); z.setTitul(txtFTitul.getText()); z.setMesto(txtFMesto.getText()); z.setUlice(txtFUlice.getText()); z.setPsc(Integer.valueOf(txtFPSC.getText())); z.setDatumNarozeni(txtFDatumNar.getText()); z.setRodneCislo(Integer.valueOf(txtFRodneC.getText())); z.setTelefoniCislo(Integer.valueOf(txtFTelefon.getText())); z.setPozice(cmbPozice.getSelectedItem().toString()); z.setKraj(cmbKraj.getSelectedItem().toString()); z.setNarodnost(txtFNarodnost.getText()); tableZamestnanci.setValueAt(txtFJmeno.getText(), tableZamestnanci.getSelectedRow(), 0); tableZamestnanci.setValueAt(txtFPrijmeni.getText(), tableZamestnanci.getSelectedRow(), 1); tableZamestnanci.setValueAt(txtFTitul.getText(), tableZamestnanci.getSelectedRow(), 2); tableZamestnanci.setValueAt(txtFMesto.getText(), tableZamestnanci.getSelectedRow(), 3); tableZamestnanci.setValueAt(txtFUlice.getText(), tableZamestnanci.getSelectedRow(), 4); tableZamestnanci.setValueAt(txtFPSC.getText(), tableZamestnanci.getSelectedRow(), 5); tableZamestnanci.setValueAt(cmbKraj.getSelectedItem().toString(), tableZamestnanci.getSelectedRow(), 6); tableZamestnanci.setValueAt(txtFDatumNar.getText(), tableZamestnanci.getSelectedRow(), 7); tableZamestnanci.setValueAt(txtFRodneC.getText(), tableZamestnanci.getSelectedRow(), 8); tableZamestnanci.setValueAt(txtFEmail.getText(), tableZamestnanci.getSelectedRow(), 9); tableZamestnanci.setValueAt(txtFTelefon.getText(), tableZamestnanci.getSelectedRow(), 10); tableZamestnanci.setValueAt(txtFNarodnost.getText(), tableZamestnanci.getSelectedRow(), 11); tableZamestnanci.setValueAt(cmbPozice.getSelectedItem().toString(), tableZamestnanci.getSelectedRow(), 12); } } Iterator itF = vytvorFirmy.dejIterator(); for (Iterator it1 = itF; it1.hasNext();) { Firma f = (Firma) it1.next(); if (aktualniFirma.getNazevFirmy().equals(f.getNazevFirmy())) { f.setListZamestanancu(aktualniFirma.getListZamestanancu()); } } }//GEN-LAST:event_btnUlozActionPerformed private void btnVypisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVypisActionPerformed DefaultTableModel model = (DefaultTableModel) tableZamestnanci.getModel(); while (model.getRowCount() > 0) { model.removeRow(0); } Iterator it = aktualniFirma.dejIteratorZamestnancu(); try { for (Iterator it1 = it; it1.hasNext();) { Zamestnanec z = (Zamestnanec) it1.next(); model.addRow(new Object[] { z.getJmeno(), z.getPrijmeni(), z.getTitul(), z.getMesto(), z.getUlice(), z.getPsc(), z.getKraj(), z.getDatumNarozeni(), z.getRodneCislo(), z.getEmail(), z.getTelefoniCislo(), z.getNarodnost(), z.getPozice() }); } } catch (Exception e) { JOptionPane.showMessageDialog(this, "seznam zamestnancu je prazdny", "Chyba", 1); } }//GEN-LAST:event_btnVypisActionPerformed private void btnSmazActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSmazActionPerformed txtFDatumNar.setText(""); txtFEmail.setText(""); txtFJmeno.setText(""); txtFMesto.setText(""); txtFNarodnost.setText(""); txtFPSC.setText(""); txtFPrijmeni.setText(""); txtFRodneC.setText(""); txtFTelefon.setText(""); txtFTitul.setText(""); txtFUlice.setText(""); }//GEN-LAST:event_btnSmazActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnEditace; private javax.swing.JButton btnNactiXLS; private javax.swing.JButton btnNactiZeSouboru; private javax.swing.JButton btnSmaz; private javax.swing.JButton btnUloz; private javax.swing.JButton btnUlozDoSouboru; private javax.swing.JButton btnUlozXLS; private javax.swing.JButton btnVyhledatF; private javax.swing.JButton btnVypis; private javax.swing.JComboBox cmbKraj; private javax.swing.JComboBox cmbPozice; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel14; private javax.swing.JLabel jLabel15; private javax.swing.JLabel jLabel16; private javax.swing.JLabel jLabel17; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JLabel lblNalezenoF; private javax.swing.JPanel panelEditace; private javax.swing.JPanel panelOvladani; private javax.swing.JPanel panelTabulka; private javax.swing.JPanel panelUkladani; private javax.swing.JPanel panelVyhledani; private javax.swing.JTable tableZamestnanci; private javax.swing.JTextField txtFDatumNar; private javax.swing.JTextField txtFEmail; private javax.swing.JTextField txtFJmeno; private javax.swing.JTextField txtFMesto; private javax.swing.JTextField txtFNarodnost; private javax.swing.JTextField txtFPSC; private javax.swing.JTextField txtFPrijmeni; private javax.swing.JTextField txtFRodneC; private javax.swing.JTextField txtFTelefon; private javax.swing.JTextField txtFTitul; private javax.swing.JTextField txtFUlice; private javax.swing.JTextField txtFVyhledatF; // End of variables declaration//GEN-END:variables }