Fermeture fenetre

Bonjour, a tous

juste un petit renseignement , j'aimerais savoir comment faire pour , a partir de ma Jframe ,

faire :

dispose();
Jframe majframe = new Jframe();
majframe.setVisible(true);

faire ceci , sans que ma nouvelle fenetre , n'est encore en memoire les instructions de l'ancienne fenetre .car lorsque ma nouvelle fenetre s'affiche , elle est encore avec les instructions de l'ancienne

voila merci beaucoup

2 réponses

  1. Modérateur
    "lorsque ma nouvelle fenetre s'affiche , elle est encore avec les instructions de l'ancienne"

    Ce sont des données static ? Dans ce cas c'est normal qu'elles soient partagées d'une fenêtre à une autre. Mais sinon il faudrait regarder ton code pour voir ce qui se passe...
    1. bonjour KX , en fait mon soucis est que , je n'arrive pas a modifier mon tableau,
      model , je récupère les données de mon tableau avec un clic de souris , je les mets dans jes jText correspondant , en suite je les mets dans ma base de données , mais pas moyen de modifier mon tableau en même temps que j'envoie les données dans ma bd , il me faut chaque fois fermer ma fenêtre et la rouvrir pour avoir mon modèle d actualise , c'est pour ça que je voulais une méthode pour ouvrir et fermer une frame

      je te laisse mes classes , au cas ou , merci pour ton attention...

      Client/////////////

      package entite;

      import java.awt.TextField;
      import java.awt.event.TextEvent;
      import java.sql.Date;
      import java.sql.ResultSet;
      import java.sql.SQLException;
      import java.sql.Statement;
      import java.text.ParseException;
      import java.text.SimpleDateFormat;
      import java.util.ArrayList;

      import javax.swing.JOptionPane;

      import com.mysql.jdbc.PreparedStatement;

      import controle.Connection_1;
      import controle.Date_parse;
      import dialogue.FrameClient;

      public class Client {

      private String id_client;
      private String nom;
      private String prenom;
      private int tph;
      private int fidelite;
      private Date date;
      private boolean vip;
      private static java.sql.Connection laConnexion = Connection_1
      .getLaConnectionStatique();
      private static ArrayList<Client> lesEnreg = new ArrayList<>();

      public Client(String vid_client, String vnom, String vprenom, int vtph,
      int vfidelite, Date vdate, boolean vvip) {
      super();
      this.id_client = vid_client;
      this.nom = vnom;
      this.prenom = vprenom;
      this.tph = vtph;
      this.fidelite = vfidelite;
      this.date = vdate;
      this.vip = vvip;
      }

      public Client(String vid_client) {
      this.id_client = vid_client;
      }

      public Client() {
      lireRecupClient();
      }

      public static void lireRecupClient() {
      try {
      Statement state = laConnexion.createStatement();
      ResultSet rs = state.executeQuery("SELECT * FROM client");
      while (rs.next()) {
      String vid_client = rs.getString("id_client");
      String vnom = rs.getString("nom");
      String vprenom = rs.getString("prenom");
      int vtph = rs.getInt("tph");
      int vfidelite = rs.getInt("fidelite");
      Date vdate = rs.getDate("date");
      boolean vvip = rs.getBoolean("vip");
      Client c = new Client(vid_client, vnom, vprenom, vtph,
      vfidelite, vdate, vvip);
      lesEnreg.add(c);

      }
      } catch (Exception e) {
      JOptionPane.showMessageDialog(null,
      "Problème rencontré : " + e.getMessage(), "Resultat",
      JOptionPane.ERROR_MESSAGE);
      }
      }

      public static void supprimerClient() {
      String client = FrameClient.textField_id_client.getText();
      try {
      String requeteClient = ("delete from client where id_client = '"
      + client + "' ");
      Statement prepare = Connection_1.getLaConnectionStatique()
      .prepareStatement(requeteClient);
      prepare.executeUpdate(requeteClient);

      JOptionPane.showMessageDialog(null, "Client " + client
      + " supprime de le base de donnees ");

      } catch (SQLException e1) {
      System.out.println("non non");
      e1.printStackTrace();
      }
      }

      public static void chercheClient() {
      String recherche = FrameClient.textField_id_client.getText();

      String requette = ("select * from client where id_client = '"
      + recherche + "' ");
      try {
      Statement st = Connection_1.getLaConnectionStatique()
      .createStatement();
      ResultSet JeuEnreg = st.executeQuery(requette);
      while (JeuEnreg.next()) {
      String trouve = JeuEnreg.getString(1);

      if (trouve.equals(recherche)) {

      String nom = JeuEnreg.getString(2);
      String prenom = JeuEnreg.getString(3);
      int mob = JeuEnreg.getInt(4);
      String tph = Integer.toString(mob);
      int fidel = JeuEnreg.getInt(5);
      String fidelite = Integer.toString(fidel);
      String date = JeuEnreg.getString(6);// Date date
      boolean lachance = JeuEnreg.getBoolean(7);
      String vip = Boolean.toString(lachance);
      FrameClient.textField_nom.setText(nom);
      FrameClient.textField_nom.setVisible(true);
      FrameClient.textField_prenom.setText(prenom);
      FrameClient.textField_prenom.setVisible(true);
      FrameClient.textField_tph.setText(tph);
      FrameClient.textField_tph.setVisible(true);
      FrameClient.textField_fidelite.setText(fidelite);
      FrameClient.textField_fidelite.setVisible(true);
      FrameClient.textField_date.setText(date);
      FrameClient.textField_date.setVisible(true);
      FrameClient.textField_vip.setText(vip);
      FrameClient.textField_vip.setVisible(true);
      }

      if (trouve.equals(null)) {

      JOptionPane.showMessageDialog(null,
      "verifier le champ id_client");
      FrameClient.textField_id_client.setText(null);
      }

      }
      } catch (SQLException e1) {

      e1.printStackTrace();

      }
      }

      public static boolean ajoutClient() throws ParseException {
      // Controle_champs_vide();
      boolean creation = false;

      String id_client = FrameClient.textField_id_client.getText();
      String nom = FrameClient.textField_nom.getText();
      String prenom = FrameClient.textField_prenom.getText();
      String telephone = FrameClient.textField_tph.getText();
      int tph = Integer.parseInt(telephone);
      String fidelis = FrameClient.textField_fidelite.getText();
      int fidelite = Integer.parseInt(fidelis);
      String d = FrameClient.textField_date.getText();
      Date_parse.chaineENversDateJava(d);
      String lachance = FrameClient.textField_vip.getText();
      int vip = Integer.parseInt(lachance);

      try {

      String requette = ("insert into client values('" + id_client
      + "','" + nom + "' ,'" + prenom + "', '" + tph + "' , '"
      + fidelite + "' , '" + d + "' , '" + vip + "' )");

      Connection_1.laConnectionStatique.createStatement().execute(
      requette);

      creation = true;
      JOptionPane.showMessageDialog(null, "Ajout dans la BD effectué : ");

      } catch (SQLException e) {
      JOptionPane.showMessageDialog(null,
      "Ajout dans la BD non effectué : " + e.getMessage(),
      "Problème rencontré", JOptionPane.ERROR_MESSAGE);

      JOptionPane.showMessageDialog(null, "VEUILLEZ REESSAYER : ");

      }

      return creation;}

      public static boolean Modifier_Client(String vid_client, String vnom,
      String vprenom, int vtph, int vfidelite, String vdate, boolean vvip)
      throws ParseException {
      boolean modif = false;
      String requete = " update client set " + " nom = ?, " + " prenom = ?, " +" tph = ?, " +
      " fidelite = ?, " + "date = ?," + " vip = ? "
      + " WHERE id_client = ?";
      try {
      PreparedStatement prepare = (PreparedStatement) laConnexion
      .prepareStatement(requete);
      prepare.setString(1, vnom);
      prepare.setString(2, vprenom);
      prepare.setInt(3, vtph);
      prepare.setInt(4,vfidelite );
      prepare.setString (5,vdate);
      prepare.setBoolean(6, vvip);
      prepare.setString(7, vid_client);
      prepare.executeUpdate();
      prepare.close();
      modif = true;

      } catch (SQLException e) {
      JOptionPane.showMessageDialog(null, "Ajout dans la BD non effectué : "
      + e.getMessage(), "Problème rencontré",
      JOptionPane.ERROR_MESSAGE);
      }
      return modif;

      }

      public static void Vide_champs_Client() {

      FrameClient.textField_id_client.setText(null);
      FrameClient.textField_nom.setText(null);
      FrameClient.textField_prenom.setText(null);
      FrameClient.textField_tph.setText(null);
      FrameClient.textField_fidelite.setText(null);
      FrameClient.textField_date.setText(null);
      FrameClient.textField_vip.setText(null);
      }

      public String getId_client() {
      return id_client;
      }

      public void setId_client(String id_client) {
      this.id_client = id_client;
      }

      public String getNom() {
      return nom;
      }

      public void setNom(String nom) {
      this.nom = nom;
      }

      public String getPrenom() {
      return prenom;
      }

      public void setPrenom(String prenom) {
      this.prenom = prenom;
      }

      public int getTph() {
      return tph;
      }

      public void setTph(int tph) {
      this.tph = tph;
      }

      public int getFidelite() {
      return fidelite;
      }

      public void setFidelite(int fidelite) {
      this.fidelite = fidelite;
      }

      public Date getDate() {
      return date;
      }

      public void setDate(Date date) {
      this.date = date;
      }

      public boolean isVip() {
      return vip;
      }

      public void setVip(boolean vip) {
      this.vip = vip;
      }

      public static java.sql.Connection getLaConnexion() {
      return laConnexion;
      }

      public static void setLaConnexion(java.sql.Connection laConnexion) {
      Client.laConnexion = laConnexion;
      }

      public ArrayList<Client> getLesEnreg() {
      return lesEnreg;
      }

      public static void setLesEnreg(ArrayList<Client> lesEnreg) {
      Client.lesEnreg = lesEnreg;
      }

      }

      ////////////////////////////////////////////////////////////////////////////////////////////

      Modele_Client

      package modele;

      import entite.Client;

      import java.sql.Date;
      import java.util.ArrayList;
      import javax.swing.table.AbstractTableModel;

      public class Modele_Client extends AbstractTableModel {

      private static final long serialVersionUID = 1L;
      static // Propriétés
      Client instanceClient = new Client();
      private ArrayList<Client> lesDonnees = instanceClient.getLesEnreg();
      public ArrayList<Client> getLesDonnees() {
      return lesDonnees;
      }

      private final String[] lesTitres = {"id_client", "Nom", "Prenom","tph", "Fidélité", "Date", "vip"};

      public int getRowCount() {
      return lesDonnees.size();
      }

      public int getColumnCount() {
      return lesTitres.length;
      }

      public String getColumnName(int columnIndex) {
      return lesTitres[columnIndex];
      }

      public Object getValueAt(int rowIndex, int columnIndex) {

      switch (columnIndex) {

      case 0:
      return lesDonnees.get(rowIndex).getId_client();
      case 1:
      return lesDonnees.get(rowIndex).getNom();
      case 2:
      return lesDonnees.get(rowIndex).getPrenom();
      case 3:
      return lesDonnees.get(rowIndex).getTph();
      case 4:
      return lesDonnees.get(rowIndex).getFidelite();
      case 5:
      return lesDonnees.get(rowIndex).getDate();
      case 6:
      return lesDonnees.get(rowIndex).isVip();

      default:
      return null;
      }
      }

      public Class<?> getColumnClass(int columnIndex) {
      switch (columnIndex) {
      case 5:
      return Date.class;
      case 4:
      return Integer.class;
      default:
      return Object.class;
      }
      }
      public void Supprimer_modele_client(int rowIndex) {
      lesDonnees.remove(rowIndex);
      fireTableRowsDeleted(rowIndex, rowIndex);
      }

      public void Modifier_modele_client(int firstRow, int lastRow , Client leClient) {
      lesDonnees.set(firstRow, leClient);
      fireTableRowsUpdated(firstRow, lastRow);
      }

      public int NumLigne(String vid_client){
      String id_client ="";
      int numero = 0 ;
      lesDonnees.equals(vid_client);
      for(int i = 0 ; i< lesDonnees.size() ; i++){

      id_client = lesDonnees.get(i).getId_client();
      if (id_client.equals(vid_client)); {
      numero = i ; }
      }

      return numero ;
      }
      }

      //////////////////////////////////////////////////////////////////////////////////////////

      FrameClient

      package dialogue;

      import java.awt.EventQueue;

      public class FrameClient extends JFrame {

      /**
      *
      */
      private static final long serialVersionUID = 1L;
      private JPanel contentPane;
      private JTable table;
      private JScrollPane scrollPane;
      private Modele_Client modele_client = new Modele_Client();
      private JButton btnAjouter;
      private JLabel lblIdclient;
      private JLabel lblPrenom;
      private JLabel lblTph;
      private JLabel lblFidelite;
      private JLabel lblDate;
      private JLabel lblVip;
      public static JTextField textField_id_client;
      public static JTextField textField_nom;
      public static JTextField textField_tph;
      public static JTextField textField_fidelite;
      public static JTextField textField_date;
      public static JTextField textField_vip;
      private JLabel lblNom;
      public static JTextField textField_prenom;
      private JButton btnsupprimer;
      private JButton btnrecherche;
      private JButton btnRaz;
      private JLabel lbl_date;
      private JButton btnModifier;

      Date actuelle = new Date();
      DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
      String date = dateFormat.format(actuelle);
      private JLabel lblCliquezSurUne;
      private JButton btnValid_modif;

      public static void main(String[] args) {
      EventQueue.invokeLater(new Runnable() {
      public void run() {
      try {
      FrameClient frame = new FrameClient();
      frame.setVisible(true);
      } catch (Exception e) {
      e.printStackTrace();
      }
      }
      });
      }

      public FrameClient() {
      setBackground(new Color(0, 0, 139));
      setForeground(new Color(0, 0, 139));
      setTitle("CLIENT");
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setBounds(100, 100, 902, 689);
      contentPane = new JPanel();
      contentPane.setForeground(Color.WHITE);
      contentPane.setBackground(new Color(25, 25, 112));
      contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
      setContentPane(contentPane);
      contentPane.setLayout(null);
      contentPane.add(getScrollPane());
      contentPane.add(getBtnAjouter());
      contentPane.add(getLblIdclient());
      contentPane.add(getLblPrenom());
      contentPane.add(getLblTph());
      contentPane.add(getLblFidelite());
      contentPane.add(getLblDate());
      contentPane.add(getLblVip());
      contentPane.add(getTextField_id_client());
      contentPane.add(getTextField_nom());
      contentPane.add(getTextField_tph());
      contentPane.add(getTextField_fidelite());
      contentPane.add(getTextField_date());
      contentPane.add(getTextField_vip());
      contentPane.add(getLblNom());
      contentPane.add(getTextField_prenom());
      contentPane.add(getBtnsupprimer());
      contentPane.add(getBtnrecherche());
      contentPane.add(getBtnRaz());
      contentPane.add(getLbl_date());
      contentPane.add(getBtnModifier());
      contentPane.add(getLblCliquezSurUne());
      contentPane.add(getBtnValid_modif());
      table.getColumnModel().getColumn(0).setCellRenderer(new Renderer());
      // table.getColumnModel().getColumn(6).setCellRenderer(new
      // RenderFidelite());
      }

      private JTable getTable() {
      if (table == null) {
      table = new JTable(modele_client);
      }

      return table;
      }

      private JScrollPane getScrollPane() {
      if (scrollPane == null) {
      scrollPane = new JScrollPane(table);
      scrollPane.setBounds(12, 13, 860, 112);
      scrollPane.setViewportView(getTable());
      }
      return scrollPane;
      }

      private JButton getBtnAjouter() {
      if (btnAjouter == null) {
      btnAjouter = new JButton("AJOUTER");
      btnAjouter.setBackground(new Color(248, 248, 255));
      btnAjouter.setForeground(new Color(0, 0, 0));
      btnAjouter.setFont(new Font("Tahoma", Font.BOLD, 16));
      btnAjouter.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {

      Object source = e.getSource();

      if (source == btnAjouter)

      {

      try{

      Client.ajoutClient();
      modele_client.getLesDonnees().add(
      new Client(textField_id_client.getText(),
      textField_nom.getText(),
      textField_prenom.getText(), Integer
      .parseInt(textField_tph
      .getText()),
      Integer.parseInt(textField_fidelite
      .getText()), java.sql.Date
      .valueOf(textField_date
      .getText()),
      (Integer.parseInt(textField_vip
      .getText()) == 1)));
      modele_client.fireTableDataChanged();
      Client.Vide_champs_Client();
      textField_date.setEditable(true);

      } catch (ParseException e1) {

      JOptionPane.showMessageDialog(null,
      "VEUILLEZ REESSAYER : ");
      }

      }

      }
      });
      btnAjouter.setBounds(539, 163, 171, 45);
      }
      return btnAjouter;
      }

      private JLabel getLblIdclient() {
      if (lblIdclient == null) {
      lblIdclient = new JLabel(" ID_CLIENT");
      lblIdclient
      .setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 16));
      lblIdclient.setForeground(new Color(250, 250, 210));
      lblIdclient.setBounds(51, 163, 132, 16);
      }
      return lblIdclient;
      }

      private JLabel getLblPrenom() {
      if (lblPrenom == null) {
      lblPrenom = new JLabel("PRENOM");
      lblPrenom.setForeground(new Color(250, 250, 210));
      lblPrenom.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 16));
      lblPrenom.setBounds(75, 238, 84, 16);
      }
      return lblPrenom;
      }

      private JLabel getLblTph() {
      if (lblTph == null) {
      lblTph = new JLabel("TPH");
      lblTph.setForeground(new Color(253, 245, 230));
      lblTph.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 16));
      lblTph.setBounds(75, 267, 56, 16);
      }
      return lblTph;
      }

      private JLabel getLblFidelite() {
      if (lblFidelite == null) {
      lblFidelite = new JLabel("FIDELITE");
      lblFidelite.setForeground(new Color(253, 245, 230));
      lblFidelite
      .setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 16));
      lblFidelite.setBounds(75, 302, 84, 16);
      }
      return lblFidelite;
      }

      private JLabel getLblDate() {
      if (lblDate == null) {
      lblDate = new JLabel("DATE");
      lblDate.setForeground(new Color(253, 245, 230));
      lblDate.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 16));
      lblDate.setBounds(75, 338, 56, 16);
      }
      return lblDate;
      }

      private JLabel getLblVip() {
      if (lblVip == null) {
      lblVip = new JLabel("VIP");
      lblVip.setForeground(new Color(253, 245, 230));
      lblVip.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 16));
      lblVip.setBounds(75, 373, 56, 16);
      }
      return lblVip;
      }

      private JTextField getTextField_id_client() {
      if (textField_id_client == null) {
      textField_id_client = new JTextField();
      textField_id_client.setForeground(new Color(0, 100, 0));
      textField_id_client.setFont(new Font("Tahoma", Font.BOLD, 15));
      textField_id_client.setBounds(195, 163, 171, 22);
      textField_id_client.setColumns(10);
      }
      return textField_id_client;
      }

      private JTextField getTextField_nom() {
      if (textField_nom == null) {
      textField_nom = new JTextField();
      textField_nom.setForeground(new Color(0, 100, 0));
      textField_nom.setFont(new Font("Tahoma", Font.BOLD, 15));
      textField_nom.setBounds(195, 195, 171, 22);
      textField_nom.setColumns(10);
      }
      return textField_nom;
      }

      private JTextField getTextField_tph() {
      if (textField_tph == null) {
      textField_tph = new JTextField();
      textField_tph.setForeground(new Color(0, 100, 0));
      textField_tph.setBounds(195, 265, 171, 22);
      textField_tph.setColumns(10);
      }
      return textField_tph;
      }

      private JTextField getTextField_fidelite() {
      if (textField_fidelite == null) {
      textField_fidelite = new JTextField();
      textField_fidelite.setForeground(new Color(0, 100, 0));
      textField_fidelite.setFont(new Font("Tahoma", Font.BOLD, 15));
      textField_fidelite.setBounds(195, 299, 171, 22);
      textField_fidelite.setColumns(10);
      }
      return textField_fidelite;
      }

      private JTextField getTextField_date() {
      if (textField_date == null) {
      textField_date = new JTextField();
      textField_date.setForeground(new Color(0, 100, 0));
      textField_date.setFont(new Font("Tahoma", Font.BOLD, 15));
      textField_date.setBounds(195, 335, 171, 22);
      textField_date.setColumns(10);
      }
      return textField_date;
      }

      private JTextField getTextField_vip() {
      if (textField_vip == null) {
      textField_vip = new JTextField();
      textField_vip.setFont(new Font("Tahoma", Font.BOLD, 15));
      textField_vip.setForeground(new Color(0, 100, 0));
      textField_vip.setBounds(195, 370, 171, 22);
      textField_vip.setColumns(10);
      }
      return textField_vip;
      }

      private JLabel getLblNom() {
      if (lblNom == null) {
      lblNom = new JLabel("NOM");
      lblNom.setForeground(new Color(253, 245, 230));
      lblNom.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 16));
      lblNom.setBounds(75, 198, 56, 16);
      }
      return lblNom;
      }

      private JTextField getTextField_prenom() {
      if (textField_prenom == null) {
      textField_prenom = new JTextField();
      textField_prenom.setForeground(new Color(0, 100, 0));
      textField_prenom.setFont(new Font("Tahoma", Font.BOLD, 15));
      textField_prenom.setBounds(195, 230, 171, 22);
      textField_prenom.setColumns(10);
      }
      return textField_prenom;
      }

      private JButton getBtnsupprimer() {
      if (btnsupprimer == null) {
      btnsupprimer = new JButton("SUPPRIMER");
      btnsupprimer.setBackground(new Color(248, 248, 255));
      btnsupprimer.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {

      Object source = e.getSource();
      if (source == btnsupprimer)
      ;

      int NumLigne = -1;
      NumLigne = table.getSelectedRow();
      if (NumLigne != -1) {
      int choix = JOptionPane.showConfirmDialog(
      null,
      "Voulez-vous supprimer"
      + " votre client ?" + "\ncode : "
      + table.getValueAt(NumLigne, 0)
      + "\nnom : "
      + table.getValueAt(NumLigne, 1),
      "SUPPRESSION", JOptionPane.YES_NO_OPTION);
      // 0 : oui 1 : non
      if (choix == 0) {
      String vCode;
      vCode = String.valueOf(table
      .getValueAt(NumLigne, 0));
      entite.Client leClient = new entite.Client(vCode);
      modele_client.Supprimer_modele_client(NumLigne);
      textField_id_client.setText(vCode);
      Client.supprimerClient();
      }
      }

      if (NumLigne == -1) {
      JOptionPane.showMessageDialog(null,
      "Sélectionnez une ligne avant.", "Suppression",
      JOptionPane.INFORMATION_MESSAGE);
      }

      Client.Vide_champs_Client();

      }
      });
      btnsupprimer.setForeground(new Color(255, 0, 0));
      btnsupprimer.setFont(new Font("Tahoma", Font.BOLD, 16));
      btnsupprimer.setBounds(539, 224, 171, 45);
      }
      return btnsupprimer;
      }

      private JButton getBtnrecherche() {
      if (btnrecherche == null) {
      btnrecherche = new JButton("RECHERCHE");
      btnrecherche.setBackground(new Color(248, 248, 255));
      btnrecherche.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {

      Object source = e.getSource();
      if (source == btnrecherche)
      ;
      {
      Client.chercheClient();
      }
      }
      });
      btnrecherche.setForeground(new Color(0, 0, 0));
      btnrecherche.setFont(new Font("Tahoma", Font.BOLD, 16));
      btnrecherche.setBounds(539, 288, 171, 45);
      }
      return btnrecherche;
      }

      private JButton getBtnRaz() {
      if (btnRaz == null) {
      btnRaz = new JButton("RAZ");
      btnRaz.setBackground(new Color(255, 250, 240));
      btnRaz.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {

      Object source = arg0.getSource();
      if (source == btnRaz)
      ;
      {
      textField_id_client.setText(null);
      textField_nom.setText(null);
      textField_prenom.setText(null);
      textField_tph.setText(null);
      textField_fidelite.setText(null);
      textField_date.setText(null);
      textField_vip.setText(null);
      }
      }
      });
      btnRaz.setForeground(new Color(0, 0, 0));
      btnRaz.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 17));
      btnRaz.setBounds(217, 517, 97, 36);
      }
      return btnRaz;
      }

      private JLabel getLbl_date() {
      if (lbl_date == null) {

      lbl_date = new JLabel();
      lbl_date.setText(date);
      lbl_date.setForeground(Color.WHITE);
      lbl_date.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 20));
      lbl_date.setBounds(195, 424, 162, 30);
      }
      return lbl_date;
      }

      private JButton getBtnModifier() {
      if (btnModifier == null) {
      btnModifier = new JButton("SELECTIONNER LES MODIFICATIONS");
      btnModifier.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
      Object source = arg0.getSource();
      if (source == btnModifier);
      int numLigne = -1;
      numLigne = table.getSelectedRow();
      // si aucune ligne sélectionnée
      if (numLigne == -1) {
      JOptionPane
      .showMessageDialog(null,"Sélectionnez auparavant"
      + " la ligne à reporter.",
      "MODIFICATION",
      JOptionPane.INFORMATION_MESSAGE);
      }
      if (numLigne != -1) {
      numLigne = table.getSelectedRow();
      JOptionPane.showMessageDialog(null, numLigne);
      // les cellules du jTable contiennent des objets
      textField_id_client.setText((String) table.getValueAt(numLigne, 0));
      textField_nom.setText((String) table.getValueAt(numLigne, 1));
      textField_prenom.setText((String) table.getValueAt(numLigne, 2));
      int tph =( int ) table.getValueAt(numLigne, 3);
      String mob = Integer.toString(tph);
      textField_tph.setText(mob);
      int fidelis = (int) table.getValueAt(numLigne, 4);
      String fidele = Integer.toString(fidelis);
      textField_fidelite.setText(fidele);
      Date date1 = (Date) table.getValueAt(numLigne, 5);
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd") ;
      String s = format.format(date1);
      textField_date.setText(s);
      boolean lachance = (Boolean)table.getValueAt(numLigne, 6);
      String vvip = Boolean.toString(lachance);
      textField_vip.setText(vvip);
      textField_id_client.setEditable(false);
      textField_date.setEditable(false);

      {

      }

      }}
      });
      btnModifier.setForeground(new Color(0, 0, 0));
      btnModifier.setFont(new Font("Tahoma", Font.BOLD, 16));
      btnModifier.setBounds(447, 359, 341, 45);
      }
      return btnModifier;
      }
      private JLabel getLblCliquezSurUne() {
      if (lblCliquezSurUne == null) {
      lblCliquezSurUne = new JLabel("CLIQUEZ SUR UNE LIGNE DU TABLEAU\r\n");
      lblCliquezSurUne.setForeground(new Color(255, 255, 255));
      lblCliquezSurUne.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 14));
      lblCliquezSurUne.setBounds(480, 406, 305, 22);
      }
      return lblCliquezSurUne;
      }
      private JButton getBtnValid_modif() {
      if (btnValid_modif == null) {
      btnValid_modif = new JButton("VALIDEZ VOS MODIFICATIONS");
      btnValid_modif.setFont(new Font("Tahoma", Font.BOLD, 16));
      btnValid_modif.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {

      }
      });
      btnValid_modif.setBounds(447, 441, 349, 45);
      }
      return btnValid_modif;
      }
      }

      Discussions similaires

      wannonce en panne

      7 réponses