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 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927
| import javax.swing.*;
//import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.border.*;
import javax.swing.JPopupMenu;
public class Interface1 extends JFrame implements MouseListener,ActionListener {
static Manager m;
public ArrayList lab=new ArrayList();
LinkedList<Employes> employe = new LinkedList<Employes>();
int W;
String Age1;
String Salaire1;
String Nom1;
String Prenom1;
// Crée un panneau
JPanel contenuFenêtre = new JPanel();
JPanel contenuBoutons = new JPanel();
JPanel contenuImage = new JPanel();
Panel panneauajouter = new Panel();
Panel panneauconsulter = new Panel();
JFrame framesupprimer=new JFrame("Confirmation");
JFrame frameajouter=new JFrame("Nouvel Employé");
JFrame frameconsulter=new JFrame("Infos");
JFrame find = new JFrame();
BorderLayout disposition = new BorderLayout();
GridLayout disposition1 = new GridLayout(1,6);
FlowLayout disposition2 = new FlowLayout();
JPanel contenuFenêtre2 = new JPanel();
JPanel contenuGril1 = new JPanel();
JPanel contenuGril2 = new JPanel();
JPanel contenuGril3 = new JPanel();
JPanel contenuGril4 = new JPanel();
JPanel contenuGril5 = new JPanel();
JPanel contenuGril6 = new JPanel();
GridLayout disposition5 = new GridLayout(7,1);
GridLayout disposition6 = new GridLayout(2,2);
BorderLayout disposition3 = new BorderLayout();
GridLayout disposition4 = new GridLayout(1,2);
JPanel panneausupprimer=new JPanel();
GridLayout dispo=new GridLayout(6,2);
JPanel contenuFenêtre4 = new JPanel();
JLabel imagefound = new JLabel(" ");
JButton lancer9 = new JButton("Fermer");
JLabel aa = new JLabel("Age : ");
JLabel aafound ;
JLabel ss = new JLabel("Salaire : ");
JLabel ssfound ;
JLabel nn = new JLabel("---Nom : ");
JLabel pp = new JLabel("Prénom : ");
JLabel walo = new JLabel("");
Border bord =new EtchedBorder();
// Graphics Gr ;
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
// Crée les contrôles en mémoire
JButton lancer= new JButton("Ajouter");
JButton lancer2=new JButton("Modifier");
JButton lancer3= new JButton("Supprimer");
JButton lancer4= new JButton("Consulter");
JButton lancer5 = new JButton("Rechercher");
JButton lancer6 = new JButton("Quitter");
JButton lancer7 = new JButton(" Modifier ");;
JButton lancer8;
JButton supprimer=new JButton("Supprimer");
JButton annuler=new JButton("Annuler");
JButton ajouter = new JButton("ajouter");;
JButton retour=new JButton("retour");
JButton retour2=new JButton("retour");
JLabel label1;
private JLabel snom=new JLabel();
private JLabel snom1=new JLabel();
private JLabel sprenom=new JLabel();
private JLabel sprenom1=new JLabel();
private JLabel ssalaire=new JLabel();
private JLabel ssalaire1=new JLabel();
private JLabel sage=new JLabel();
private JLabel sage1=new JLabel();
private JLabel simage = new JLabel();
JTextField age1 = new JTextField(10);
JTextField salaire1 =new JTextField(10);
JTextField nom1;
JTextField prenom1;
JTextField textnom=new JTextField();
JTextField textprenom=new JTextField();
JTextField textage=new JTextField();
JTextField textsalaire=new JTextField();
JTextField textimage=new JTextField();
JLabel image =new JLabel();
JLabel labnom1 =new JLabel();
JLabel nom =new JLabel("----Nom ------------------------- ");
JLabel prenom =new JLabel("----Prénom----------------------");
JLabel labprenom1 =new JLabel();
JLabel age =new JLabel("---- Age ------- ----------------");
JLabel salaire =new JLabel("---- Salaire ------- --------------");
MenuBar mb = new MenuBar();
Menu menu = new Menu(" Application ");
MenuItem quitter = new MenuItem(" Quitter ");
MenuItem rechercher = new MenuItem(" Rechercher");;
Menu m3 = new Menu(" Aide ");
MenuItem aide =new MenuItem(" A propos ");
JPopupMenu menucliq = new JPopupMenu () ;
JMenuItem SupprimerMenucliq = new JMenuItem ("Supprimer") ;
JMenuItem ModifierMenucliq = new JMenuItem ("Modifier") ;
JMenuItem ConsulterMenucliq = new JMenuItem ("Consulter") ;
Scrollbar scrol = new Scrollbar(Scrollbar.VERTICAL );
public Interface1() {
super();
supprimer.addActionListener(this);
annuler.addActionListener(this);
ajouter.addActionListener(this);
lancer7.addActionListener(this);
lancer.addActionListener(this);
lancer2.addActionListener(this);
lancer3.addActionListener(this);
lancer4.addActionListener(this);
lancer5.addActionListener(this);
lancer6.addActionListener(this);
retour.addActionListener(this);
retour2.addActionListener(this);
menucliq.add(SupprimerMenucliq) ;
SupprimerMenucliq.addActionListener (this) ;
menucliq.add(ModifierMenucliq) ;
ModifierMenucliq.addActionListener (this) ;
menucliq.add(ConsulterMenucliq) ;
ConsulterMenucliq.addActionListener (this) ;
try {
FInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void FInit() throws Exception {
this.setTitle("GESTION DU PERSONNEL");
// Positionne les dimensions
this.setSize(800,700);
// Menu
setMenuBar(mb);
mb.add(menu);
menu.add(rechercher);
menu.add(quitter);
mb.add(m3);
m3.add(aide);
rechercher.addActionListener (this) ;
quitter.addActionListener (this) ;
aide.addActionListener (this) ;
// Affecte un gestionnaire de disposition à ce panneau
contenuFenêtre.setLayout(disposition);
contenuBoutons.setLayout(disposition1);
contenuImage.setLayout(disposition2);
// Gr = contenuFenêtre.getGraphics();
// Ajoute les contrôles au panneau
contenuBoutons.add(lancer);
contenuBoutons.add(lancer2);
contenuBoutons.add(lancer3);
contenuBoutons.add(lancer4);
contenuBoutons.add(lancer5);
contenuBoutons.add(lancer6);
// contenuFenêtre.add("Center",contenuImage);
contenuFenêtre.add("South",contenuBoutons);
// Gr.setColor(Color.orange);
/* lancer.addActionListener(this);
lancer2.addActionListener(this);
lancer3.addActionListener(this);
lancer4.addActionListener(this);
lancer5.addActionListener(this);
lancer6.addActionListener(this);*/
try {
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
this_windowClosing(e);
}
});
}
catch(Exception e) {
e.printStackTrace();
}
lancer2.setEnabled(false);
lancer3.setEnabled(false);
lancer4.setEnabled(false);
setLocation(dim.width/2- getWidth()/2, dim.height/2 - this.getHeight()/2);
m = lire();
afficherImages(m);
contenuFenêtre.repaint();
// ajoute le pannel à l'objet et rend la fenêtre visible
contenuFenêtre.add("East",scrol);
scrol.setVisible(true);
this.setContentPane(contenuFenêtre);
this.setVisible(true);
}
void this_windowClosing(WindowEvent e) {
this.hide();
}
public void afficherImages(Manager m)
{
int x=10,y=10;
int k=0,j=0;
String tmp;
Employes tmpx;
Iterator i = m.l1.iterator();
while (i.hasNext()){
tmpx=(Employes)i.next();
tmp=tmpx.getImage();
lab.add(new JLabel());
((JLabel)lab.get(k)).setIcon(new ImageIcon(tmp));
((JLabel)lab.get(k)).setBounds(x,y,80,80);
((JLabel)lab.get(k)).setName(String.valueOf(k));
((JLabel)lab.get(k)).setVisible(true);
((JLabel)lab.get(k)).addMouseListener(this);
((JLabel)lab.get(k)).addMouseListener(new MouseAdapter()
{ public void mouseReleased (MouseEvent e)
{ { if (e.isPopupTrigger())
menucliq.show (e.getComponent(), e.getX(), e.getY()) ;
}
}
} ) ;
contenuImage.add((JLabel)lab.get(k));
x+=90;
k++;
j++;
if(j==6)
{
x=10;
y+=90;j=0;}
}
contenuImage.repaint();
contenuFenêtre.add("Center",contenuImage);
}
// Fonctions liées au boutons
public void Modifier(int i,Manager m)
{
contenuGril1.setLayout(disposition6);
contenuGril2.setLayout(disposition6);
contenuGril3.setLayout(disposition3);
contenuGril4.setLayout(disposition3);
contenuGril5.setLayout(disposition4);
contenuGril6.setLayout(disposition3);
contenuFenêtre2.setLayout(disposition5);
image.setIcon(new ImageIcon((m.l1.get(W)).getImage()));
labnom1.setText((m.l1.get(W)).getNom());
labprenom1.setText((m.l1.get(W)).getPrenom());
contenuGril5.add(image);
contenuGril1.add(nom);
contenuGril1.add(labnom1);
contenuGril1.add(prenom);
contenuGril1.add(labprenom1);
contenuGril5.add(contenuGril1);
contenuFenêtre2.add(contenuGril5);
contenuFenêtre2.add(age);
contenuFenêtre2.add(age1);
contenuFenêtre2.add(salaire);
contenuFenêtre2.add(salaire1);
// contenuFenêtre2.add(walo);
contenuFenêtre2.add(lancer7);
contenuFenêtre2.add(retour2);
age1.setEditable(true);
salaire1.setEditable(true);
this.setContentPane(contenuFenêtre2);
this.setTitle("Modification des données");
this.setVisible(true);
//lancer7.addActionListener(this);
}
public void Rechercher(Manager M){
find.setBounds(450, 250, 400, 200);
JPanel contenuFenêtre3 = new JPanel();
GridLayout disposition = new GridLayout(5,1);
contenuFenêtre3.setLayout(disposition);
JLabel findnom =new JLabel("Nom");
nom1 = new JTextField(10);
JLabel findprenom =new JLabel("Prénom");
prenom1 = new JTextField(10);
lancer8 = new JButton("Rechercher");
contenuFenêtre3.add(findnom);
contenuFenêtre3.add(nom1);
contenuFenêtre3.add(findprenom);
contenuFenêtre3.add(prenom1);
contenuFenêtre3.add(lancer8);
find.setContentPane(contenuFenêtre3);
find.setTitle("Recherche");
find.setVisible(true);
lancer8.addActionListener(this);
}
public void fenetresupprimer()
{
panneausupprimer.setLayout(dispo);
framesupprimer.setBounds(300,300,400,200);
panneausupprimer.add(snom1);
panneausupprimer.add(snom);
snom1.setText("Nom:");
snom.setText((m.l1.get(W)).getNom());
sprenom.setText((m.l1.get(W)).getPrenom());
panneausupprimer.add(sprenom1);
panneausupprimer.add(sprenom);
sprenom1.setText("Prénom:");
sage.setText(String.valueOf((m.l1.get(W)).getAge()));
panneausupprimer.add(sage1);
panneausupprimer.add(sage);
sage1.setText("Age:");
ssalaire.setText(String.valueOf((m.l1.get(W)).getSalaire()));
panneausupprimer.add(ssalaire1);
panneausupprimer.add(ssalaire);
ssalaire1.setText("Salaire:");
panneausupprimer.add(supprimer);
panneausupprimer.add(annuler);
// supprimer.addActionListener(this);
//annuler.addActionListener(this);
framesupprimer.setContentPane(panneausupprimer);
framesupprimer.setVisible(true);
framesupprimer.setLocation(dim.width/2- getWidth()/2, dim.height/2 - this.getHeight()/2);
}
public void fenetreajouter()
{
panneauajouter.setLayout(null);
//ajouter.addActionListener(this);
textnom.setText("");
textprenom.setText("");
textage.setText("");
textsalaire.setText("");
textimage.setText("");
textnom.setBounds(250, 50, 126, 26);
panneauajouter.add(textnom);
snom1.setBounds(100, 50, 50, 26);
snom1.setText("Nom:");
panneauajouter.add(snom1);
textprenom.setBounds(250, 100, 126, 26);
panneauajouter.add(textprenom);
sprenom1.setBounds(100, 100, 50, 26);
sprenom1.setText("Prénom:");
panneauajouter.add(sprenom1);
textage.setBounds(250, 150, 126, 26);
panneauajouter.add(textage);
sage1.setBounds(100, 150, 50, 26);
panneauajouter.add(sage1);
sage1.setText("Age:");
textsalaire.setBounds(250,200, 126, 26);
panneauajouter.add(textsalaire);
ssalaire1.setBounds(100,200, 50, 26);
panneauajouter.add(ssalaire1);
ssalaire1.setText("Salaire:");
textimage.setBounds(250,250, 126, 26);
panneauajouter.add(textimage);
simage.setBounds(100,250, 50, 26);
panneauajouter.add(simage);
simage.setText("Image:");
ajouter.setBounds(450,300,150,50);
panneauajouter.add(ajouter);
frameajouter.setContentPane(panneauajouter);
frameajouter.setLocation(dim.width/2- getWidth()/2, dim.height/2 - this.getHeight()/2);
frameajouter.setSize(650,400);
frameajouter.setVisible(true);
}
public void fenetreconsulter()
{
panneauconsulter.setLayout(null);
image.setIcon(new ImageIcon((m.l1.get(W)).getImage()));
image.setBounds( 0,0,150,150);
panneauconsulter.add(image);
snom.setBounds(225, 50, 126, 26);
panneauconsulter.add(snom);
snom1.setBounds(75, 50, 50, 26);
snom1.setText("Nom:");
panneauconsulter.add(snom1);
snom.setText((m.l1.get(W)).getNom());
sprenom.setText((m.l1.get(W)).getPrenom());
sprenom.setBounds(225, 100, 126, 26);
panneauconsulter.add(sprenom);
sprenom1.setBounds(75, 100, 50, 26);
sprenom1.setText("Prénom:");
panneauconsulter.add(sprenom1);
sage.setText(String.valueOf((m.l1.get(W)).getAge()));
sage.setBounds(225, 150, 126, 26);
panneauconsulter.add(sage);
sage1.setBounds(75, 150, 50, 26);
panneauconsulter.add(sage1);
sage1.setText("Age:");
ssalaire.setText(String.valueOf((m.l1.get(W)).getSalaire()));
ssalaire.setBounds(225,200, 126, 26);
panneauconsulter.add(ssalaire);
ssalaire1.setBounds(75,200, 50, 26);
panneauconsulter.add(ssalaire1);
ssalaire1.setText("Salaire:");
retour.setBounds(100,250,150,50);
panneauconsulter.add(retour);
frameconsulter.setContentPane(panneauconsulter);
frameconsulter.setSize(350,400);
frameconsulter.setLocation(dim.width/2- getWidth()/2, dim.height/2 - this.getHeight()/2);
frameconsulter.setVisible(true);
//retour.addActionListener(this);
}
// Gestion des événements
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if (source == lancer) { fenetreajouter();}
if (source == lancer2) {Modifier(W,m);
}
if (source == lancer3) { fenetresupprimer();}
if (source == supprimer)
{
m=lire();
m.l1.remove(m.l1.get(W));
sauvegarder(m);
framesupprimer.setVisible(false);
int c=lab.size();
for(int a=c-1;a>=0;a--)
{
((JLabel)lab.get(a)).setVisible(false);
lab.remove(a);
}
try {
FInit();
}
catch(Exception er) {
er.printStackTrace();
}
}
if (source == lancer4) { fenetreconsulter();}
if (source == lancer5) { Rechercher(m);}
if (source == lancer6) { System.exit(0);}
if (source == lancer7) {
Age1 = age1.getText();
Salaire1 = salaire1.getText();
Integer a1 = new Integer(Age1);
int A1 = a1.intValue();
m.l1.get(W).age= A1;
Integer s1 = new Integer(Salaire1);
int S1 = s1.intValue();
m.l1.get(W).Salaire = S1;
sauvegarder(m);
System.out.println(m.l1.get(W));
System.out.println("drdh"+ Age1);
System.out.println("gfrfds"+ salaire1.getText());
try {
FInit();
}
catch(Exception er) {
er.printStackTrace();
}
}
if (source == lancer8){
Nom1 = nom1.getText();
Prenom1 = prenom1.getText();
String N = new String(Nom1);
String P = new String(Prenom1);
Employes emp;
m =lire();
Iterator i = m.l1.iterator();
int b=employe.size();
for( int a=b-1;a>=0;a--)
{
employe.remove(a);
}
while (i.hasNext()){
emp=(Employes)i.next();
if (emp.nom.equals(N) && emp.prenom.equals(P))
{
employe.add(emp);
}
}
if (!employe.isEmpty()){
int k;
Integer g;
Double S;
k = employe.size();
find.setBounds(450, 150, 400, 150);
GridLayout dispofen4 = new GridLayout(k+1,9);
contenuFenêtre4.setLayout(dispofen4);
Iterator j = employe.iterator();
while (j.hasNext()){
emp =(Employes)j.next();
N = emp.getNom();
P = emp.getPrenom();
g = emp.getAge();
S = emp.getSalaire();
imagefound.setIcon(new ImageIcon((emp.getImage())));
aafound = new JLabel(g.toString());
ssfound = new JLabel(S.toString());
JLabel ppfound = new JLabel(P);
JLabel nnfound = new JLabel(N);
contenuFenêtre4.add(imagefound);
contenuFenêtre4.add(nn);
contenuFenêtre4.add(nnfound);
contenuFenêtre4.add(pp);
contenuFenêtre4.add(ppfound);
contenuFenêtre4.add(aa);
contenuFenêtre4.add(aafound);
contenuFenêtre4.add(ss);
contenuFenêtre4.add(ssfound);
}
contenuFenêtre4.add(lancer9);
lancer9.addActionListener(this);
contenuFenêtre4.repaint();
find.setContentPane(contenuFenêtre4);
find.setTitle("Résultats");
find.setVisible(true);
}
else JOptionPane.showMessageDialog (null, "Aucun employé de ce nom et prénom n'existe", "", JOptionPane.WARNING_MESSAGE) ;
}
if (source == lancer9){
find.setVisible(false);
}
if (source == quitter){System.exit(0);}
if (source == rechercher){Rechercher(m);}
if (source == aide){
find.setBounds(200, 200, 400, 100);
JPanel contenuFenêtre3 = new JPanel();
JLabel help = new JLabel("Cette application vous permet de gérer vos employés.");
JLabel help2 = new JLabel("Pour activer les contrôles consulter,supprimer et modifier");
JLabel help3 = new JLabel("sélectionner un employé.");
contenuFenêtre3.add(help);
contenuFenêtre3.add(help2);
contenuFenêtre3.add(help3);
find.setContentPane(contenuFenêtre3);
find.setTitle("Aide");
find.setVisible(true);}
if (source == annuler){framesupprimer.setVisible(false);}
if (source == ajouter){
String n=textnom.getText();
String p=textprenom.getText();
Integer ma=new Integer(textage.getText());
int a=ma.intValue();
Integer ms=new Integer(textsalaire.getText());
double s=ms.doubleValue();
String i=textimage.getText();
m=lire();
Employes em = new Employes(n,p,a,s,i);
m.ajouter(em);
sauvegarder(m);
frameajouter.setVisible(false);
try {
FInit();
}
catch(Exception er) {
er.printStackTrace();
}
}
if (source==retour) {frameconsulter.setVisible(false);}
if(source == SupprimerMenucliq){fenetresupprimer();}
if (source == ModifierMenucliq) {Modifier(W,m);}
if (source == ConsulterMenucliq) {fenetreconsulter();}
if (source==retour2) {try {
FInit();
}
catch(Exception er) {
er.printStackTrace();
}}
}
public void mouseClicked(MouseEvent ee){
Object s = ee.getSource();
String tmp;
Iterator i = lab.iterator();
if(ee.getClickCount()==2){
fenetreconsulter();
}
else if(ee.getClickCount()==1){
for ( int p=0;p<lab.size();p++)
{
((JLabel)lab.get(p)).setBorder(null);
}
W = Integer.parseInt(((JLabel)s).getName());
((JLabel)lab.get(W)).setBorder(bord);
((JLabel)lab.get(W)).setBackground(Color.blue);
try
{
lancer2.setEnabled(true);
lancer3.setEnabled(true);
lancer4.setEnabled(true);
}
catch(Exception et){
}
}
}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
// Sauvegarde des données dans un fichier
public void sauvegarder(Manager m){
try {
File f = new File("N:/projava/manager.ser");
FileOutputStream fos = new FileOutputStream (f);
ObjectOutputStream oos = new ObjectOutputStream ( fos );
oos.writeObject(m);
oos.flush();
oos.close();
}
catch (IOException err) {err.printStackTrace();}
}
// charger manager à partir du fichier
public Manager lire (){
try {
File f = new File("N:/projava/manager.ser");
FileInputStream fis = new FileInputStream (f);
ObjectInputStream ois = new ObjectInputStream ( fis );
m = (Manager)ois.readObject();
ois.close();
}
catch (IOException err) {err.printStackTrace();}
catch (ClassNotFoundException z)
{ System.out.println("class not found !"); }
return m;
}
public static void main(String[] args) {
/*try {
File f = new File("N:/projava/manager.ser");
FileInputStream fis = new FileInputStream (f);
ObjectInputStream ois = new ObjectInputStream ( fis );
m = (Manager)ois.readObject();
ois.close();
}
catch (IOException err) {err.printStackTrace();}
catch (ClassNotFoundException z)
{ System.out.println("class not found !"); }
*/
Interface1 Interface = new Interface1();
}
}
classe employe
/**
* @author charaf
*/
import java.io.*;
public class Employes extends Personne implements java.io.Serializable {
public double Salaire = 0;
public Employes(String nom,String prenom,int age,double salaire,String image) {
// TODO Auto-generated constructor stub
super(nom,prenom,age,image);
this.Salaire=salaire;
}
public void afficher()
{
super.afficher();
System.out.println("Salaire"+Salaire);
}
public String toString()
{
return(super.toString()+Salaire);
}
public String getNom() {return nom;}
public String getPrenom() {return prenom;}
public int getAge() {return age;}
public double getSalaire() {return Salaire;}
public String getImage() { return image;}
public static void main(String[] A) {
// TODO Auto-generated method stub
try {
File f = new File("N:/projava/emp.ser");
Employes y = new Employes("Yamna","Alami", 21 ,10000,"N:\\Eglantier.jpg");
FileOutputStream fos = new FileOutputStream (f);
ObjectOutputStream oos = new ObjectOutputStream ( fos );
oos.writeObject(y);
oos.flush();
oos.close();
FileInputStream fis = new FileInputStream ("N:/projava/emp.ser");
ObjectInputStream ois = new ObjectInputStream ( fis );
Employes z = (Employes)ois.readObject();
ois.close();
System.out.println("lobjet coucou" +z.toString());
}
catch (IOException err) {err.printStackTrace();}
catch (ClassNotFoundException z)
{ System.out.println("class not found !"); }
}
}
classe manager
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.* ;
import javax.swing.*;
public class Manager extends LinkedList {
/**
* @param args
*/
private int nbemployes;
LinkedList<Employes> l1 = new LinkedList<Employes>();
public void ajouter( Employes E ) {
l1.add (E);
nbemployes++;
}
public boolean Rechercher(Employes e)
{
return(l1.contains(e));
}
public void Supprimer(Employes e)
{
l1.remove(e);
nbemployes--;
JOptionPane.showMessageDialog (null, "message ", "Supprimé !", JOptionPane.ERROR_MESSAGE) ;
}
public void toutafficher()
{
Iterator i = l1.iterator();
while(i.hasNext())
System.out.println(i.next());
/*}
for (int i = 0; i < l1.size(); i++) {
Employes o = l1.get(i);
System.out.println(o);
}*/
}
public static void main(String[] A) {
Employes E = new Employes ( "Lachgar" , "Fatima Zahra" , 12 , 100000,"N:\\Eglantier.jpg");
Employes F = new Employes ( "chacha" , "Fatima" , 123 , 1000,"N:\\Eglantier.jpg");
Manager m = new Manager ();
m.ajouter(E);
m.ajouter(F);
try {
File f = new File("N:/projava/manager.ser");
FileOutputStream fos = new FileOutputStream (f);
ObjectOutputStream oos = new ObjectOutputStream ( fos );
oos.writeObject(m);
oos.flush();
oos.close();
}
catch (IOException err) {err.printStackTrace();}
}
//M.toutafficher();
//M.Supprimer(F);
}
classe personne
public class Personne implements java.io.Serializable {
String nom = "";
String prenom="";
int age = 0;
String image;
public Personne(String n, String p, int a,String i) {
nom = n;
prenom = p;
age = a;
image = i;
}
public void afficher() {
System.out.println("Nom:"+nom);
System.out.println("Prenom:"+prenom);
System.out.println("Age:"+age);
}
public String toString() {
return(nom+prenom+age);
}
/*static public void main (String [] A) {
Personne Per = new Personne("Janati","Nisrine",21,"N:\\Eglantier.jpg");
System.out.println("La personne est "+Per);
}*/
} |