analyseWriter/src/fenetres/modifStudent.java

150 lines
4.8 KiB
Java

package fenetres;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import MEPTL.commandes;
import MEPTL.meptl;
import cXML.node;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class modifStudent extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField textFieldNom;
private JTextField textFieldPrenom;
private JTextField textFieldCourriel;
private JTextField textFieldId;
private JButton btnSupprimer;
private JButton btnModifier;
node nodeStudent = null;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
modifStudent frame = new modifStudent(null,null);
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public modifStudent(node nodeStudent, node nodImportCSV) {
String name = nodImportCSV.getAttributs().get("name");
String email = nodImportCSV.getAttributs().get("email");
String firstname = nodImportCSV.getAttributs().get("firstname");
String id = nodImportCSV.getAttributs().get("id");
setResizable(false);
setTitle("Modifier étudiant");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNom = new JLabel("Nom");
lblNom.setFont(new Font("Tahoma", Font.BOLD, 16));
lblNom.setBounds(10, 18, 75, 17);
contentPane.add(lblNom);
textFieldNom = new JTextField();
textFieldNom.setFont(new Font("Tahoma", Font.BOLD, 16));
textFieldNom.setBounds(112, 11, 312, 31);
contentPane.add(textFieldNom);
textFieldNom.setColumns(10);
textFieldNom.setText(nodeStudent.getAttributs().get(name));
textFieldPrenom = new JTextField();
textFieldPrenom.setFont(new Font("Tahoma", Font.BOLD, 16));
textFieldPrenom.setColumns(10);
textFieldPrenom.setBounds(112, 53, 312, 31);
contentPane.add(textFieldPrenom);
textFieldPrenom.setText(nodeStudent.getAttributs().get(firstname));
JLabel lblPrenom = new JLabel("Prénom");
lblPrenom.setFont(new Font("Tahoma", Font.BOLD, 16));
lblPrenom.setBounds(10, 60, 75, 17);
contentPane.add(lblPrenom);
textFieldCourriel = new JTextField();
textFieldCourriel.setFont(new Font("Tahoma", Font.BOLD, 16));
textFieldCourriel.setColumns(10);
textFieldCourriel.setBounds(112, 95, 312, 31);
contentPane.add(textFieldCourriel);
textFieldCourriel.setText(nodeStudent.getAttributs().get(email));
textFieldId = new JTextField();
textFieldId.setFont(new Font("Tahoma", Font.BOLD, 16));
textFieldId.setColumns(10);
textFieldId.setBounds(112, 137, 312, 31);
contentPane.add(textFieldId);
textFieldId.setText(nodeStudent.getAttributs().get(id));
JLabel lblEmail = new JLabel("Courriel");
lblEmail.setFont(new Font("Tahoma", Font.BOLD, 16));
lblEmail.setBounds(10, 102, 75, 17);
contentPane.add(lblEmail);
JLabel lblIdentifiant = new JLabel("Identifiant");
lblIdentifiant.setFont(new Font("Tahoma", Font.BOLD, 16));
lblIdentifiant.setBounds(10, 144, 98, 17);
contentPane.add(lblIdentifiant);
btnModifier = new JButton("Modifier");
btnModifier.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
nodeStudent.getAttributs().put(name, textFieldNom.getText());
nodeStudent.getAttributs().put(firstname, textFieldPrenom.getText());
nodeStudent.getAttributs().put(id, textFieldId.getText());
nodeStudent.getAttributs().put(email, textFieldCourriel.getText());
evaluate.getTxtpnmessages().setContentType("text/html");
evaluate.getTxtpnmessages().setText(meptl.afficheNodeCSV().toString());
dispose();
}
});
btnModifier.setFont(new Font("Tahoma", Font.BOLD, 16));
btnModifier.setBounds(247, 219, 177, 31);
contentPane.add(btnModifier);
btnSupprimer = new JButton("Supprimer");
btnSupprimer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
commandes.nodeCSV.supprimeNodeEnfant("student", id, nodeStudent.getAttributs().get(id));
evaluate.getTxtpnmessages().setContentType("text/html");
evaluate.getTxtpnmessages().setText("<html><h1>*** L'étudiant a été supprimé de la liste ***</h1></html>");
dispose();
}
});
btnSupprimer.setFont(new Font("Tahoma", Font.BOLD, 16));
btnSupprimer.setBounds(10, 219, 182, 31);
contentPane.add(btnSupprimer);
}
}