TP GL View

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

/*

* 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 View;

import javax.swing.JOptionPane;
import static javax.swing.JOptionPane.showMessageDialog;
import Control.ChefService;
import Control.Employe;

import Model.EmployeEntity;

/**
*
* @author KHALED
*/
public class EmployeView extends javax.swing.JFrame {

boolean verif = true;

/**
* Creates new form EmployeView
*/
public EmployeView() {
initComponents();
labService.setVisible(false);
txtService.setVisible(false);

/**
* 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() {

jLabel8 = new javax.swing.JLabel();


jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
comType = new javax.swing.JComboBox<>();
labNom = new javax.swing.JLabel();
txtNom = new javax.swing.JTextField();
labPrenom = new javax.swing.JLabel();
txtPrenom = new javax.swing.JTextField();
labAge = new javax.swing.JLabel();
txtAge = new javax.swing.JTextField();
labAdresse = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
txtAdresse = new javax.swing.JTextArea();
labService = new javax.swing.JLabel();
txtService = new javax.swing.JTextField();
btnEnregistrer = new javax.swing.JButton();
jLabel9 = new javax.swing.JLabel();

jLabel8.setText("jLabel8");

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Ajout d'un employé");
setBackground(new java.awt.Color(255, 255, 255));
setLocation(new java.awt.Point(250, 50));
setName("EmployeFrame"); // NOI18N
setResizable(false);

jPanel1.setBackground(java.awt.Color.orange);

jLabel1.setFont(new java.awt.Font("Times New Roman", 0, 36)); //


NOI18N
jLabel1.setText("Ajout d'un Employé");

jLabel2.setFont(new java.awt.Font("Times New Roman", 1, 14)); //


NOI18N
jLabel2.setText("Type");

comType.setModel(new javax.swing.DefaultComboBoxModel<>(new
String[] { "Employé", "Chef Service" }));
comType.setName("comType"); // NOI18N
comType.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
comTypeActionPerformed(evt);
}
});

labNom.setFont(new java.awt.Font("Times New Roman", 1, 14)); //


NOI18N
labNom.setText("Nom");

txtNom.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtNomActionPerformed(evt);
}
});

labPrenom.setFont(new java.awt.Font("Times New Roman", 1, 14)); //


NOI18N
labPrenom.setText("Prénom");

labAge.setFont(new java.awt.Font("Times New Roman", 1, 14)); //


NOI18N
labAge.setText("Age");

labAdresse.setFont(new java.awt.Font("Times New Roman", 1, 14)); //


NOI18N
labAdresse.setText("Adresse");

txtAdresse.setColumns(20);
txtAdresse.setRows(5);
jScrollPane1.setViewportView(txtAdresse);

labService.setFont(new java.awt.Font("Times New Roman", 1, 14)); //


NOI18N
labService.setText("Service");
btnEnregistrer.setIcon(new
javax.swing.ImageIcon(getClass().getResource("/Images/apply.png"))); //
NOI18N
btnEnregistrer.setText("Enregistrer");
btnEnregistrer.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnEnregistrerActionPerformed(evt);
}
});

jLabel9.setIcon(new
javax.swing.ImageIcon(getClass().getResource("/Images/kuser.png"))); //
NOI18N

javax.swing.GroupLayout jPanel1Layout = new


javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.Gro
upLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(101, 101, 101)
.addComponent(jLabel1))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(57, 57, 57)
.addGroup(jPanel1Layout.createParallelGroup(javax.s
wing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2)
.addGroup(jPanel1Layout.createParallelGroup(jav
ax.swing.GroupLayout.Alignment.LEADING)
.addComponent(labAdresse)
.addGroup(jPanel1Layout.createParallelGroup
(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(labPrenom)
.addComponent(labAge))
.addComponent(labNom,
javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(labService)))
.addGap(63, 63, 63)
.addGroup(jPanel1Layout.createParallelGroup(javax.s
wing.GroupLayout.Alignment.LEADING, false)
.addComponent(jScrollPane1,
javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(txtAge,
javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(txtPrenom,
javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(txtNom,
javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(comType, 0,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txtService))))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.Gro
upLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(64, 64, 64)
.addComponent(jLabel9))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(31, 31, 31)
.addComponent(btnEnregistrer,
javax.swing.GroupLayout.PREFERRED_SIZE, 144,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(55, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.Gro
upLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel9)
.addGap(41, 41, 41))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(27, 27, 27)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentP
lacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.s
wing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(comType,
javax.swing.GroupLayout.PREFERRED_SIZE, 29,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(27, 27, 27)))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.Gro
upLayout.Alignment.BASELINE)
.addComponent(labNom)
.addComponent(txtNom,
javax.swing.GroupLayout.PREFERRED_SIZE, 32,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(48, 48, 48)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.Gro
upLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(13, 13, 13)
.addComponent(labPrenom))
.addComponent(txtPrenom,
javax.swing.GroupLayout.PREFERRED_SIZE, 32,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(27, 27, 27)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.Gro
upLayout.Alignment.TRAILING)
.addComponent(labAge)
.addComponent(txtAge,
javax.swing.GroupLayout.PREFERRED_SIZE, 31,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.Gro
upLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(41, 41, 41)
.addComponent(labAdresse))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.Gro
upLayout.Alignment.BASELINE)
.addComponent(txtService,
javax.swing.GroupLayout.PREFERRED_SIZE, 31,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(labService)
.addComponent(btnEnregistrer,
javax.swing.GroupLayout.PREFERRED_SIZE, 47,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(97, Short.MAX_VALUE))
);

javax.swing.GroupLayout layout = new


javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1,
javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
);

pack();
}// </editor-fold>//GEN-END:initComponents

private void btnEnregistrerActionPerformed(java.awt.event.ActionEvent


evt) {//GEN-FIRST:event_btnEnregistrerActionPerformed
// TODO add your handling code here:
// Récupération des valeurs saisies sur l'interface
String nom = txtNom.getText();
String prenom = txtPrenom.getText();
String age = txtAge.getText();
String adresse = txtAdresse.getText();
// Conversion de la chaine de caractères Age en entier
int a = Integer.valueOf(age);

if (verif) { // le booleen verif est à true veut dire que c'est


Employé qui est selectionné comme Type sur l'interface
Employe e = new Employe(nom, prenom, a, adresse);
//Employe e = new Employe(nom,prenom,a,adresse);
e.description();
//EmployeEntity ee = new EmployeEntity();
JOptionPane.showMessageDialog(null, "Employé ajouté avec
succès", "Message de succès",
JOptionPane.INFORMATION_MESSAGE);
//ee.addEmploye(e);
} else { // ici le booleen verif est à false ce qui veut dire que
c'est Chef service qui est selectionné comme Type sur l'interface
String service = txtService.getText();
ChefService c = new ChefService(nom, prenom, a, adresse,
service);
c.description();
//EmployeEntity ee = new EmployeEntity();
JOptionPane.showMessageDialog(null, "Chef Service ajouté avec
succès", "Message de succès",
JOptionPane.INFORMATION_MESSAGE);
//ee.addChefService(c);

}
}//GEN-LAST:event_btnEnregistrerActionPerformed

private void txtNomActionPerformed(java.awt.event.ActionEvent evt)


{//GEN-FIRST:event_txtNomActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtNomActionPerformed

private void comTypeActionPerformed(java.awt.event.ActionEvent evt)


{//GEN-FIRST:event_comTypeActionPerformed
// TODO add your handling code here:
// L'action à executer lors d'une selection du Type (Employé ou
ChefService)
if ("Employé".equals(comType.getSelectedItem())) {
verif = true;
labService.setVisible(false);
txtService.setVisible(false);
} else {
verif = false;
labService.setVisible(true);
txtService.setVisible(true);
}
txtNom.setText(null);
txtPrenom.setText(null);
txtAge.setText(null);
txtAdresse.setText(null);
txtService.setText(null);
}//GEN-LAST:event_comTypeActionPerformed

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel
setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with
the default look and feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {

javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {

java.util.logging.Logger.getLogger(EmployeView.class.getName()).log(java.ut
il.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(EmployeView.class.getName()).log(java.ut
il.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(EmployeView.class.getName()).log(java.ut
il.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(EmployeView.class.getName()).log(java.ut
il.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new EmployeView().setVisible(true);
}
});
}

// Variables declaration - do not modify//GEN-BEGIN:variables


private javax.swing.JButton btnEnregistrer;
private javax.swing.JComboBox<String> comType;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel labAdresse;
private javax.swing.JLabel labAge;
private javax.swing.JLabel labNom;
private javax.swing.JLabel labPrenom;
private javax.swing.JLabel labService;
private javax.swing.JTextArea txtAdresse;
private javax.swing.JTextField txtAge;
private javax.swing.JTextField txtNom;
private javax.swing.JTextField txtPrenom;
private javax.swing.JTextField txtService;
// End of variables declaration//GEN-END:variables
}

You might also like