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 streaming.gui; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.persistence.EntityManager; import javax.persistence.Persistence; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import streaming.entity.Pays; import streaming.entity.Serie; import streaming.exception.SynopsisVideException; import streaming.service.PaysService; import streaming.service.SerieService; /** * * @author admin */ @Component public class JDialogEditSerie extends javax.swing.JDialog { @Autowired private SerieService serieserv; @Autowired private PaysService pserv; private List<Pays> listePays = new ArrayList<Pays>(); private JPanelListeSerie jpSerie = null; /** * Creates new form JDialogEditSerie */ public void rafraichir() { listePays = pserv.listerTous(); initialiseComboBox(); setJpSerie(jpSerie); } public JDialogEditSerie() { initComponents(); setModal(true); } public JPanelListeSerie getJpSerie() { return jpSerie; } public void setJpSerie(JPanelListeSerie jpSerie) { this.jpSerie = jpSerie; } public void initialiseComboBox() { jComboBoxPays.removeAllItems(); for (Pays p : listePays) { jComboBoxPays.addItem(p.getNom()); } } /** * 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() { jLabelID = new javax.swing.JLabel(); jPanel1 = new javax.swing.JPanel(); jTextField1 = new javax.swing.JTextField(); jLabelTitre = new javax.swing.JLabel(); jPanel2 = new javax.swing.JPanel(); jTextFieldTitre = new javax.swing.JTextField(); jLabelAnnee = new javax.swing.JLabel(); jPanel3 = new javax.swing.JPanel(); jTextFieldAnnee = new javax.swing.JTextField(); jLabelPays = new javax.swing.JLabel(); jPanel4 = new javax.swing.JPanel(); jComboBoxPays = new javax.swing.JComboBox<>(); jLabelSynopsis = new javax.swing.JLabel(); jPanel5 = new javax.swing.JPanel(); jTextFieldSynopsis = new javax.swing.JTextField(); jPanel6 = new javax.swing.JPanel(); jPanel7 = new javax.swing.JPanel(); jButtonAjouter = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Ajout d'une Serie"); getContentPane().setLayout(new java.awt.GridLayout(6, 3)); jLabelID.setText("ID"); getContentPane().add(jLabelID); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 140, Short.MAX_VALUE)); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 50, Short.MAX_VALUE)); getContentPane().add(jPanel1); jTextField1.setEditable(false); getContentPane().add(jTextField1); jLabelTitre.setText("Titre"); getContentPane().add(jLabelTitre); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 140, Short.MAX_VALUE)); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 50, Short.MAX_VALUE)); getContentPane().add(jPanel2); getContentPane().add(jTextFieldTitre); jLabelAnnee.setText("Anne de production"); getContentPane().add(jLabelAnnee); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 140, Short.MAX_VALUE)); jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 50, Short.MAX_VALUE)); getContentPane().add(jPanel3); getContentPane().add(jTextFieldAnnee); jLabelPays.setText("Pays"); getContentPane().add(jLabelPays); javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); jPanel4.setLayout(jPanel4Layout); jPanel4Layout.setHorizontalGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 140, Short.MAX_VALUE)); jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 50, Short.MAX_VALUE)); getContentPane().add(jPanel4); jComboBoxPays.setModel( new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); jComboBoxPays.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jComboBoxPaysActionPerformed(evt); } }); getContentPane().add(jComboBoxPays); jLabelSynopsis.setText("Synopsis"); getContentPane().add(jLabelSynopsis); javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); jPanel5.setLayout(jPanel5Layout); jPanel5Layout.setHorizontalGroup(jPanel5Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 140, Short.MAX_VALUE)); jPanel5Layout.setVerticalGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 50, Short.MAX_VALUE)); getContentPane().add(jPanel5); getContentPane().add(jTextFieldSynopsis); javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6); jPanel6.setLayout(jPanel6Layout); jPanel6Layout.setHorizontalGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 140, Short.MAX_VALUE)); jPanel6Layout.setVerticalGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 50, Short.MAX_VALUE)); getContentPane().add(jPanel6); javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7); jPanel7.setLayout(jPanel7Layout); jPanel7Layout.setHorizontalGroup(jPanel7Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 140, Short.MAX_VALUE)); jPanel7Layout.setVerticalGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 50, Short.MAX_VALUE)); getContentPane().add(jPanel7); jButtonAjouter.setText("Ajouter"); jButtonAjouter.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonAjouterActionPerformed(evt); } }); getContentPane().add(jButtonAjouter); pack(); }// </editor-fold>//GEN-END:initComponents private void jButtonAjouterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAjouterActionPerformed // Ajout d'une nouvelle srie Serie serie = new Serie(); serie.setTitre(jTextFieldTitre.getText()); serie.setAnnee(Long.parseLong(jTextFieldAnnee.getText())); serie.setSynopsis(jTextFieldSynopsis.getText()); for (Pays p : listePays) { if (p.getNom().equals(jComboBoxPays.getSelectedItem())) { serie.setPays(p); } } try { serieserv.ajouter(serie); } catch (SynopsisVideException ex) { } jpSerie.rafraichirJTable(); this.setVisible(false); this.dispose(); }//GEN-LAST:event_jButtonAjouterActionPerformed private void jComboBoxPaysActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxPaysActionPerformed }//GEN-LAST:event_jComboBoxPaysActionPerformed /** * @param args the command line arguments */ // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButtonAjouter; private javax.swing.JComboBox<String> jComboBoxPays; private javax.swing.JLabel jLabelAnnee; private javax.swing.JLabel jLabelID; private javax.swing.JLabel jLabelPays; private javax.swing.JLabel jLabelSynopsis; private javax.swing.JLabel jLabelTitre; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel4; private javax.swing.JPanel jPanel5; private javax.swing.JPanel jPanel6; private javax.swing.JPanel jPanel7; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextFieldAnnee; private javax.swing.JTextField jTextFieldSynopsis; private javax.swing.JTextField jTextFieldTitre; // End of variables declaration//GEN-END:variables }