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
| import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class FenetreSaisie extends JFrame{
private static final Component Label1 = null;
private static final Component Label2 = null;
private static final Component Label3 = null;
private JTextField textField;
private JTextField textField2;
private JTextField textField3;
private JTextField textField4;
private Container pane1;
private JLabel label;
public FenetreSaisie(){
super();
build();//On initialise notre fenêtre
}
private void build(){
setTitle("Fenêtre qui demande du texte"); //On donne un titre à l'application
setSize(800,600); //On donne une taille à notre fenêtre
setLocationRelativeTo(null); //On centre la fenêtre sur l'écran
setResizable(true); //On permet le redimensionnement
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //On dit à l'application de se fermer lors du clic sur la croix
setContentPane(buildContentPane());
}
private JPanel buildContentPane(){
// Instance de JPanel
JPanel panel = new JPanel();
JPanel panel2 = new JPanel();
JPanel panel3 = new JPanel();
// Méthode setLayout
panel.setLayout(new FlowLayout()); //On définit le layout à utiliser sur le content pane
// Demander du texte à l'utilisateur
textField = new JTextField("1er champs"); // Création champs pour user1
textField.setColumns(8);
panel.add(textField);
textField2 = new JTextField("2ème champs"); // Création champs pour user2
textField2.setColumns(8);
panel.add(textField2);
textField3 = new JTextField("3ème champs"); // Création champs pour user3
textField3.setColumns(8);
panel.add(textField3);
textField4 = new JTextField("4ème champs"); // Création champs pour user4
textField4.setColumns(8);
panel.add(textField4);
// Afficher du texte dans la fenetre
JLabel label = new JLabel("Zone de début");
panel.add(label);
JLabel label1 = new JLabel("Zone de fin");
panel.add(label1);
JLabel label2 = new JLabel("Valeur de début");
panel.add(label2);
JLabel label3 = new JLabel("Valeur de fin");
panel.add(label3);
// Afficher boutons
JButton bouton1 = new JButton("PARCOURIR"); // Je créer bouton
panel.add(bouton1);
JButton bouton2 = new JButton("OK"); // Je créer bouton2
panel.add(bouton2);
JButton bouton3 = new JButton("ANNULER"); // Je créer bouton3
panel.add(bouton3);
return panel;
}
public JTextField getTextField(){
return textField;
}
public JLabel getLabel(){
return label;
}
public static void main(String[] args) {
//On crée une nouvelle instance de notre FenetreTexte
FenetreSaisie fenetre = new FenetreSaisie();
fenetre.setVisible(true);//On la rend visible
}
} |
Partager