Bonsoir tout le monde
j'ai besoin de votre aide sur une petite manipulation:
j'ai deux fenêtre une la voici:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
import java.awt.BorderLayout;
import java.awt.EventQueue;
 
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JMenu;
import java.awt.CardLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
 
 
public class Gestion extends JFrame {
 
	private JPanel contentPane;
 
	/**
         * Launch the application.
         */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Gestion frame = new Gestion();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
 
	/**
         * Create the frame.
         */
	public Gestion() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
 
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
 
		JMenu mnGestion = new JMenu("Gestion Empruntes");
		menuBar.add(mnGestion);
 
		JMenuItem mntmEmprunter = new JMenuItem("Emprunter");
		mntmEmprunter.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Gestion2 g=new Gestion2();
				g.setVisible(true);
			}
		});
		mnGestion.add(mntmEmprunter);
 
		JMenuItem mntmNewMenuItem = new JMenuItem("Retourner");
		mnGestion.add(mntmNewMenuItem);
 
		JMenu mnGestionDeLivre = new JMenu("Gestion livre");
		menuBar.add(mnGestionDeLivre);
 
		JMenuItem mntmAjouter = new JMenuItem("Ajouter");
		mnGestionDeLivre.add(mntmAjouter);
 
		JMenuItem mntmSupprimer = new JMenuItem("Supprimer");
		mnGestionDeLivre.add(mntmSupprimer);
 
		JMenuItem mntmModifier = new JMenuItem("Modifier");
		mnGestionDeLivre.add(mntmModifier);
 
		JMenu mnEtudiant = new JMenu("Etudiant ");
		menuBar.add(mnEtudiant);
 
		JMenuItem mntmAjouter_1 = new JMenuItem("Ajouter");
		mnEtudiant.add(mntmAjouter_1);
 
		JMenuItem mntmSupprimer_1 = new JMenuItem("Supprimer");
		mnEtudiant.add(mntmSupprimer_1);
 
		JMenuItem mntmModifier_1 = new JMenuItem("Modifier");
		mnEtudiant.add(mntmModifier_1);
		getContentPane().setLayout(new CardLayout(0, 0));
	}
 
}
et une autre :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.FlowLayout;
 
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JMenu;
import java.awt.CardLayout;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
 
 
public class Gestion2 extends JFrame {
 
	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
 
	/**
         * Launch the application.
         */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Gestion2 frame = new Gestion2();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
 
	/**
         * Create the frame.
         */
	public Gestion2() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
 
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
 
		JMenu mnGestion = new JMenu("Gestion Empruntes");
		menuBar.add(mnGestion);
 
		JMenuItem mntmEmprunter = new JMenuItem("Emprunter");
		mnGestion.add(mntmEmprunter);
 
		JMenuItem mntmNewMenuItem = new JMenuItem("Retourner");
		mnGestion.add(mntmNewMenuItem);
 
		JMenu mnGestionDeLivre = new JMenu("Gestion livre");
		menuBar.add(mnGestionDeLivre);
 
		JMenuItem mntmAjouter = new JMenuItem("Ajouter");
		mnGestionDeLivre.add(mntmAjouter);
 
		JMenuItem mntmSupprimer = new JMenuItem("Supprimer");
		mnGestionDeLivre.add(mntmSupprimer);
 
		JMenuItem mntmModifier = new JMenuItem("Modifier");
		mnGestionDeLivre.add(mntmModifier);
 
		JMenu mnEtudiant = new JMenu("Etudiant ");
		menuBar.add(mnEtudiant);
 
		JMenuItem mntmAjouter_1 = new JMenuItem("Ajouter");
		mnEtudiant.add(mntmAjouter_1);
 
		JMenuItem mntmSupprimer_1 = new JMenuItem("Supprimer");
		mnEtudiant.add(mntmSupprimer_1);
 
		JMenuItem mntmModifier_1 = new JMenuItem("Modifier");
		mnEtudiant.add(mntmModifier_1);
 
		getContentPane().setLayout(new CardLayout(0, 0));
 
		JPanel panel = new JPanel();
		getContentPane().add(panel, "name_3686234843963");
		panel.setLayout(null);
 
		JLabel lblNewLabel = new JLabel("CNE");
		lblNewLabel.setBounds(30, 13, 20, 14);
		panel.add(lblNewLabel);
 
		textField = new JTextField();
		textField.setBounds(80, 10, 103, 20);
		panel.add(textField);
		textField.setColumns(10);
 
		JLabel lblNewLabel_1 = new JLabel("ISBN");
		lblNewLabel_1.setBounds(34, 85, 46, 14);
		panel.add(lblNewLabel_1);
 
		textField_1 = new JTextField();
		textField_1.setBounds(80, 82, 103, 20);
		panel.add(textField_1);
		textField_1.setColumns(10);
 
		JButton btnNewButton = new JButton("Valider");
		btnNewButton.setBounds(30, 153, 89, 23);
		panel.add(btnNewButton);
 
		JButton btnRetour = new JButton("Retour");
		btnRetour.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Gestion g=new Gestion();
				g.setVisible(true);
			}
		});
		btnRetour.setBounds(179, 153, 89, 23);
		panel.add(btnRetour);
	}
}
j'aimerai faire la gestion de l’évènement suivant: quand je cliquer sur le bouton retour dans la deuxième fenêtre cette dernière sera remplacé par la première pur faire ceci j'ai fait :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
JButton btnRetour = new JButton("Retour");
		btnRetour.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Gestion g=new Gestion();
				g.setVisible(true);
			}
le problème c'est que j'ai les deux fenêtre qui s'affichent à l’écran au lieu d'une seule,je vous serai très reconnaissant si vous m'indiquer une solution
cordialement