Skip to content
Commits on Source (6)
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
*/ */
package com.mycompany.formulairegraphique; package com.mycompany.formulairegraphique;
import formulaires.ContactForm;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
/** /**
* *
...@@ -14,33 +16,37 @@ import javax.swing.JOptionPane; ...@@ -14,33 +16,37 @@ import javax.swing.JOptionPane;
public class MainClass { public class MainClass {
public static void main(String[] args) { public static void main(String[] args) {
String nom = JOptionPane.showInputDialog(null, "Entrez le nom de la personne :");
// Créer une fenêtre de dialogue pour choisir le sexe de la personne // String nom = JOptionPane.showInputDialog(null, "Entrez le nom de la personne :");
String[] optionsSexe = {"Masculin", "Féminin", "Non-binaire"}; //
int choixSexe = JOptionPane.showOptionDialog(null, "Choisissez le sexe de la personne :", "Sexe", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, optionsSexe, optionsSexe[0]); // // Créer une fenêtre de dialogue pour choisir le sexe de la personne
String sexe; // String[] optionsSexe = {"Masculin", "Féminin", "Non-binaire"};
switch (choixSexe) { // int choixSexe = JOptionPane.showOptionDialog(null, "Choisissez le sexe de la personne :", "Sexe", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, optionsSexe, optionsSexe[0]);
case 0: // String sexe;
sexe = "masculin"; // switch (choixSexe) {
break; // case 0:
case 1: // sexe = "masculin";
sexe = "féminin"; // break;
break; // case 1:
case 2: // sexe = "féminin";
sexe = "non-binaire"; // break;
break; // case 2:
default: // sexe = "non-binaire";
sexe = "inconnu"; // break;
} // default:
// sexe = "inconnu";
// }
//
// // Créer une fenêtre de dialogue pour saisir l'âge de la personne
// String ageString = JOptionPane.showInputDialog(null, "Entrez l'âge de la personne :");
// int age = Integer.parseInt(ageString);
//
// // Afficher les informations dans une nouvelle fenêtre de dialogue
// String message = "Nom : " + nom + "\nSexe : " + sexe + "\nÂge : " + age;
// JOptionPane.showMessageDialog(null, message);
// Créer une fenêtre de dialogue pour saisir l'âge de la personne
String ageString = JOptionPane.showInputDialog(null, "Entrez l'âge de la personne :");
int age = Integer.parseInt(ageString);
// Afficher les informations dans une nouvelle fenêtre de dialogue new ContactForm();
String message = "Nom : " + nom + "\nSexe : " + sexe + "\nÂge : " + age;
JOptionPane.showMessageDialog(null, message);
} }
} }
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package formulaires;
/**
*
* @author ramzi
*/
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
*
* @author ramzi
*/
class AddressPanel extends JPanel {
private JLabel numberLabel, streetLabel, cityLabel, zipCodeLabel;
private JTextField numberField, streetField, cityField, zipCodeField;
public AddressPanel() {
setLayout(new GridLayout(4, 2, 10, 10));
setBorder(BorderFactory.createTitledBorder("Adresse"));
// Labels
numberLabel = new JLabel("Numéro :");
streetLabel = new JLabel("Rue :");
cityLabel = new JLabel("Ville :");
zipCodeLabel = new JLabel("Code postal :");
// Text fields
numberField = new JTextField(10);
streetField = new JTextField(20);
cityField = new JTextField(20);
zipCodeField = new JTextField(10);
// Add components to panel
add(numberLabel);
add(numberField);
add(streetLabel);
add(streetField);
add(cityLabel);
add(cityField);
add(zipCodeLabel);
add(zipCodeField);
}
public String getAddress() {
String number = numberField.getText();
String street = streetField.getText();
String city = cityField.getText();
String zipCode = zipCodeField.getText();
return number + " " + street + "\n" + zipCode + " " + city;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package formulaires;
import java.awt.GridLayout;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
/**
*
* @author ramzi
*/
class BirthdatePanel extends JPanel {
private JLabel birthdateLabel, dayLabel, monthLabel, yearLabel;
private JComboBox<Integer> dayComboBox, monthComboBox, yearComboBox;
public BirthdatePanel() {
setLayout(new GridLayout(1, 4, 10, 10));
// Labels
birthdateLabel = new JLabel("Date de naissance :");
dayLabel = new JLabel("Jour :");
monthLabel = new JLabel("Mois :");
yearLabel = new JLabel("Année :");
// Combo boxes
dayComboBox = new JComboBox<Integer>();
for (int i = 1; i <= 31; i++) {
dayComboBox.addItem(i);
}
monthComboBox = new JComboBox<Integer>();
for (int i = 1; i <= 12; i++) {
monthComboBox.addItem(i);
}
yearComboBox = new JComboBox<Integer>();
for (int i = 1900; i <= 2023; i++) {
yearComboBox.addItem(i);
}
// Add components to panel
add(birthdateLabel);
add(dayLabel);
add(dayComboBox);
add(monthLabel);
add(monthComboBox);
add(yearLabel);
add(yearComboBox);
}
public String getBirthdate() {
int day = (int) dayComboBox.getSelectedItem();
int month = (int) monthComboBox.getSelectedItem();
int year = (int) yearComboBox.getSelectedItem();
return day + "/" + month + "/" + year;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package formulaires;
/**
*
* @author ramzi
*/
import javax.swing.*;
import java.awt.*;
public class CivilityPanel extends JPanel {
private JLabel civilityLabel;
private JRadioButton meRadioButton, mmeRadioButton, mlleRadioButton;
private JComboBox<String> civilityComboBox;
public CivilityPanel() {
setLayout(new FlowLayout(FlowLayout.LEFT));
setBorder(BorderFactory.createTitledBorder("Civilité"));
civilityLabel = new JLabel("Civilité :");
meRadioButton = new JRadioButton("M.");
mmeRadioButton = new JRadioButton("Mme.");
mlleRadioButton = new JRadioButton("Mlle.");
ButtonGroup civGroup = new ButtonGroup();
civGroup.add(meRadioButton);
civGroup.add(mmeRadioButton);
civGroup.add(mlleRadioButton);
add(meRadioButton);
add(mmeRadioButton);
add(mlleRadioButton);
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package formulaires;
/**
*
* @author ramzi
*/
import java.awt.BorderLayout;
import javax.swing.*;
public class ContactForm extends JFrame {
private CivilityPanel civilityPanel;
private NamePanel namePanel;
private BirthdatePanel birthdatePanel;
private AddressPanel addressPanel;
private LanguagePanel languagePanel;
private PassionPanel passionPanel;
private JButton submitButton;
public ContactForm() {
// Configuration de la fenêtre
setTitle("Formulaire de contact");
setSize(500, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
// Création des différents panneaux
civilityPanel = new CivilityPanel();
namePanel = new NamePanel();
birthdatePanel = new BirthdatePanel();
addressPanel = new AddressPanel();
languagePanel = new LanguagePanel();
passionPanel = new PassionPanel();
// Ajout des panneaux à la fenêtre
getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
getContentPane().add(civilityPanel);
getContentPane().add(namePanel);
getContentPane().add(birthdatePanel);
getContentPane().add(addressPanel);
getContentPane().add(languagePanel);
add(passionPanel, BorderLayout.CENTER);
// Bouton de validation
submitButton = new JButton("Valider");
getContentPane().add(submitButton);
// Affichage de la fenêtre
pack();
setVisible(true);
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package formulaires;
import javax.swing.*;
import java.awt.*;
/**
*
* @author ramzi
*/
public class LanguagePanel extends JPanel {
private JLabel langLabel;
private JCheckBox cCheckBox, cppCheckBox, csharpCheckBox, javaSECheckBox, javaEECheckBox, pythonCheckBox, shellCheckBox, delphiCheckBox, pascalCheckBox, turboPascalCheckBox;
public LanguagePanel() {
setBorder(BorderFactory.createTitledBorder("Langages"));
setLayout(new GridLayout(5, 2, 5, 5));
langLabel = new JLabel("Langages :");
cCheckBox = new JCheckBox("C");
cppCheckBox = new JCheckBox("C++");
csharpCheckBox = new JCheckBox("C#");
javaSECheckBox = new JCheckBox("Java SE");
javaEECheckBox = new JCheckBox("Java EE");
pythonCheckBox = new JCheckBox("Python");
shellCheckBox = new JCheckBox("Shell");
delphiCheckBox = new JCheckBox("Delphi");
pascalCheckBox = new JCheckBox("Pascal");
turboPascalCheckBox = new JCheckBox("Turbo Pascal");
add(langLabel);
add(new JPanel());
add(cCheckBox);
add(cppCheckBox);
add(csharpCheckBox);
add(javaSECheckBox);
add(javaEECheckBox);
add(pythonCheckBox);
add(shellCheckBox);
add(delphiCheckBox);
add(pascalCheckBox);
add(turboPascalCheckBox);
}
public String[] getSelectedLanguages() {
String[] selectedLanguages = new String[10];
int index = 0;
if (cCheckBox.isSelected()) {
selectedLanguages[index] = cCheckBox.getText();
index++;
}
if (cppCheckBox.isSelected()) {
selectedLanguages[index] = cppCheckBox.getText();
index++;
}
if (csharpCheckBox.isSelected()) {
selectedLanguages[index] = csharpCheckBox.getText();
index++;
}
if (javaSECheckBox.isSelected()) {
selectedLanguages[index] = javaSECheckBox.getText();
index++;
}
if (javaEECheckBox.isSelected()) {
selectedLanguages[index] = javaEECheckBox.getText();
index++;
}
if (pythonCheckBox.isSelected()) {
selectedLanguages[index] = pythonCheckBox.getText();
index++;
}
if (shellCheckBox.isSelected()) {
selectedLanguages[index] = shellCheckBox.getText();
index++;
}
if (delphiCheckBox.isSelected()) {
selectedLanguages[index] = delphiCheckBox.getText();
index++;
}
if (pascalCheckBox.isSelected()) {
selectedLanguages[index] = pascalCheckBox.getText();
index++;
}
if (turboPascalCheckBox.isSelected()) {
selectedLanguages[index] = turboPascalCheckBox.getText();
index++;
}
// Truncate the array to the actual number of selected languages
String[] truncatedArray = new String[index];
System.arraycopy(selectedLanguages, 0, truncatedArray, 0, index);
return truncatedArray;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package formulaires;
/**
*
* @author ramzi
*/
import javax.swing.*;
import java.awt.*;
public class NamePanel extends JPanel {
private JLabel nameLabel, firstnameLabel;
private JTextField nameField, firstnameField;
public NamePanel() {
setLayout(new FlowLayout(FlowLayout.LEFT));
nameLabel = new JLabel("Nom :");
firstnameLabel = new JLabel("Prénom :");
nameField = new JTextField(20);
firstnameField = new JTextField(20);
add(nameLabel);
add(nameField);
add(firstnameLabel);
add(firstnameField);
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package formulaires;
/**
*
* @author ramzi
*/
import javax.swing.*;
import java.awt.*;
public class PassionPanel extends JScrollPane {
private JTextArea passionTextArea;
public PassionPanel() {
initPassionPanel();
}
private void initPassionPanel() {
setPreferredSize(new Dimension(400, 200));
setBorder(BorderFactory.createTitledBorder("Passions"));
passionTextArea = new JTextArea();
passionTextArea.setLineWrap(true);
passionTextArea.setWrapStyleWord(true);
setViewportView(passionTextArea);
}
public String getPassions() {
return passionTextArea.getText();
}
}