-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttributsTableau.java
More file actions
158 lines (119 loc) · 3.23 KB
/
AttributsTableau.java
File metadata and controls
158 lines (119 loc) · 3.23 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
public class AttributsTableau extends JDialog implements ActionListener
{
private int nbLignes;
private int nbColonnes;
private JLabel[] titreLabel;
private JTextField[] titre;
private JButton valider, annuler;
public AttributsTableau(JFrame parent, String title, boolean modal, int nbLignes, int nbColonnes)
{
super(parent, title, modal);
this.setLayout(new BorderLayout());
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
this.setSize(400, 200);
this.nbLignes = nbLignes;
this.nbColonnes = nbColonnes;
titreLabel = new JLabel[nbColonnes];
titre = new JTextField[nbColonnes];
this.initComponent();
}
public void initComponent()
{
JPanel centre = new JPanel(new GridLayout(nbColonnes, 2));
char defaut = 'A';
for(int i = 0; i < nbColonnes; i++)
{
titreLabel[i] = new JLabel("Champ " + (i+1) + " :");
titreLabel[i].setFont(new Font("default",Font.BOLD,12));
titreLabel[i].setHorizontalAlignment(JLabel.CENTER);
titre[i] = new JTextField(String.valueOf(defaut));
titre[i].setPreferredSize(new Dimension(150, 25));
titre[i].addCaretListener(new CaretListener(){
@Override
public void caretUpdate(CaretEvent arg0)
{
boolean verification = true;
for(int i = 0; i < titre.length; i++)
{
if(titre[i].getText().isEmpty())
{
verification = false;
}
}
if(verification)
valider.setEnabled(false);
else
valider.setEnabled(true);
}
});
titre[i].addKeyListener(new KeyListener(){
@Override
public void keyPressed(KeyEvent arg0)
{
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent arg0)
{
if(!valider.isEnabled() && arg0.getKeyCode() == KeyEvent.VK_ENTER)
{
nouveauTableau();
}
}
@Override
public void keyTyped(KeyEvent arg0)
{
// TODO Auto-generated method stub
}
});
centre.add(titreLabel[i]);
centre.add(titre[i]);
defaut++;
}
JPanel control = new JPanel();
valider = new JButton("Valider");
valider.addActionListener(this);
annuler = new JButton("Annuler");
annuler.addActionListener(this);
control.add(annuler);
control.add(valider);
JScrollPane sclScroll = new JScrollPane(centre);
add(sclScroll, BorderLayout.CENTER);
add(control, BorderLayout.SOUTH);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e)
{
if(e.getSource().equals(annuler))
{
this.dispose();
}
else if(e.getSource().equals(valider))
{
nouveauTableau();
}
}
public void nouveauTableau()
{
}
}