1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
|
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.*;
import javax.swing.border.Border;
public class FenetreSwing extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
//*********** Déclaration des Container *********\\
JPanel panel = new JPanel();
JPanel boutons = new JPanel();
JPanel infos = new JPanel();
JPanel pics = new JPanel();
JPanel i_selectionnee = new JPanel();
// ************* Déclaration des cadres ************
Border selection = BorderFactory.createLineBorder(Color.yellow,5);
Border bordure = BorderFactory.createLineBorder(Color.white);
Border cadre_image = BorderFactory.createLineBorder(Color.black,1);
Border cadre_informations = BorderFactory.createTitledBorder(" Informations ");
// ************* Déclaration des bouttons **************
JButton Ajouter = new JButton("Ajouter");
JButton Consulter = new JButton("Consulter");
JButton Rechercher = new JButton("Rechercher");
JButton Modifier = new JButton("Modifier");
JButton Supprimer = new JButton ("Supprimer");
// ************* Déclaration des Labels ***************
JLabel code = new JLabel (" Code de l'employé : ");
JLabel nom = new JLabel ("\nNom de l'employé : ");
JLabel prenom = new JLabel ("\nPrénom de l'employé : ");
JLabel age = new JLabel ("\nAge de l'employé : ");
JLabel salaire = new JLabel("\nSalaire de l'employé : ");
JScrollPane scrol = new JScrollPane(pics,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
FenetreAjouter fenetreAjouter = new FenetreAjouter(1);
FenetreAjouter fenetreModifier = new FenetreAjouter(4);
// ************* Constructeur ********************
public FenetreSwing() {
//this.setVisible(true);
this.setTitle("Gestion des employés");
this.setSize(800,600);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setContentPane(panel);
panel.setBackground(Color.white);
panel.setLayout(null);
panel.add(boutons);
panel.add(infos);
panel.add(pics);
panel.addMouseListener(new mlistner(2));
// ****** Configuration des bouttons du panel "boutons" ******\\
boutons.setLayout(null);
boutons.setBorder(bordure);
boutons.setBounds(25,400,200,165);
boutons.setBackground(Color.white);
boutons.add(Ajouter);
boutons.add(Rechercher);
boutons.add(Consulter);
boutons.add(Modifier);
boutons.add(Supprimer);
Ajouter.setBounds(20,10,160,30);
Ajouter.addActionListener(new actionAjout(1));
Rechercher.setBounds(20,40,160,30);
Consulter.setBounds(20,70,160,30);
Consulter.setEnabled(false);
Modifier.setBounds(20,100,160,30);
Modifier.setEnabled(false);
Supprimer.setBounds(20,130,160,30);
Supprimer.setEnabled(false);
// *********** Configuration du panel "infos" ********* \\
infos.setLayout(new GridLayout(5,1));
infos.setBackground(Color.white);
infos.setBorder(cadre_informations);
infos.setBounds(230,400,540,165);
infos.add(code);
infos.add(nom);
infos.add(prenom);
infos.add(age);
infos.add(salaire);
// ************** Configuration du panel "pics" ***********\\
pics.setLayout(new FlowLayout(FlowLayout.LEFT));
pics.setBorder(cadre_image);
pics.setBounds(40,20,730,360);
pics.setBackground(Color.white);
pics.add(scrol);
// pics.addMouseListener();
Ajouter.addMouseListener(new mlistner(1));
Consulter.addMouseListener(new mlistner(2));
Rechercher.addMouseListener(new mlistner(3));
Modifier.addMouseListener(new mlistner(4));
Supprimer.addMouseListener(new mlistner(5));
}
void initialiser_infos(){
code.setText("Pour afficher les informations sur les employés : ");
nom.setText("\t1) Double-cliquer sur un employé ");
prenom.setText("\t2) Cliquer (bouton droit) puis consulter ");
age.setText("");
salaire.setText("");
}
public class actionAjout implements ActionListener {
int i;
public actionAjout(int cas){
this.i = cas;
}
public void actionPerformed(ActionEvent e) {
switch(i){
case 1 :
//fenetreAjouter.initialiser();
fenetreAjouter.setLocationRelativeTo(null);
fenetreAjouter.setVisible(true);
break;
case 2 :
default :
}
}
}
class mlistner implements MouseListener{
int cas;
int k;
public mlistner(int i){
cas = i;
}
@Override
public void mouseClicked(MouseEvent e) {
JPanel j = (JPanel)e.getSource();
k = e.getClickCount();
switch(cas) {
case 1 :
if(i_selectionnee != null) i_selectionnee.setBorder(null);
j.setBorder(selection);
Consulter.setEnabled(true);
Modifier.setEnabled(true);
Supprimer.setEnabled(true);
break;
case 2 :
initialiser_infos();
Consulter.setEnabled(false);
Modifier.setEnabled(false);
Supprimer.setEnabled(false);
break;
}
}
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
}
} |
Partager