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
| //déclaration de variable
private JLabel Lpers1 = getL(8, 0, 47, 35,"P.1");
private JLabel Lpers2 = getL(42, 0, 47, 35,"P.2");
private JLabel Lnom = getL(75, 0, 105, 35,"NomFamille");
private JLabel Lnomjf = getL(165, 0, 121, 35,"NomJeuneF");
private JLabel Lprenom1 = getL(255, 0, 92, 35,"Prenom.1");
private JLabel Lprenom2 = getL(345, 0, 92, 35,"Prenom.2");
private JLabel Lprenom3 = getL(435, 0, 92, 35,"Prenom.3");
private JLabel Lprenom4 = getL(525, 0, 92, 35,"Prenom.4");
private JLabel Ljour = getL(630, 3, 43, 29,"Jour");
private JLabel Lmois = getL(675, 3, 43, 29,"Mois");
private JLabel Lannee = getL(720, 3, 43, 29,"Annee");
private JLabel Lpays = getL(780, 3, 43, 29,"Pays");
private JPanel jPanel = null;
private JScrollPane js;
private JButton jButton1 = null;
private int a = 18;
//fonction pour fabriquer les labels
private JLabel getL(int x, int y, int l,int h,String T) {
JLabel L = null;
if(L==null) {
L = new JLabel();
L.setBounds(new Rectangle(x, y, l, h));
L.setText(T);
L.setForeground(Color.blue);
}
return L;
}
//JPanel
public JPanel getJPanel() {
if (jPanel == null) {
jPanel = new JPanel();
jPanel.setLayout(null);
jPanel.add(Lpers1);
jPanel.add(Lpers2);
jPanel.add(Lnom);
jPanel.add(Lnomjf);
jPanel.add(Lprenom1);
jPanel.add(Lprenom2);
jPanel.add(Lprenom3);
jPanel.add(Lprenom4);
jPanel.add(Ljour);
jPanel.add(Lmois);
jPanel.add(Lannee);
jPanel.add(Lpays);
jPanel.add(getJButton1());
}
return jPanel;
}
//fonction pour fabriquer les JTextField
private JTextField getTfnom(String N,int y,String Z) {
Nom += 1;
JTextField tf = null;
if(tf==null) {
tf = new JTextField();
tf.setBounds(new Rectangle(75, y, 90, 20));
tf.setName(N+Nom);
tf.setText(Z);
tf.setForeground(Color.darkGray);
tf.setEditable(false);
}
return tf;
}
//JButton
private JButton getJButton1() {
a = 18;
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setBounds(new Rectangle(902, 10, 80, 19));
jButton1.setText("Aff/Ref");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
a += 22;
jPanel.add(getTfnom("Nom_",a,strNom)); //appel de la fonction textfield et ajout sur le panel
jPanel.setPreferredSize(new Dimension (980,a+22)); //taille du JPanel incrementation en Y pour lui dire que le panel Bouge
jPanel.repaint(); //sert a repaindre le panel a chaque fabriquation de textfield
jPanel.revalidate(); //revalidations du JPanel
}
}
);
}
return jButton1;
}
//JScrollPane
public JScrollPane JS()
{
if (js == null)
{
js = new JScrollPane();
js.setViewportView(getJPanel());
}
return js;
} |