Bonjour a tous,
J’ai un problème du affichage deux JLabel du nom et prénom voila mon programme :
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class test_1 extends JPanel implements ActionListener{
private JButton button;
private JLabel label_nom;
private JLabel label_prénom;
public test_1() {
setLayout(null);
label_nom = new JLabel("Nom :");
label_prénom = new JLabel("Prénom :");
button = new JButton("Afficher");
button.addActionListener(this);
label_nom.setBounds(20, 20, 100, 20);
label_prénom.setBounds(20, 50, 100, 20);
button.setBounds(20, 100, 100, 20);
add(label_nom);
add(label_prénom);
add(button);
}
public void actionPerformed(ActionEvent e) {
Object boutonCliqué = e.getSource();
if (boutonCliqué == button) {
JLabel aff_nom = new JLabel("Aziz");
JLabel aff_pré = new JLabel("Dérouiche");
aff_nom.setBounds(50, 20, 100, 20);
aff_pré.setBounds(50, 50, 100, 20);
add(aff_nom);
add(aff_pré);
}
}
public static void main(String[] args) {
test_1 test = new test_1();
JFrame frame = new JFrame("test_1");
frame.setContentPane(test);
frame.setVisible(true);
frame.setSize(300, 200);
}
}
Merci de me répondre.