bonjour j'essaye de mettre en place l'architecture mvc pour mon code
je suis au niveau de la vue et le controleur
je fais intervenir 3 objet distinct ( fenetre + panelAuthentification (Boutton) + gestionAuthentification (actionPerformed). en effet au lancement de la fenetre, je set un panelauthentification qui comporte un bouton de validation, l'action sur ce bouton est déléguée a un objet Gestion authentification qui represente mon controleur. afin de ne pas faire new () a tout va je souhaite lui passer en paramettre la fenetre de lancement pour invoquer ses méthodes, sauf que l'action du bouton se trouve au niveau du panel:
voila le code que j'ai ecris si quelqu1 peut me débloquer svp.
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 public class GestionAuthentification implements ActionListener { private JLabel lb_Auth_Reussie = null; private Fenetre frame; public GestionAuthentification(Fenetre frame) { super(); this.frame=frame; } public void actionPerformed(ActionEvent e) { try { String value1 = frame.getAuthentification().getTextLogin() .getText(); String value2 = frame.getAuthentification().getTextPassWd() .getText(); System.out.println("je suis dans le bouton"); if (value1.equals("roseindia") && value2.equals("roseinida")) { frame.getContentPane().removeAll(); frame.getContentPane().repaint(); frame.lanceMenuBar(); lb_Auth_Reussie = new JLabel("Welcome Mr:" + value1); frame.getContentPane().add(lb_Auth_Reussie); } else { System.out.println("enter the valid username and password"); JOptionPane.showInputDialog(this); } } catch (Exception e2) { System.out.println("gros soucis"); } } }
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 public class PanelAuthentification extends JPanel { JTextField textLogin = new JTextField(15); JTextField textPassWd = new JPasswordField(15); Fenetre frame ; public PanelAuthentification(Fenetre frame) { super(); this.frame=frame; JLabel label1 = new JLabel(); label1.setText("Username:"); JLabel label2 = new JLabel(); label2.setText("Password:"); JButton valide = new JButton("valider"); add(label1); ; add(textLogin); add(label2); add(textPassWd); add(valide); /* je souhaite invoquer l'obejt mere, la fenetre qui as lancée le panel afin d'invoquer ses méthodes ActionListener gestionBouton = new GestionAuthentification(?); valide.addActionListener(gestionBouton);*/ } public JTextField getTextLogin() { return textLogin; } public void setTextLogin(JTextField textLogin) { this.textLogin = textLogin; } public JTextField getTextPassWd() { return textPassWd; } public void setTextPassWd(JTextField textPassWd) { this.textPassWd = textPassWd; } }
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 public class Fenetre extends JFrame{ private PanelAuthentification authentification = null; private MenuBarFenetre menuBar; public Fenetre() throws HeadlessException { super(); getContentPane().setBackground(Color.LIGHT_GRAY); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().setLayout(new BorderLayout(0, 0)); authentification = new PanelAuthentification(this); lancePanelAuthentification(); } public void lancePanelAuthentification() { setContentPane(authentification); } public void lanceMenuBar() { menuBar = new MenuBarFenetre(); setJMenuBar(menuBar); menuBar.setVisible(true); } public PanelAuthentification getAuthentification() { return authentification; } public void setAuthentification(PanelAuthentification authentification) { this.authentification = authentification; }
Partager