import [Link].
*;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
import [Link];
import [Link].*;
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link].*;
public class ExempleSwing {
public static void main(String[] args) {
// Création de la fenêtre (JFrame)
JFrame frame = new JFrame("Exemple de champ de texte");
[Link](new FlowLayout());
[Link](300, 200);
[Link](JFrame.EXIT_ON_CLOSE);
// Création du champ de texte avec une largeur de 20 colonnes
JTextField textField = new JTextField(20);
// Optionnel : Définir un texte par défaut
[Link]("Saisissez votre texte ici");
// Ajout du champ à la fenêtre
[Link](textField);
[Link](true);
}
}
public class MaFenetreBoutons {
public static void main(String[] args) {
// 1. Créer le cadre (fenêtre principale)
JFrame frame = new JFrame("Exemple Boutons Java");
[Link](300, 200);
[Link](JFrame.EXIT_ON_CLOSE);
[Link](null); // Centre la fenêtre
// 2. Créer un panneau pour organiser les composants
JPanel panel = new JPanel();
[Link](new FlowLayout()); // Positionnement automatique
// 3. Créer les boutons
JButton bouton1 = new JButton("Bouton 1");
JButton bouton2 = new JButton("Bouton 2");
// 4. Ajouter les boutons au panneau
[Link](bouton1);
[Link](bouton2);
// 5. Ajouter le panneau au cadre et rendre visible
[Link](panel);
[Link](true);
}
}
public class ExempleLabel {
public static void main(String[] args) {
// Création de la fenêtre
JFrame frame = new JFrame("Exemple de Label");
[Link](JFrame.EXIT_ON_CLOSE);
[Link](300, 150);
[Link](new FlowLayout());
// 1. Création d'un label simple
JLabel label1 = new JLabel("Texte du label");
// 2. Création d'un label personnalisé (police, taille)
JLabel label2 = new JLabel("Label personnalisé");
[Link](new Font("Arial", [Link], 16));
// Ajout des labels à la fenêtre
[Link](label1);
[Link](label2);
// Affichage
[Link](true);
}
}
public class ExempleChampTexte {
public static void main(String[] args) {
JFrame frame = new JFrame("Exemple");
JPanel panel = new JPanel();
// Création d'un champ de texte de 20 colonnes
JTextField textField = new JTextField(20);
// Optionnel : ajouter du texte par défaut
[Link]("Texte par défaut");
[Link](new JLabel("Nom :"));
[Link](textField);
[Link](panel);
[Link](300, 100);
[Link](JFrame.EXIT_ON_CLOSE);
[Link](true);
}
}
public class MaFenetre {
public static void main(String[] args) {
// 1. Créer la fenêtre principale (JFrame)
JFrame frame = new JFrame("Ma Fenêtre Java");
[Link](JFrame.EXIT_ON_CLOSE);
[Link](400, 200);
[Link](null); // Centrer la fenêtre
// 2. Créer un conteneur (JPanel) pour organiser les composants
JPanel panel = new JPanel();
[Link](new FlowLayout()); // Alignement simple des
composants
// 3. Créer des boutons (JButton)
JButton bouton1 = new JButton("Bouton 1");
JButton bouton2 = new JButton("Bouton 2");
// 4. Ajouter une action au clic (ActionListener)
[Link](new ActionListener() {
public void actionPerformed(ActionEvent e) {
[Link](frame, "Vous avez cliqué
sur le Bouton 1 !");
}
});
// 5. Ajouter les boutons au panneau, puis le panneau à la
fenêtre
[Link](bouton1);
[Link](bouton2);
[Link](panel);
// 6. Rendre la fenêtre visible
[Link](true);
}
public class ExempleCheckbox {
public static void main(String[] args) {
// Création de la fenêtre (JFrame)
JFrame frame = new JFrame("Exemple de cases à
cocher");
[Link](JFrame.EXIT_ON_CLOSE);
[Link](300, 150);
[Link](new FlowLayout());
// 1. Création des cases à cocher (JCheckBox)
JCheckBox check1 = new JCheckBox("Option 1");
JCheckBox check2 = new JCheckBox("Option 2",
true); // Pré-cochée
// 2. Ajouter un écouteur d'action (optionnel, pour détecter les
clics)
[Link](new ActionListener() {
public void actionPerformed(ActionEvent e) {
[Link]("Option 1 est : " +
([Link]() ? "cochée" : "décochée"));
}
});
// 3. Ajouter les cases à la fenêtre
[Link](check1);
[Link](check2);
// Afficher la fenêtre
[Link](true);
}
}
public class ExempleSwing {
public static void main(String[] args) {
JFrame frame = new JFrame("Exemple Case à
Cocher");
[Link](new FlowLayout());
// Création des cases à cocher
JCheckBox check1 = new JCheckBox("Option 1");
JCheckBox check2 = new JCheckBox("Option 2",
true); // Sélectionnée par défaut
// Ajout au cadre
[Link](check1);
[Link](check2);
[Link](300, 200);
[Link](true);
[Link](JFrame.EXIT_ON_CLOSE);
}
}
public class ExempleRadioBoutons {
public static void main(String[] args) {
JFrame frame = new JFrame("Exemple Boutons Radio");
[Link](JFrame.EXIT_ON_CLOSE);
[Link](300, 150);
[Link](new FlowLayout());
// 1. Créer les boutons radio
JRadioButton radio1 = new JRadioButton("Option 1");
JRadioButton radio2 = new JRadioButton("Option 2");
JRadioButton radio3 = new JRadioButton("Option 3");
// 2. Regrouper les boutons (un seul sélectionnable)
ButtonGroup group = new ButtonGroup();
[Link](radio1);
[Link](radio2);
[Link](radio3);
// 3. Ajouter les boutons au cadre
[Link](radio1);
[Link](radio2);
[Link](radio3);
// 4. Ajouter un écouteur d'action (optionnel, pour gérer le clic)
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
[Link]("Sélectionné : " +
((JRadioButton)[Link]()).getText());
}
};
[Link](actionListener);
[Link](actionListener);
[Link](actionListener);
[Link](true);
}
}
import [Link].*;
import [Link].*;
public class ExempleSwing {
public static void main(String[] args) {
JFrame frame = new JFrame("Exemple Bouton
Radio");
[Link](new FlowLayout());
// Création des boutons radio
JRadioButton radio1 = new JRadioButton("Option 1");
JRadioButton radio2 = new JRadioButton("Option 2");
// Groupe pour l'exclusivité (indispensable)
ButtonGroup group = new ButtonGroup();
[Link](radio1);
[Link](radio2);
// Ajout à l'interface
[Link](radio1);
[Link](radio2);
[Link](300, 150);
[Link](true);
}
}
public class ExempleListeDeroulante {
public static void main(String[] args) {
// Création de la fenêtre
JFrame frame = new JFrame("Exemple JComboBox");
[Link](JFrame.EXIT_ON_CLOSE);
[Link](300, 200);
[Link](new FlowLayout());
// Éléments à ajouter dans la liste
String[] options = {"Option 1", "Option 2",
"Option 3", "Option 4"};
// Création de la liste déroulante (JComboBox)
JComboBox<String> comboBox = new
JComboBox<>(options);
// Ajout d'un écouteur pour détecter la sélection
[Link](e -> {
[Link]("Sélection : " +
[Link]());
});
// Ajout de la liste au panneau
[Link](comboBox);
[Link](true);
}
}
public class ExempleSelection extends JFrame {
public ExempleSelection() {
setTitle("Exemple Liste de Sélection");
setSize(300, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
// 1. Création des données (éléments de la liste)
String[] options = {"Option 1", "Option 2",
"Option 3", "Option 4"};
// 2. Création de la JComboBox (liste déroulante)
JComboBox<String> comboBox = new
JComboBox<>(options);
// 3. Ajout d'un écouteur pour détecter la
sélection
[Link](new ActionListener() {
public void actionPerformed(ActionEvent e) {
String selected = (String)
[Link]();
[Link]("Élément sélectionné :
" + selected);
}
});
// Ajouter la liste au cadre (JFrame)
add(new JLabel("Choisir un élément :"));
add(comboBox);
setVisible(true);
}
public static void main(String[] args) {
new ExempleSelection();
}
}
public class SwingExample {
public static void main(String[] args) {
JFrame frame = new JFrame("Exemple JList");
String[] data = {"Élément 1", "Élément 2",
"Élément 3"};
// Création de la liste
JList<String> list = new JList<>(data);
[Link](ListSelectionModel.SINGLE_SELECTION
); // Sélection unique
// Écouteur de sélection
[Link](e -> {
if (![Link]()) {
[Link]("Sélectionné : " +
[Link]());
}
});
[Link](new JScrollPane(list));
[Link](300, 200);
[Link](true);
}
}