Hello,

Je me demande comment coder proprement une application qui aurait plusieurs écrans.

Exemple :

- L'écran 1 a deux boutons dont un qui "amène" à l'écran 2.
- L'écran 2 a un bouton qui "ramène" à l'écran 3.

Je ne sais pas si je suis très clair...

Voici ce que j'ai codé, mais qui ne marche pas bien (outre le fait que ça doit pas respecter les bonnes pratiques de conception) :

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
package ricksGuitars.visualLayer;
 
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 
public class Ihm {
 
	JFrame frame;
	MainPage mainPage;
	SecondPage secondPage;
 
	public void go() {
		frame = new JFrame();
 
		mainPage = new MainPage();
		secondPage = new SecondPage();
 
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().add(BorderLayout.CENTER, mainPage);
		frame.getContentPane().add(BorderLayout.SOUTH, secondPage);
 
		secondPage.setVisible(false);
 
		frame.setSize(600, 480);
		frame.setVisible(true);
	}
 
	class MainPage extends JPanel {
		JButton buttonInventory;
		JButton buttonSearch;
		public MainPage() {
			buttonInventory = new JButton("Inventory");
			buttonInventory.addActionListener(new InventoryListener());
			buttonSearch = new JButton("Search");
			buttonSearch.addActionListener(new SearchListener());		
			this.add(buttonInventory);
			this.add(buttonSearch);
		}
	}
 
	class SecondPage extends JPanel {
		JButton goBack;
		public SecondPage() {
			goBack = new JButton("Go back");
			goBack.addActionListener(new GoBackListener());
			this.add(goBack);
		}
 
	}
 
	class InventoryListener implements ActionListener {
		public void actionPerformed(ActionEvent event) {
			System.out.println("buttonInventory have been pressed.");
			mainPage.setVisible(false);
			secondPage.setVisible(true);
		}
	}
 
	class SearchListener implements ActionListener {
		public void actionPerformed(ActionEvent event) {
			System.out.println("buttonSearch have been pressed.");
		}
	}
 
	class GoBackListener implements ActionListener {
		public void actionPerformed(ActionEvent event) {
			System.out.println("GoBack have been pressed.");
			mainPage.setVisible(true);
			secondPage.setVisible(false);
		}
	}
 
}
Merci d'avance,