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.swing; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import streaming.entity.Film; import streaming.entity.Genre; import streaming.entity.Lien; import streaming.entity.Pays; import streaming.entity.Realisateur; import streaming.exception.ExceptionSynopsisNullOuVide; import streaming.service.FilmService; import streaming.service.GenreService; import streaming.service.LienService; import streaming.service.PaysService; import streaming.service.RealisateurService; /** * * @author admin */ @Component public class JDialogFilm extends javax.swing.JDialog { @Autowired FilmService filmService; @Autowired GenreService genreService; @Autowired PaysService paysService; @Autowired RealisateurService realisateurService; @Autowired LienService lienService; @Autowired private JPannelListeFilm jpFilm; List<Genre> listeGenre; List<Realisateur> listeRealisateur; List<Pays> listePays; List<Lien> listeLien; public void refreshCombos() { listeGenre = genreService.listGenres(); listeRealisateur = realisateurService.listRealisateur(); listePays = paysService.listPays(); listeLien = lienService.listerLiens(); for (Genre g : listeGenre) jComboBoxGenre.addItem(g.getNom()); for (Pays p : listePays) JComboBoxPays.addItem(p.getNom()); for (Lien l : listeLien) jComboBoxLien.addItem(l.getWrl()); for (Realisateur r : listeRealisateur) jComboBoxRealisateur.addItem(r.getNom()); } public JDialogFilm() { this.setModal(true); initComponents(); // init(); } public JPannelListeFilm getJpFilm() { return jpFilm; } public void setJpFilm(JPannelListeFilm jpFilm) { this.jpFilm = jpFilm; } /** * Creates new form JDialogGenre */ // public JDialogFilm(java.awt.Frame parent, boolean modal, JPannelListeFilm jf) { // super(parent, modal); // initComponents(); // init(); // jpFilm=jf; // } /** * 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() { jLabel2 = new javax.swing.JLabel(); jPanel3 = new javax.swing.JPanel(); jTextField1 = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); jPanel4 = new javax.swing.JPanel(); jTextAnnee = new javax.swing.JTextField(); jLabel1 = new javax.swing.JLabel(); jPanel1 = new javax.swing.JPanel(); jTextTitre = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); jPanel6 = new javax.swing.JPanel(); jComboBoxGenre = new javax.swing.JComboBox<>(); jLabel5 = new javax.swing.JLabel(); jPanel7 = new javax.swing.JPanel(); JComboBoxPays = new javax.swing.JComboBox<>(); jLabel6 = new javax.swing.JLabel(); jPanel8 = new javax.swing.JPanel(); jComboBoxRealisateur = new javax.swing.JComboBox<>(); jLabel7 = new javax.swing.JLabel(); jPanel9 = new javax.swing.JPanel(); jComboBoxLien = new javax.swing.JComboBox<>(); jPanel2 = new javax.swing.JPanel(); jPanel5 = new javax.swing.JPanel(); jBAjouter = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Film"); getContentPane().setLayout(new java.awt.GridLayout(8, 3)); jLabel2.setText("ID"); getContentPane().add(jLabel2); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300, Short.MAX_VALUE)); jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 37, Short.MAX_VALUE)); getContentPane().add(jPanel3); jTextField1.setEditable(false); jTextField1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField1ActionPerformed(evt); } }); getContentPane().add(jTextField1); jLabel3.setText("Annee"); getContentPane().add(jLabel3); javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); jPanel4.setLayout(jPanel4Layout); jPanel4Layout.setHorizontalGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300, Short.MAX_VALUE)); jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 37, Short.MAX_VALUE)); getContentPane().add(jPanel4); jTextAnnee.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextAnneeActionPerformed(evt); } }); getContentPane().add(jTextAnnee); jLabel1.setText("Titre"); getContentPane().add(jLabel1); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300, Short.MAX_VALUE)); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 37, Short.MAX_VALUE)); getContentPane().add(jPanel1); jTextTitre.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextTitreActionPerformed(evt); } }); getContentPane().add(jTextTitre); jLabel4.setText("Genre"); getContentPane().add(jLabel4); javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6); jPanel6.setLayout(jPanel6Layout); jPanel6Layout.setHorizontalGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300, Short.MAX_VALUE)); jPanel6Layout.setVerticalGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 37, Short.MAX_VALUE)); getContentPane().add(jPanel6); jComboBoxGenre.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "" })); jComboBoxGenre.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jComboBoxGenreActionPerformed(evt); } }); getContentPane().add(jComboBoxGenre); jLabel5.setText("Pays"); getContentPane().add(jLabel5); javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7); jPanel7.setLayout(jPanel7Layout); jPanel7Layout.setHorizontalGroup(jPanel7Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300, Short.MAX_VALUE)); jPanel7Layout.setVerticalGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 37, Short.MAX_VALUE)); getContentPane().add(jPanel7); JComboBoxPays.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "" })); JComboBoxPays.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { JComboBoxPaysActionPerformed(evt); } }); getContentPane().add(JComboBoxPays); jLabel6.setText("Realisateur"); getContentPane().add(jLabel6); javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8); jPanel8.setLayout(jPanel8Layout); jPanel8Layout.setHorizontalGroup(jPanel8Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300, Short.MAX_VALUE)); jPanel8Layout.setVerticalGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 37, Short.MAX_VALUE)); getContentPane().add(jPanel8); jComboBoxRealisateur.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "" })); jComboBoxRealisateur.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jComboBoxRealisateurActionPerformed(evt); } }); getContentPane().add(jComboBoxRealisateur); jLabel7.setText("Lien"); getContentPane().add(jLabel7); javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9); jPanel9.setLayout(jPanel9Layout); jPanel9Layout.setHorizontalGroup(jPanel9Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300, Short.MAX_VALUE)); jPanel9Layout.setVerticalGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 37, Short.MAX_VALUE)); getContentPane().add(jPanel9); jComboBoxLien.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "" })); jComboBoxLien.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jComboBoxLienActionPerformed(evt); } }); getContentPane().add(jComboBoxLien); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300, Short.MAX_VALUE)); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 37, Short.MAX_VALUE)); getContentPane().add(jPanel2); javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); jPanel5.setLayout(jPanel5Layout); jPanel5Layout.setHorizontalGroup(jPanel5Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300, Short.MAX_VALUE)); jPanel5Layout.setVerticalGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 37, Short.MAX_VALUE)); getContentPane().add(jPanel5); jBAjouter.setText("Ajouter"); jBAjouter.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jBAjouterActionPerformed(evt); } }); getContentPane().add(jBAjouter); pack(); }// </editor-fold>//GEN-END:initComponents private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jTextField1ActionPerformed private void jTextTitreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextTitreActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jTextTitreActionPerformed private void jBAjouterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAjouterActionPerformed // TODO add your handling code here: int indGenre = jComboBoxGenre.getSelectedIndex(); int indPays = JComboBoxPays.getSelectedIndex(); int indLien = jComboBoxLien.getSelectedIndex(); int indRealisateur = jComboBoxRealisateur.getSelectedIndex(); Film f = new Film(genreService.rechercheGenre(indGenre), paysService.recherchePays(indPays), jTextTitre.getText(), "blab", Long.parseLong(jTextAnnee.getText())); f.setCreateurs((List<Realisateur>) realisateurService.rechercheRealisateur(indRealisateur)); f.setLiens((List<Lien>) lienService.rechercLien(indLien)); try { filmService.ajouter(f); } catch (ExceptionSynopsisNullOuVide ex) { Logger.getLogger(JDialogFilm.class.getName()).log(Level.SEVERE, null, ex); } this.jpFilm.rafraichirJTable(); this.setVisible(false); }//GEN-LAST:event_jBAjouterActionPerformed private void jTextAnneeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextAnneeActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jTextAnneeActionPerformed private void jComboBoxGenreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxGenreActionPerformed }//GEN-LAST:event_jComboBoxGenreActionPerformed private void JComboBoxPaysActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JComboBoxPaysActionPerformed // TODO add your handling code here: }//GEN-LAST:event_JComboBoxPaysActionPerformed private void jComboBoxRealisateurActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxRealisateurActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jComboBoxRealisateurActionPerformed private void jComboBoxLienActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxLienActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jComboBoxLienActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JComboBox<String> JComboBoxPays; private javax.swing.JButton jBAjouter; private javax.swing.JComboBox<String> jComboBoxGenre; private javax.swing.JComboBox<String> jComboBoxLien; private javax.swing.JComboBox<String> jComboBoxRealisateur; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; 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.JPanel jPanel8; private javax.swing.JPanel jPanel9; private javax.swing.JTextField jTextAnnee; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextTitre; // End of variables declaration//GEN-END:variables }