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
| import java.awt.event.*;
import javax.swing.*;
public class Titi {
public static void main(String[] args) {
JFrame leformulaire=new JFrame("Formulaire 2");
final JLabel Titre=new JLabel("Entrez vos informations personnelles");
Titre.setBounds(90,20, 400,20);
final JLabel QNom1=new JLabel("Quel est ton nom ?");
QNom1.setBounds(20,80, 200,20);
final JTextField RNom1=new JTextField();
RNom1.setBounds(165,80, 200,20);
String rep1 = RNom1.getText();
final JLabel QNom2=new JLabel("Quelle est votre âge ?");
QNom2.setBounds(20,130, 200,20);
final JTextField RNom2=new JTextField();
RNom2.setBounds(165,130, 200,20);
String rep2 = RNom2.getText();
final JLabel QNom3=new JLabel("Quelle est votre taille ?");
QNom3.setBounds(20,180, 200,20);
final JTextField RNom3=new JTextField();
RNom3.setBounds(165,180, 200,20);
String rep3 = RNom3.getText();
JButton lebouton=new JButton("Enregistrez");
lebouton.setBounds(130,230,135,30);
final JLabel Commentaire=new JLabel("");
Commentaire.setBounds(10,280, 400,20);
lebouton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Commentaire.setText("Bonjour " + rep1 + ", Vous avez " + rep2 + " ans et vous mesurez " + rep3 + " mètres.");
}
});
leformulaire.add(lebouton);
leformulaire.add(Titre);
leformulaire.add(QNom1);
leformulaire.add(QNom2);
leformulaire.add(QNom3);
leformulaire.add(RNom1);
leformulaire.add(RNom2);
leformulaire.add(RNom3);
leformulaire.add(Commentaire);
leformulaire.setSize(400,400);
leformulaire.setLayout(null);
leformulaire.setVisible(true);
leformulaire.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
leformulaire.setLocationRelativeTo(null);
}
} |
Partager