//f est mon jinternalframe if(f!=null){ desktop.remove(f);//desktop est mon desktopane f.setclosed(true); }
addWindwowListener(new Fermeur())
public class Fermeur implements WindowListener { public void windowOpened(WindowEvent e){ } public void windowClosing(WindowEvent e){ } public void windowClosed(WindowEvent e){ } public void windowIconified(WindowEvent e){ } public void windowDeinconified(WindowEvent e){ } public void windowActivated(WindowEvent e){ } public void windowDeactivated(WindowEvent e){ } }
public class index extends JFrame implements ActionListener{ /** * */ private static final long serialVersionUID = 1L; //components JMenuBar index=new JMenuBar(); JMenu cpt=new JMenu("Compte"); JMenu clnt=new JMenu("Client"); JMenuItem agnc=new JMenuItem("Agence"); JMenuItem creer=new JMenuItem("Créer");JMenuItem creer2=new JMenuItem("Créer"); JMenuItem consulter=new JMenuItem("Consulter");JMenuItem consulter2=new JMenuItem("Consulter"); JDesktopPane desktop = new JDesktopPane(); JInternalFrame cptcreer; JInternalFrame cptconsulter; JInternalFrame clntcreer; JInternalFrame clntconsulter; JInternalFrame agence; public index(String s){ setTitle(s); setSize(700,400); setLocationRelativeTo(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setJMenuBar(index); index.add(cpt);index.add(clnt);index.add(agnc); clnt.add(creer);clnt.add(consulter); cpt.add(creer2);cpt.add(consulter2); creer.addActionListener(this); creer2.addActionListener(this); consulter.addActionListener(this); consulter2.addActionListener(this); agnc.addActionListener(this); getContentPane().add(desktop); show(); } public void actionPerformed(ActionEvent e){ if(e.getSource()==creer){ clntcreer = new creer_client(); clntcreer.setSize(this.getSize()); clntcreer.setVisible(true); desktop.add(clntcreer); try{clntcreer.setSelected(true);}catch(Exception a){a.printStackTrace();} } if(e.getSource()==consulter){ fermer(); clntconsulter = new consulter_client(); clntconsulter.setSize(this.getSize()); clntconsulter.setVisible(true); desktop.add(clntconsulter); try{clntconsulter.setSelected(true);}catch(Exception a){a.printStackTrace();} } if(e.getSource()==creer2){ fermer(); cptcreer = new Compte_Creer(); cptcreer.setSize(this.getSize()); cptcreer.setVisible(true); desktop.add(cptcreer); try{cptcreer.setSelected(true);}catch(Exception a){a.printStackTrace();} } if(e.getSource()==consulter2){ fermer(); cptconsulter = new Compte_Consulter(); cptconsulter.setSize(this.getSize()); cptconsulter.setVisible(true); desktop.add(cptconsulter); try{cptconsulter.setSelected(true);}catch(Exception a){a.printStackTrace();} } if(e.getSource()==agnc){ fermer(); agence = new agences(); agnc.setSize(this.getSize()); agnc.setVisible(true); desktop.add(agnc); try{agnc.setSelected(true);}catch(Exception a){a.printStackTrace();} } } public void fermer(){ if(agence.isVisible()){ agence.setVisible(false); } if(clntcreer.isVisible()){ clntcreer.setVisible(false)); } if(clntconsulter.isVisible()){ clntconsulter.setVisible(false); } if(cptcreer.isVisible()){ cptcreer.dispose(); } if(cptconsulter.isVisible()){ cptconsulter.setVisible(false); } } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question