-
Notifications
You must be signed in to change notification settings - Fork 0
/
PanelDrawer.java
101 lines (70 loc) · 2.45 KB
/
PanelDrawer.java
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
import javax.swing.*;
import java.awt.GridLayout;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.*;
public class PanelDrawer extends JPanel implements ActionListener
{
private Controleur ctrl;
private JButton btnAddPass;
private JButton[] ensMDP;
private JPanel pnlAddPass;
public PanelDrawer( Controleur ctrl)
{
this.ctrl = ctrl;
this.setLayout ( new GridLayout( 10, 1, 10, 10 ) );
/*----------------------------*/
/* Création des composants */
/*----------------------------*/
this.pnlAddPass = new JPanel( new BorderLayout() );
this.btnAddPass = new JButton ( "+");
this.btnAddPass.setBackground( Color.yellow);
this.ensMDP = new JButton[this.ctrl.getNbPassword()];// méthode get
for (int i = 0; i < this.ensMDP.length; i++)
{
this.ensMDP[i] = new JButton( this.ctrl.getPasswordIndice(i).getNom() );
}
/*--------------------------------*/
/* positionnement des composants */
/*--------------------------------*/
this.pnlAddPass.add(this.btnAddPass, BorderLayout.WEST);
this.pnlAddPass.add( new JLabel( "Ajouter mot de passe") );
this.add ( this.pnlAddPass);
for (JButton b : ensMDP)
{
this.add( b );
b.setBackground( new Color(205, 74, 74) );
}
// Colors
this.pnlAddPass.setBackground( new Color(181, 79, 79) );
this.setBackground( Color.DARK_GRAY );
/*----------------------------------------*/
/* Activation des composants */
/*----------------------------------------*/
// Bouton ajouter mot de passe
this.btnAddPass.addActionListener( this );
// Bouton accès mot de passe
for (JButton b : this.ensMDP) b.addActionListener( this );
}
public void actionPerformed(ActionEvent e)
{
if ( e.getSource() == this.btnAddPass ) this.ctrl.newMdp();
if ( e.getSource() != this.btnAddPass )
{
int index=0;
for (JButton b : this.ensMDP)
{
if (e.getSource() == b)
{
b.setBackground(Color.yellow);
this.ctrl.actualisation(index);
}
else
{
b.setBackground( new Color(205, 74, 74) );
}
index++;
}
}
}
}