Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1197 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  rafraichissement jscrollpane

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

rafraichissement jscrollpane

n°2217503
jeremyl332​40
Posté le 24-01-2014 à 18:39:19  profilanswer
 

Bonsoir.
 
Jeune développeur novice qui code pendant son temps libre je suis confronté à un problème que je n'arrive pas à résoudre depuis hier.
Le but de ce programme est qu'à chaque fois qu'on clique sur un bouton, cela ajoute 50 à la case distance correspondante.  
Celle partie fonctionne très bien et la BDD se met à jour correctement.
Le seul et dernier soucis que je n'arrive pas à résoudre c'est que je voudrai que quand on clique sur l'un des boutons, le jScrollPane se mette à jour avec la nouvelle distance.
 
Pour voir en détail la fenêtre, elle se trouve ici :
http://img15.hostingpics.net/pics/795594Sanstitre.png
 
Et sinon pour les classes, les voilàs
 
Connexion

Code :
  1. package pointage;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.SQLException;
  5. import javax.swing.JOptionPane;
  6. public class Connexion{
  7.   private static String url = "jdbc:mysql://localhost:3306/bdd_anl";
  8.   private static String user = "java";
  9.   private static String passwd = "anl";
  10.   private static Connection connect;
  11.   public static Connection getInstance(){
  12.     if(connect == null){
  13.       try {
  14.         connect = DriverManager.getConnection(url, user, passwd);
  15.         System.out.println("connexion etablie" );
  16.       } catch (SQLException e) {
  17.         JOptionPane.showMessageDialog(null, e.getMessage(), "ERREUR DE CONNEXION ! ", JOptionPane.ERROR_MESSAGE);
  18.       }
  19.     }
  20.     return connect;
  21.   }
  22. }


 
 
FenPointage

Code :
  1. package pointage;
  2. import javax.swing.JButton;
  3. import javax.swing.JLabel;
  4. import javax.swing.JScrollPane;
  5. import javax.swing.JTable;
  6. import javax.swing.GroupLayout;
  7. import javax.swing.LayoutStyle;
  8. public class FenPointage extends javax.swing.JFrame {
  9.    
  10.     public JButton jButton1;
  11.     public JButton jButton2;   
  12.     public JButton jButton3;
  13.     public JButton jButton4;
  14.     public JButton jButton5;
  15.     public JButton jButton6;
  16.     public JButton jButton7;
  17.     public JButton jButton8;
  18.     public JButton jButton9;
  19.     public JButton jButton10;
  20.     public JButton jButton11;
  21.     public JButton jButton12;
  22.     public JButton jButton13;
  23.     public JButton jButton14;
  24.     public JButton jButton15;
  25.     public JButton jButton16;
  26.     public JButton jButton17;
  27.     public JButton jButton18;
  28.     public JButton jButton19;
  29.     public JButton jButton20;
  30.     public JButton jButton21;
  31.     public JButton jButton22;
  32.     public JButton jButton23;
  33.     public JButton jButton24;
  34.     public JButton jButton25;
  35.     public JButton jButton26;
  36.     public JButton jButton27;
  37.     public JButton jButton28;
  38.     public JButton jButton29;
  39.     public JButton jButton30;
  40.     public JButton jButton31;
  41.     public JButton jButton32;
  42.     public JButton jButton33;
  43.     public JButton jButton34;
  44.     public JButton jButton35;
  45.     public JButton jButton36;
  46.     public JButton jButton37;
  47.     public JButton jButton38;
  48.     public JButton jButton39;
  49.     public JButton jButton40;   
  50.     private JLabel jLabel1;
  51.     private JLabel jLabel2;
  52.     private JLabel jLabel3;
  53.     private JLabel jLabel4;
  54.     private JLabel jLabel5;
  55.     private JLabel jLabel6;
  56.     private JLabel jLabel7;
  57.     private JLabel jLabel8;
  58.     private JScrollPane jScrollPane1;
  59.     private JScrollPane jScrollPane2;
  60.     private JScrollPane jScrollPane3;
  61.     private JScrollPane jScrollPane4;
  62.     private JTable jTable1;
  63.     private JTable jTable2;
  64.     private JTable jTable3;
  65.     private JTable jTable4;
  66.     public FenPointage() {
  67.         setSize(650, 600);
  68.         setTitle("Pointage des nageurs" );
  69.         setLocationRelativeTo(null);
  70.         setDefaultCloseOperation(EXIT_ON_CLOSE);
  71.        
  72.     }
  73.                        
  74.     public void initComponents() {
  75.         jScrollPane1 = new JScrollPane();
  76.         jScrollPane2 = new JScrollPane();
  77.         jScrollPane3 = new JScrollPane();
  78.         jScrollPane4 = new JScrollPane();
  79.         jTable1 = new JTable();
  80.         jTable2 = new JTable();
  81.         jTable3 = new JTable();
  82.         jTable4 = new JTable();
  83.         jLabel1 = new JLabel();
  84.         jLabel2 = new JLabel();
  85.         jLabel3 = new JLabel();
  86.         jLabel4 = new JLabel();
  87.         jLabel5 = new JLabel();
  88.         jLabel6 = new JLabel();
  89.         jLabel7 = new JLabel();
  90.         jLabel8 = new JLabel();
  91.         jButton1 = new JButton();
  92.         jButton2 = new JButton();
  93.         jButton3 = new JButton();
  94.         jButton4 = new JButton();
  95.         jButton5 = new JButton();
  96.         jButton6 = new JButton();
  97.         jButton7 = new JButton();
  98.         jButton8 = new JButton();
  99.         jButton9 = new JButton();
  100.         jButton10 = new JButton();       
  101.         jButton11 = new JButton();
  102.         jButton12 = new JButton();
  103.         jButton13 = new JButton();
  104.         jButton14 = new JButton();
  105.         jButton15 = new JButton();
  106.         jButton16 = new JButton();
  107.         jButton17 = new JButton();
  108.         jButton18 = new JButton();
  109.         jButton19 = new JButton();
  110.         jButton20 = new JButton();       
  111.         jButton21 = new JButton();
  112.         jButton22 = new JButton();
  113.         jButton23 = new JButton();
  114.         jButton24 = new JButton();
  115.         jButton25 = new JButton();
  116.         jButton26 = new JButton();
  117.         jButton27 = new JButton();
  118.         jButton28 = new JButton();
  119.         jButton29 = new JButton();
  120.         jButton30 = new JButton();       
  121.         jButton31 = new JButton();
  122.         jButton32 = new JButton();
  123.         jButton33 = new JButton();
  124.         jButton34 = new JButton();
  125.         jButton35 = new JButton();
  126.         jButton36 = new JButton();
  127.         jButton37 = new JButton();
  128.         jButton38 = new JButton();
  129.         jButton39 = new JButton();
  130.         jButton40 = new JButton();   
  131.        
  132.         ModifBoutons modif = new ModifBoutons();
  133.         jButton1.addActionListener(modif);
  134.         jButton2.addActionListener(modif);
  135.         jButton3.addActionListener(modif);
  136.         jButton4.addActionListener(modif);
  137.         jButton5.addActionListener(modif);
  138.         jButton6.addActionListener(modif);
  139.         jButton7.addActionListener(modif);
  140.         jButton8.addActionListener(modif);
  141.         jButton9.addActionListener(modif);
  142.         jButton10.addActionListener(modif);
  143.         jButton11.addActionListener(modif);
  144.         jButton12.addActionListener(modif);
  145.         jButton13.addActionListener(modif);
  146.         jButton14.addActionListener(modif);
  147.         jButton15.addActionListener(modif);
  148.         jButton16.addActionListener(modif);
  149.         jButton17.addActionListener(modif);
  150.         jButton18.addActionListener(modif);
  151.         jButton19.addActionListener(modif);
  152.         jButton20.addActionListener(modif);
  153.         jButton21.addActionListener(modif);
  154.         jButton22.addActionListener(modif);
  155.         jButton23.addActionListener(modif);
  156.         jButton24.addActionListener(modif);
  157.         jButton25.addActionListener(modif);
  158.         jButton25.addActionListener(modif);
  159.         jButton26.addActionListener(modif);
  160.         jButton27.addActionListener(modif);
  161.         jButton28.addActionListener(modif);
  162.         jButton29.addActionListener(modif);
  163.         jButton30.addActionListener(modif);
  164.         jButton31.addActionListener(modif);
  165.         jButton32.addActionListener(modif);
  166.         jButton33.addActionListener(modif);
  167.         jButton34.addActionListener(modif);
  168.         jButton35.addActionListener(modif);
  169.         jButton36.addActionListener(modif);
  170.         jButton37.addActionListener(modif);
  171.         jButton38.addActionListener(modif);
  172.         jButton39.addActionListener(modif);
  173.         jButton40.addActionListener(modif);
  174.        
  175.         jTable1.setModel(new javax.swing.table.DefaultTableModel(Pointage.getdata1(),Pointage.getcolumn1()));     
  176.         jScrollPane1.setViewportView(jTable1);
  177.         jTable2.setModel(new javax.swing.table.DefaultTableModel(Pointage.getdata2(),Pointage.getcolumn2()));     
  178.         jScrollPane2.setViewportView(jTable2);
  179.         jTable3.setModel(new javax.swing.table.DefaultTableModel(Pointage.getdata3(),Pointage.getcolumn3()));     
  180.         jScrollPane3.setViewportView(jTable3);
  181.         jTable4.setModel(new javax.swing.table.DefaultTableModel(Pointage.getdata4(),Pointage.getcolumn4()));     
  182.         jScrollPane4.setViewportView(jTable4);
  183.         jButton1.setText("1" );
  184.         jButton1.setName("jButton1" );
  185.         jButton2.setText("2" );
  186.         jButton2.setName("jButton2" );
  187.         jButton3.setText("3" );
  188.         jButton3.setName("jButton3" );
  189.         jButton4.setText("4" );
  190.         jButton4.setName("jButton4" );
  191.         jButton5.setText("5" );
  192.         jButton5.setName("jButton5" );
  193.         jButton6.setText("6" );
  194.         jButton6.setName("jButton6" );
  195.         jButton7.setText("7" );
  196.         jButton7.setName("jButton7" );
  197.         jButton8.setText("8" );
  198.         jButton8.setName("jButton8" );
  199.         jButton9.setText("9" );
  200.         jButton9.setName("jButton9" );
  201.         jButton10.setText("10" );
  202.         jButton10.setName("jButton10" );
  203.         jButton11.setText("1" );
  204.         jButton11.setName("jButton11" );
  205.         jButton12.setText("2" );
  206.         jButton12.setName("jButton12" );
  207.         jButton13.setText("3" );
  208.         jButton13.setName("jButton13" );
  209.         jButton14.setText("4" );
  210.         jButton14.setName("jButton14" );
  211.         jButton15.setText("5" );
  212.         jButton15.setName("jButton15" );
  213.         jButton16.setText("6" );
  214.         jButton16.setName("jButton16" );
  215.         jButton17.setText("7" );
  216.         jButton17.setName("jButton17" );
  217.         jButton18.setText("8" );
  218.         jButton18.setName("jButton18" );
  219.         jButton19.setText("9" );
  220.         jButton19.setName("jButton19" );
  221.         jButton20.setText("10" );
  222.         jButton20.setName("jButton20" );
  223.         jButton21.setText("1" );
  224.         jButton21.setName("jButton21" );
  225.         jButton22.setText("2" );
  226.         jButton22.setName("jButton22" );
  227.         jButton23.setText("3" );
  228.         jButton23.setName("jButton23" );
  229.         jButton24.setText("4" );
  230.         jButton24.setName("jButton24" );
  231.         jButton25.setText("5" );
  232.         jButton25.setName("jButton25" );
  233.         jButton26.setText("6" );
  234.         jButton26.setName("jButton26" );
  235.         jButton27.setText("7" );
  236.         jButton27.setName("jButton27" );
  237.         jButton28.setText("8" );
  238.         jButton28.setName("jButton28" );
  239.         jButton29.setText("9" );
  240.         jButton29.setName("jButton29" );
  241.         jButton30.setText("10" );
  242.         jButton30.setName("jButton30" );
  243.         jButton31.setText("1" );
  244.         jButton31.setName("jButton31" );
  245.         jButton32.setText("2" );
  246.         jButton32.setName("jButton32" );
  247.         jButton33.setText("3" );
  248.         jButton33.setName("jButton33" );
  249.         jButton34.setText("4" );
  250.         jButton34.setName("jButton34" );
  251.         jButton35.setText("5" );
  252.         jButton35.setName("jButton35" );
  253.         jButton36.setText("6" );
  254.         jButton36.setName("jButton36" );
  255.         jButton37.setText("7" );
  256.         jButton37.setName("jButton37" );
  257.         jButton38.setText("8" );
  258.         jButton38.setName("jButton38" );
  259.         jButton39.setText("9" );
  260.         jButton39.setName("jButton39" );
  261.         jButton40.setText("10" );
  262.         jButton40.setName("jButton40" );
  263.         jLabel1.setText("Ligne 1" );
  264.         jLabel2.setText("Ligne 2" );
  265.         jLabel3.setText("Ligne 3" );
  266.         jLabel4.setText("Ligne 4" );
  267.         jLabel5.setText("bonnet" );
  268.         jLabel6.setText("bonnet" );
  269.         jLabel7.setText("bonnet" );
  270.         jLabel8.setText("bonnet" );
  271.         GroupLayout layout = new GroupLayout(getContentPane());
  272.         getContentPane().setLayout(layout);
  273.         layout.setHorizontalGroup(
  274.             layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  275.             .addGroup(layout.createSequentialGroup()
  276.                 .addGap(30, 30, 30)
  277.                 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  278.                     .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
  279.                         .addComponent(jButton10, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  280.                         .addComponent(jButton1, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  281.                         .addComponent(jButton2, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  282.                         .addComponent(jButton3, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  283.                         .addComponent(jButton4, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  284.                         .addComponent(jButton5, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  285.                         .addComponent(jButton6, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  286.                         .addComponent(jButton7, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  287.                         .addComponent(jButton8, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  288.                         .addComponent(jButton9, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  289.                         .addComponent(jButton21, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  290.                         .addComponent(jButton22, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  291.                         .addComponent(jButton23, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  292.                         .addComponent(jButton24, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  293.                         .addComponent(jButton25, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  294.                         .addComponent(jButton26, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  295.                         .addComponent(jButton27, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  296.                         .addComponent(jButton28, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  297.                         .addComponent(jButton29, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  298.                         .addComponent(jButton30, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE))
  299.                     .addComponent(jLabel5)
  300.                     .addComponent(jLabel7))
  301.                 .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  302.                 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
  303.                     .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  304.                         .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  305.                             .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE)
  306.                             .addComponent(jLabel1))
  307.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
  308.                         .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  309.                             .addComponent(jLabel6)
  310.                             .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  311.                                 .addComponent(jButton11, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  312.                                 .addComponent(jButton12, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  313.                                 .addComponent(jButton13, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  314.                                 .addComponent(jButton14, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  315.                                 .addComponent(jButton15, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  316.                                 .addComponent(jButton16, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  317.                                 .addComponent(jButton17, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  318.                                 .addComponent(jButton18, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  319.                                 .addComponent(jButton19, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  320.                                 .addComponent(jButton20, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE))))
  321.                     .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  322.                         .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  323.                             .addComponent(jScrollPane3, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE)
  324.                             .addComponent(jLabel3))
  325.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  326.                         .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  327.                             .addComponent(jLabel8)
  328.                             .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  329.                                 .addComponent(jButton31, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  330.                                 .addComponent(jButton32, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  331.                                 .addComponent(jButton33, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  332.                                 .addComponent(jButton34, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  333.                                 .addComponent(jButton35, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  334.                                 .addComponent(jButton36, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  335.                                 .addComponent(jButton37, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  336.                                 .addComponent(jButton38, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  337.                                 .addComponent(jButton39, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  338.                                 .addComponent(jButton40, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)))))
  339.                 .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  340.                 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  341.                     .addComponent(jLabel4)
  342.                     .addComponent(jLabel2)
  343.                     .addComponent(jScrollPane2, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE)
  344.                     .addComponent(jScrollPane4, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE))
  345.                 .addGap(30, 30, 30))
  346.         );
  347.         layout.setVerticalGroup(
  348.             layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  349.             .addGroup(layout.createSequentialGroup()
  350.                 .addGap(28, 28, 28)
  351.                 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
  352.                     .addComponent(jLabel1)
  353.                     .addComponent(jLabel2)
  354.                     .addComponent(jLabel5)
  355.                     .addComponent(jLabel6))
  356.                 .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  357.                 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  358.                     .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
  359.                         .addGroup(layout.createSequentialGroup()
  360.                             .addComponent(jButton1, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  361.                             .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  362.                             .addComponent(jButton2, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  363.                             .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  364.                             .addComponent(jButton3, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  365.                             .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  366.                             .addComponent(jButton4, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  367.                             .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  368.                             .addComponent(jButton5, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  369.                             .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  370.                             .addComponent(jButton6, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  371.                             .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  372.                             .addComponent(jButton7, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  373.                             .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  374.                             .addComponent(jButton8, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  375.                             .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  376.                             .addComponent(jButton9, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  377.                             .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  378.                             .addComponent(jButton10, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE))
  379.                         .addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)
  380.                         .addComponent(jScrollPane2, GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
  381.                     .addGroup(layout.createSequentialGroup()
  382.                         .addComponent(jButton11, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  383.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  384.                         .addComponent(jButton12, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  385.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  386.                         .addComponent(jButton13, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  387.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  388.                         .addComponent(jButton14, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  389.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  390.                         .addComponent(jButton15, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  391.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  392.                         .addComponent(jButton16, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  393.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  394.                         .addComponent(jButton17, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  395.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  396.                         .addComponent(jButton18, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  397.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  398.                         .addComponent(jButton19, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  399.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  400.                         .addComponent(jButton20, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)))
  401.                 .addGap(30, 30, 30)
  402.                 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
  403.                     .addComponent(jLabel3)
  404.                     .addComponent(jLabel4)
  405.                     .addComponent(jLabel7)
  406.                     .addComponent(jLabel8))
  407.                 .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  408.                 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
  409.                     .addGroup(layout.createSequentialGroup()
  410.                         .addComponent(jButton31, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  411.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  412.                         .addComponent(jButton32, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  413.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  414.                         .addComponent(jButton33, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  415.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  416.                         .addComponent(jButton34, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  417.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  418.                         .addComponent(jButton35, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  419.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  420.                         .addComponent(jButton36, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  421.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  422.                         .addComponent(jButton37, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  423.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  424.                         .addComponent(jButton38, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  425.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  426.                         .addComponent(jButton39, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  427.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  428.                         .addComponent(jButton40, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE))
  429.                     .addGroup(layout.createSequentialGroup()
  430.                         .addComponent(jButton21, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  431.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  432.                         .addComponent(jButton22, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  433.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  434.                         .addComponent(jButton23, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  435.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  436.                         .addComponent(jButton24, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  437.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  438.                         .addComponent(jButton25, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  439.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  440.                         .addComponent(jButton26, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  441.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  442.                         .addComponent(jButton27, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  443.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  444.                         .addComponent(jButton28, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  445.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  446.                         .addComponent(jButton29, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  447.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  448.                         .addComponent(jButton30, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE))
  449.                     .addComponent(jScrollPane3, GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)
  450.                     .addComponent(jScrollPane4, GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
  451.                 .addGap(30, 30, 30))
  452.         );
  453.     } 
  454. }


 
 
Pointage

Code :
  1. package pointage;
  2. import java.sql.*;
  3. public class Pointage {
  4.    
  5.     public FenPointage fen;
  6.    
  7.     String l1 = "SELECT bonnet, prenom, distance FROM Nageur WHERE actif='1' AND ligne='1' ORDER BY bonnet ASC;";
  8.     String l2 = "SELECT bonnet, prenom, distance FROM Nageur WHERE actif='1' AND ligne='2' ORDER BY bonnet ASC;";
  9.     String l3 = "SELECT bonnet, prenom, distance FROM Nageur WHERE actif='1' AND ligne='3' ORDER BY bonnet ASC;";
  10.     String l4 = "SELECT bonnet, prenom, distance FROM Nageur WHERE actif='1' AND ligne='4' ORDER BY bonnet ASC;";
  11.    
  12.     public static Object[] column1;
  13.     public static Object[] column2;
  14.     public static Object[] column3;
  15.     public static Object[] column4;
  16.     public static Object[][] data1;
  17.     public static Object[][] data2;
  18.     public static Object[][] data3;
  19.     public static Object[][] data4;
  20.  
  21.     public static void main(String[] args) {
  22.         Pointage point = new Pointage();
  23.         point.start();
  24.     }
  25.    
  26.     public Pointage(){
  27.         fen = new FenPointage();
  28.     }
  29.    
  30.     public void start(){
  31.      initLigne1(l1);
  32.      initLigne2(l2);
  33.      initLigne3(l3);
  34.      initLigne4(l4);
  35.      fen.initComponents();
  36.      fen.repaint();
  37.      fen.setVisible( true );
  38.     }
  39.     /////
  40.     //tableau ligne 1
  41.     /////
  42.     public void initLigne1(String query){
  43.     try {
  44.       Statement state =Connexion.getInstance().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
  45.       ResultSet res = state.executeQuery(query);
  46.       ResultSetMetaData meta = res.getMetaData();
  47.       Object [] colonne = new Object[meta.getColumnCount()];
  48.       for(int i = 1 ; i <= meta.getColumnCount(); i++)
  49.         colonne[i-1] = meta.getColumnName(i);
  50.       //Petite manipulation pour obtenir le nombre de lignes
  51.       res.last();
  52.       Object[][] donnee = new Object[res.getRow()][meta.getColumnCount()];
  53.       //On revient au départ
  54.       res.beforeFirst();
  55.       int j = 1;
  56.       //On remplit le tableau d'Object[][]
  57.       while(res.next()){
  58.         for(int i = 1 ; i <= meta.getColumnCount(); i++)
  59.           donnee[j-1][i-1] = res.getObject(i);
  60.         j++;
  61.       }
  62.       res.close();
  63.       state.close();
  64.       Pointage.setcolumn1(colonne);
  65.       Pointage.setdata1(donnee);     
  66.     } catch (SQLException e) {}
  67.   }
  68.    
  69.     /////
  70.     //tableau ligne 2
  71.     /////
  72.     public void initLigne2(String query){
  73.     try {
  74.       Statement state =Connexion.getInstance().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
  75.       ResultSet res = state.executeQuery(query);
  76.       ResultSetMetaData meta = res.getMetaData();
  77.       Object [] colonne = new Object[meta.getColumnCount()];
  78.       for(int i = 1 ; i <= meta.getColumnCount(); i++)
  79.         colonne[i-1] = meta.getColumnName(i);
  80.       //Petite manipulation pour obtenir le nombre de lignes
  81.       res.last();
  82.       Object[][] donnee = new Object[res.getRow()][meta.getColumnCount()];
  83.       //On revient au départ
  84.       res.beforeFirst();
  85.       int j = 1;
  86.       //On remplit le tableau d'Object[][]
  87.       while(res.next()){
  88.         for(int i = 1 ; i <= meta.getColumnCount(); i++)
  89.           donnee[j-1][i-1] = res.getObject(i);
  90.         j++;
  91.       }
  92.       res.close();
  93.       state.close();
  94.       Pointage.setcolumn2(colonne);
  95.       Pointage.setdata2(donnee);     
  96.     } catch (SQLException e) {}
  97.   }
  98.    
  99.     /////
  100.     //tableau ligne 3
  101.     /////
  102.     public void initLigne3(String query){
  103.     try {
  104.       Statement state =Connexion.getInstance().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
  105.       ResultSet res = state.executeQuery(query);
  106.       ResultSetMetaData meta = res.getMetaData();
  107.       Object [] colonne = new Object[meta.getColumnCount()];
  108.       for(int i = 1 ; i <= meta.getColumnCount(); i++)
  109.         colonne[i-1] = meta.getColumnName(i);
  110.       //Petite manipulation pour obtenir le nombre de lignes
  111.       res.last();
  112.       Object[][] donnee = new Object[res.getRow()][meta.getColumnCount()];
  113.       //On revient au départ
  114.       res.beforeFirst();
  115.       int j = 1;
  116.       //On remplit le tableau d'Object[][]
  117.       while(res.next()){
  118.         for(int i = 1 ; i <= meta.getColumnCount(); i++)
  119.           donnee[j-1][i-1] = res.getObject(i);
  120.         j++;
  121.       }
  122.       res.close();
  123.       state.close();
  124.       Pointage.setcolumn3(colonne);
  125.       Pointage.setdata3(donnee);     
  126.     } catch (SQLException e) {}
  127.   }
  128.    
  129.     /////
  130.     //tableau ligne 4
  131.     /////
  132.     public void initLigne4(String query){
  133.     try {
  134.       Statement state =Connexion.getInstance().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
  135.       ResultSet res = state.executeQuery(query);
  136.       ResultSetMetaData meta = res.getMetaData();
  137.       Object [] colonne = new Object[meta.getColumnCount()];
  138.       for(int i = 1 ; i <= meta.getColumnCount(); i++)
  139.         colonne[i-1] = meta.getColumnName(i);
  140.       //Petite manipulation pour obtenir le nombre de lignes
  141.       res.last();
  142.       Object[][] donnee = new Object[res.getRow()][meta.getColumnCount()];
  143.       //On revient au départ
  144.       res.beforeFirst();
  145.       int j = 1;
  146.       //On remplit le tableau d'Object[][]
  147.       while(res.next()){
  148.         for(int i = 1 ; i <= meta.getColumnCount(); i++)
  149.           donnee[j-1][i-1] = res.getObject(i);
  150.         j++;
  151.       }
  152.       res.close();
  153.       state.close();
  154.       Pointage.setcolumn4(colonne);
  155.       Pointage.setdata4(donnee);     
  156.     } catch (SQLException e) {}
  157.   }
  158.    
  159.     ////////////////////////////////////////////////////////////////////////////
  160.     public static Object[][] getdata1 (){
  161.         return data1;
  162.     };
  163.     public static Object[][] getdata2 (){
  164.         return data2;
  165.     };
  166.     public static Object[][] getdata3 (){
  167.         return data3;
  168.     };
  169.     public static Object[][] getdata4 (){
  170.         return data4;
  171.     };
  172.     ////////////////////////////////////////////////////////////////////////////
  173.     public static Object[] getcolumn1 (){
  174.         return column1;
  175.     };
  176.     public static Object[] getcolumn2 (){
  177.         return column2;
  178.     };
  179.     public static Object[] getcolumn3 (){
  180.         return column3;
  181.     };
  182.     public static Object[] getcolumn4 (){
  183.         return column4;
  184.     };
  185.     ////////////////////////////////////////////////////////////////////////////
  186.     public static void setdata1 (Object dat[][]){
  187.         data1= dat;
  188.     };
  189.     public static void setdata2 (Object dat[][]){
  190.         data2= dat;
  191.     };
  192.     public static void setdata3 (Object dat[][]){
  193.         data3= dat;
  194.     };
  195.     public static void setdata4 (Object dat[][]){
  196.         data4= dat;
  197.     };
  198.     ////////////////////////////////////////////////////////////////////////////
  199.     public static void setcolumn1 (Object col[]){
  200.         column1= col;
  201.     };
  202.     public static void setcolumn2 (Object col[]){
  203.         column2= col;
  204.     };
  205.     public static void setcolumn3 (Object col[]){
  206.         column3= col;
  207.     };
  208.     public static void setcolumn4 (Object col[]){
  209.         column4= col;
  210.     };
  211.    
  212.     public void stop(){
  213.     fen.setVisible( false );
  214.   }
  215. }


 
 
ModifBoutons

Code :
  1. package pointage;
  2. import java.awt.event.ActionListener;
  3. import java.awt.event.ActionEvent;
  4. import java.sql.*;
  5. import javax.swing.JButton;
  6. public class ModifBoutons implements ActionListener {
  7.    
  8.     public void actionPerformed(ActionEvent événement) {
  9.          Pointage p = new Pointage();
  10.          String ligne="0";
  11.          String bonnet;
  12.          String nomboutonclique;
  13.          String updist;
  14.          String uptemps;
  15.          String upvitesse;       
  16.        
  17.          nomboutonclique = ((JButton) événement.getSource()).getName() ;
  18.          System.out.println("nom du bouton : "+nomboutonclique);
  19.          if (nomboutonclique=="jButton1"||nomboutonclique=="jButton2"||nomboutonclique=="jButton3"||nomboutonclique=="jButton4"||
  20.              nomboutonclique=="jButton5"||nomboutonclique=="jButton6"||nomboutonclique=="jButton7"||nomboutonclique=="jButton8"||
  21.              nomboutonclique=="jButton9"||nomboutonclique=="jButton9" ){
  22.          ligne="1";
  23.          }
  24.          if (nomboutonclique=="jButton11"||nomboutonclique=="jButton12"||nomboutonclique=="jButton13"||nomboutonclique=="jButton14"||
  25.              nomboutonclique=="jButton15"||nomboutonclique=="jButton16"||nomboutonclique=="jButton17"||nomboutonclique=="jButton18"||
  26.              nomboutonclique=="jButton19"||nomboutonclique=="jButton19" ){
  27.          ligne="2";
  28.          }
  29.          if (nomboutonclique=="jButton21"||nomboutonclique=="jButton22"||nomboutonclique=="jButton23"||nomboutonclique=="jButton24"||
  30.              nomboutonclique=="jButton25"||nomboutonclique=="jButton26"||nomboutonclique=="jButton27"||nomboutonclique=="jButton28"||
  31.              nomboutonclique=="jButton29"||nomboutonclique=="jButton29" ){
  32.          ligne="3";
  33.          }
  34.          if (nomboutonclique=="jButton31"||nomboutonclique=="jButton32"||nomboutonclique=="jButton33"||nomboutonclique=="jButton34"||
  35.              nomboutonclique=="jButton35"||nomboutonclique=="jButton36"||nomboutonclique=="jButton37"||nomboutonclique=="jButton38"||
  36.              nomboutonclique=="jButton39"||nomboutonclique=="jButton39" ){
  37.          ligne="4";
  38.          }
  39.        
  40.          JButton titreboutonclique = (JButton) événement.getSource();
  41.          bonnet = titreboutonclique.getText();
  42.          System.out.println("numéro du ligne : "+ligne);
  43.          System.out.println("numéro du bonnet : "+bonnet);
  44.        
  45.          updist = "UPDATE Nageur SET distance = distance+50 WHERE actif='1' AND ligne = '"+ligne+"' AND bonnet = '"+bonnet+"';";
  46.          uptemps= "UPDATE Nageur SET temps = CURRENT_TIME()-heure_depart WHERE actif='1' AND  ligne = '"+ligne+"' AND bonnet = '"+bonnet+"';";
  47.          upvitesse = "UPDATE Nageur SET vitesse = distance*3.6/TIME_TO_SEC(temps) WHERE actif='1' AND ligne = '"+ligne+"' AND bonnet = '"+bonnet+"';";
  48.        
  49.          try {
  50.             Statement state = Connexion.getInstance().createStatement();
  51.             int updatedist = state.executeUpdate(updist);
  52.             int updatetemps = state.executeUpdate(uptemps);
  53.             int updatevitesse = state.executeUpdate(upvitesse);
  54.             System.out.println("distance : "+updatedist+" temps : "+updatetemps+" vitesse : "+updatevitesse);
  55.             state.close();
  56.            
  57.          } catch (SQLException e) {}
  58.     }
  59.   }


 
 
Juste pour info, j'ai bien ententu essayé de faire un p.start à la fin du actionPerformed mais résultat, une seconde fenêtre à jour se lance en plus de la première donc ce n'est pas pratique. Il me faut juste la réinitialisation des jScrollPane :D
 
Merci à celui ou celle qui pourra résoudre ce soucis qui à l'air simple sur le papier.
 
Bonne soirée,
 
Jérémy

mood
Publicité
Posté le 24-01-2014 à 18:39:19  profilanswer
 

n°2217555
honrisse
Posté le 26-01-2014 à 10:12:47  profilanswer
 

jeremyl33240 a écrit :

Bonsoir.
 
Jeune développeur novice qui code pendant son temps libre je suis confronté à un problème que je n'arrive pas à résoudre depuis hier.
Le but de ce programme est qu'à chaque fois qu'on clique sur un bouton, cela ajoute 50 à la case distance correspondante.  
Celle partie fonctionne très bien et la BDD se met à jour correctement.
Le seul et dernier soucis que je n'arrive pas à résoudre c'est que je voudrai que quand on clique sur l'un des boutons, le jScrollPane se mette à jour avec la nouvelle distance.
 
Pour voir en détail la fenêtre, elle se trouve ici :
http://img15.hostingpics.net/pics/795594Sanstitre.png
 
Et sinon pour les classes, les voilàs
 
Connexion

Code :
  1. package pointage;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.SQLException;
  5. import javax.swing.JOptionPane;
  6. public class Connexion{
  7.   private static String url = "jdbc:mysql://localhost:3306/bdd_anl";
  8.   private static String user = "java";
  9.   private static String passwd = "anl";
  10.   private static Connection connect;
  11.   public static Connection getInstance(){
  12.     if(connect == null){
  13.       try {
  14.         connect = DriverManager.getConnection(url, user, passwd);
  15.         System.out.println("connexion etablie" );
  16.       } catch (SQLException e) {
  17.         JOptionPane.showMessageDialog(null, e.getMessage(), "ERREUR DE CONNEXION ! ", JOptionPane.ERROR_MESSAGE);
  18.       }
  19.     }
  20.     return connect;
  21.   }
  22. }


 
 
FenPointage

Code :
  1. package pointage;
  2. import javax.swing.JButton;
  3. import javax.swing.JLabel;
  4. import javax.swing.JScrollPane;
  5. import javax.swing.JTable;
  6. import javax.swing.GroupLayout;
  7. import javax.swing.LayoutStyle;
  8. public class FenPointage extends javax.swing.JFrame {
  9.    
  10.     public JButton jButton1;
  11.     public JButton jButton2;   
  12.     public JButton jButton3;
  13.     public JButton jButton4;
  14.     public JButton jButton5;
  15.     public JButton jButton6;
  16.     public JButton jButton7;
  17.     public JButton jButton8;
  18.     public JButton jButton9;
  19.     public JButton jButton10;
  20.     public JButton jButton11;
  21.     public JButton jButton12;
  22.     public JButton jButton13;
  23.     public JButton jButton14;
  24.     public JButton jButton15;
  25.     public JButton jButton16;
  26.     public JButton jButton17;
  27.     public JButton jButton18;
  28.     public JButton jButton19;
  29.     public JButton jButton20;
  30.     public JButton jButton21;
  31.     public JButton jButton22;
  32.     public JButton jButton23;
  33.     public JButton jButton24;
  34.     public JButton jButton25;
  35.     public JButton jButton26;
  36.     public JButton jButton27;
  37.     public JButton jButton28;
  38.     public JButton jButton29;
  39.     public JButton jButton30;
  40.     public JButton jButton31;
  41.     public JButton jButton32;
  42.     public JButton jButton33;
  43.     public JButton jButton34;
  44.     public JButton jButton35;
  45.     public JButton jButton36;
  46.     public JButton jButton37;
  47.     public JButton jButton38;
  48.     public JButton jButton39;
  49.     public JButton jButton40;   
  50.     private JLabel jLabel1;
  51.     private JLabel jLabel2;
  52.     private JLabel jLabel3;
  53.     private JLabel jLabel4;
  54.     private JLabel jLabel5;
  55.     private JLabel jLabel6;
  56.     private JLabel jLabel7;
  57.     private JLabel jLabel8;
  58.     private JScrollPane jScrollPane1;
  59.     private JScrollPane jScrollPane2;
  60.     private JScrollPane jScrollPane3;
  61.     private JScrollPane jScrollPane4;
  62.     private JTable jTable1;
  63.     private JTable jTable2;
  64.     private JTable jTable3;
  65.     private JTable jTable4;
  66.     public FenPointage() {
  67.         setSize(650, 600);
  68.         setTitle("Pointage des nageurs" );
  69.         setLocationRelativeTo(null);
  70.         setDefaultCloseOperation(EXIT_ON_CLOSE);
  71.        
  72.     }
  73.                        
  74.     public void initComponents() {
  75.         jScrollPane1 = new JScrollPane();
  76.         jScrollPane2 = new JScrollPane();
  77.         jScrollPane3 = new JScrollPane();
  78.         jScrollPane4 = new JScrollPane();
  79.         jTable1 = new JTable();
  80.         jTable2 = new JTable();
  81.         jTable3 = new JTable();
  82.         jTable4 = new JTable();
  83.         jLabel1 = new JLabel();
  84.         jLabel2 = new JLabel();
  85.         jLabel3 = new JLabel();
  86.         jLabel4 = new JLabel();
  87.         jLabel5 = new JLabel();
  88.         jLabel6 = new JLabel();
  89.         jLabel7 = new JLabel();
  90.         jLabel8 = new JLabel();
  91.         jButton1 = new JButton();
  92.         jButton2 = new JButton();
  93.         jButton3 = new JButton();
  94.         jButton4 = new JButton();
  95.         jButton5 = new JButton();
  96.         jButton6 = new JButton();
  97.         jButton7 = new JButton();
  98.         jButton8 = new JButton();
  99.         jButton9 = new JButton();
  100.         jButton10 = new JButton();       
  101.         jButton11 = new JButton();
  102.         jButton12 = new JButton();
  103.         jButton13 = new JButton();
  104.         jButton14 = new JButton();
  105.         jButton15 = new JButton();
  106.         jButton16 = new JButton();
  107.         jButton17 = new JButton();
  108.         jButton18 = new JButton();
  109.         jButton19 = new JButton();
  110.         jButton20 = new JButton();       
  111.         jButton21 = new JButton();
  112.         jButton22 = new JButton();
  113.         jButton23 = new JButton();
  114.         jButton24 = new JButton();
  115.         jButton25 = new JButton();
  116.         jButton26 = new JButton();
  117.         jButton27 = new JButton();
  118.         jButton28 = new JButton();
  119.         jButton29 = new JButton();
  120.         jButton30 = new JButton();       
  121.         jButton31 = new JButton();
  122.         jButton32 = new JButton();
  123.         jButton33 = new JButton();
  124.         jButton34 = new JButton();
  125.         jButton35 = new JButton();
  126.         jButton36 = new JButton();
  127.         jButton37 = new JButton();
  128.         jButton38 = new JButton();
  129.         jButton39 = new JButton();
  130.         jButton40 = new JButton();   
  131.        
  132.         ModifBoutons modif = new ModifBoutons();
  133.         jButton1.addActionListener(modif);
  134.         jButton2.addActionListener(modif);
  135.         jButton3.addActionListener(modif);
  136.         jButton4.addActionListener(modif);
  137.         jButton5.addActionListener(modif);
  138.         jButton6.addActionListener(modif);
  139.         jButton7.addActionListener(modif);
  140.         jButton8.addActionListener(modif);
  141.         jButton9.addActionListener(modif);
  142.         jButton10.addActionListener(modif);
  143.         jButton11.addActionListener(modif);
  144.         jButton12.addActionListener(modif);
  145.         jButton13.addActionListener(modif);
  146.         jButton14.addActionListener(modif);
  147.         jButton15.addActionListener(modif);
  148.         jButton16.addActionListener(modif);
  149.         jButton17.addActionListener(modif);
  150.         jButton18.addActionListener(modif);
  151.         jButton19.addActionListener(modif);
  152.         jButton20.addActionListener(modif);
  153.         jButton21.addActionListener(modif);
  154.         jButton22.addActionListener(modif);
  155.         jButton23.addActionListener(modif);
  156.         jButton24.addActionListener(modif);
  157.         jButton25.addActionListener(modif);
  158.         jButton25.addActionListener(modif);
  159.         jButton26.addActionListener(modif);
  160.         jButton27.addActionListener(modif);
  161.         jButton28.addActionListener(modif);
  162.         jButton29.addActionListener(modif);
  163.         jButton30.addActionListener(modif);
  164.         jButton31.addActionListener(modif);
  165.         jButton32.addActionListener(modif);
  166.         jButton33.addActionListener(modif);
  167.         jButton34.addActionListener(modif);
  168.         jButton35.addActionListener(modif);
  169.         jButton36.addActionListener(modif);
  170.         jButton37.addActionListener(modif);
  171.         jButton38.addActionListener(modif);
  172.         jButton39.addActionListener(modif);
  173.         jButton40.addActionListener(modif);
  174.        
  175.         jTable1.setModel(new javax.swing.table.DefaultTableModel(Pointage.getdata1(),Pointage.getcolumn1()));     
  176.         jScrollPane1.setViewportView(jTable1);
  177.         jTable2.setModel(new javax.swing.table.DefaultTableModel(Pointage.getdata2(),Pointage.getcolumn2()));     
  178.         jScrollPane2.setViewportView(jTable2);
  179.         jTable3.setModel(new javax.swing.table.DefaultTableModel(Pointage.getdata3(),Pointage.getcolumn3()));     
  180.         jScrollPane3.setViewportView(jTable3);
  181.         jTable4.setModel(new javax.swing.table.DefaultTableModel(Pointage.getdata4(),Pointage.getcolumn4()));     
  182.         jScrollPane4.setViewportView(jTable4);
  183.         jButton1.setText("1" );
  184.         jButton1.setName("jButton1" );
  185.         jButton2.setText("2" );
  186.         jButton2.setName("jButton2" );
  187.         jButton3.setText("3" );
  188.         jButton3.setName("jButton3" );
  189.         jButton4.setText("4" );
  190.         jButton4.setName("jButton4" );
  191.         jButton5.setText("5" );
  192.         jButton5.setName("jButton5" );
  193.         jButton6.setText("6" );
  194.         jButton6.setName("jButton6" );
  195.         jButton7.setText("7" );
  196.         jButton7.setName("jButton7" );
  197.         jButton8.setText("8" );
  198.         jButton8.setName("jButton8" );
  199.         jButton9.setText("9" );
  200.         jButton9.setName("jButton9" );
  201.         jButton10.setText("10" );
  202.         jButton10.setName("jButton10" );
  203.         jButton11.setText("1" );
  204.         jButton11.setName("jButton11" );
  205.         jButton12.setText("2" );
  206.         jButton12.setName("jButton12" );
  207.         jButton13.setText("3" );
  208.         jButton13.setName("jButton13" );
  209.         jButton14.setText("4" );
  210.         jButton14.setName("jButton14" );
  211.         jButton15.setText("5" );
  212.         jButton15.setName("jButton15" );
  213.         jButton16.setText("6" );
  214.         jButton16.setName("jButton16" );
  215.         jButton17.setText("7" );
  216.         jButton17.setName("jButton17" );
  217.         jButton18.setText("8" );
  218.         jButton18.setName("jButton18" );
  219.         jButton19.setText("9" );
  220.         jButton19.setName("jButton19" );
  221.         jButton20.setText("10" );
  222.         jButton20.setName("jButton20" );
  223.         jButton21.setText("1" );
  224.         jButton21.setName("jButton21" );
  225.         jButton22.setText("2" );
  226.         jButton22.setName("jButton22" );
  227.         jButton23.setText("3" );
  228.         jButton23.setName("jButton23" );
  229.         jButton24.setText("4" );
  230.         jButton24.setName("jButton24" );
  231.         jButton25.setText("5" );
  232.         jButton25.setName("jButton25" );
  233.         jButton26.setText("6" );
  234.         jButton26.setName("jButton26" );
  235.         jButton27.setText("7" );
  236.         jButton27.setName("jButton27" );
  237.         jButton28.setText("8" );
  238.         jButton28.setName("jButton28" );
  239.         jButton29.setText("9" );
  240.         jButton29.setName("jButton29" );
  241.         jButton30.setText("10" );
  242.         jButton30.setName("jButton30" );
  243.         jButton31.setText("1" );
  244.         jButton31.setName("jButton31" );
  245.         jButton32.setText("2" );
  246.         jButton32.setName("jButton32" );
  247.         jButton33.setText("3" );
  248.         jButton33.setName("jButton33" );
  249.         jButton34.setText("4" );
  250.         jButton34.setName("jButton34" );
  251.         jButton35.setText("5" );
  252.         jButton35.setName("jButton35" );
  253.         jButton36.setText("6" );
  254.         jButton36.setName("jButton36" );
  255.         jButton37.setText("7" );
  256.         jButton37.setName("jButton37" );
  257.         jButton38.setText("8" );
  258.         jButton38.setName("jButton38" );
  259.         jButton39.setText("9" );
  260.         jButton39.setName("jButton39" );
  261.         jButton40.setText("10" );
  262.         jButton40.setName("jButton40" );
  263.         jLabel1.setText("Ligne 1" );
  264.         jLabel2.setText("Ligne 2" );
  265.         jLabel3.setText("Ligne 3" );
  266.         jLabel4.setText("Ligne 4" );
  267.         jLabel5.setText("bonnet" );
  268.         jLabel6.setText("bonnet" );
  269.         jLabel7.setText("bonnet" );
  270.         jLabel8.setText("bonnet" );
  271.         GroupLayout layout = new GroupLayout(getContentPane());
  272.         getContentPane().setLayout(layout);
  273.         layout.setHorizontalGroup(
  274.             layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  275.             .addGroup(layout.createSequentialGroup()
  276.                 .addGap(30, 30, 30)
  277.                 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  278.                     .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
  279.                         .addComponent(jButton10, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  280.                         .addComponent(jButton1, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  281.                         .addComponent(jButton2, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  282.                         .addComponent(jButton3, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  283.                         .addComponent(jButton4, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  284.                         .addComponent(jButton5, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  285.                         .addComponent(jButton6, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  286.                         .addComponent(jButton7, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  287.                         .addComponent(jButton8, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  288.                         .addComponent(jButton9, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  289.                         .addComponent(jButton21, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  290.                         .addComponent(jButton22, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  291.                         .addComponent(jButton23, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  292.                         .addComponent(jButton24, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  293.                         .addComponent(jButton25, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  294.                         .addComponent(jButton26, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  295.                         .addComponent(jButton27, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  296.                         .addComponent(jButton28, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  297.                         .addComponent(jButton29, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  298.                         .addComponent(jButton30, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE))
  299.                     .addComponent(jLabel5)
  300.                     .addComponent(jLabel7))
  301.                 .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  302.                 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
  303.                     .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  304.                         .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  305.                             .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE)
  306.                             .addComponent(jLabel1))
  307.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
  308.                         .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  309.                             .addComponent(jLabel6)
  310.                             .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  311.                                 .addComponent(jButton11, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  312.                                 .addComponent(jButton12, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  313.                                 .addComponent(jButton13, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  314.                                 .addComponent(jButton14, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  315.                                 .addComponent(jButton15, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  316.                                 .addComponent(jButton16, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  317.                                 .addComponent(jButton17, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  318.                                 .addComponent(jButton18, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  319.                                 .addComponent(jButton19, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  320.                                 .addComponent(jButton20, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE))))
  321.                     .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  322.                         .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  323.                             .addComponent(jScrollPane3, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE)
  324.                             .addComponent(jLabel3))
  325.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  326.                         .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  327.                             .addComponent(jLabel8)
  328.                             .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  329.                                 .addComponent(jButton31, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  330.                                 .addComponent(jButton32, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  331.                                 .addComponent(jButton33, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  332.                                 .addComponent(jButton34, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  333.                                 .addComponent(jButton35, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  334.                                 .addComponent(jButton36, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  335.                                 .addComponent(jButton37, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  336.                                 .addComponent(jButton38, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  337.                                 .addComponent(jButton39, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  338.                                 .addComponent(jButton40, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)))))
  339.                 .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  340.                 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  341.                     .addComponent(jLabel4)
  342.                     .addComponent(jLabel2)
  343.                     .addComponent(jScrollPane2, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE)
  344.                     .addComponent(jScrollPane4, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE))
  345.                 .addGap(30, 30, 30))
  346.         );
  347.         layout.setVerticalGroup(
  348.             layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  349.             .addGroup(layout.createSequentialGroup()
  350.                 .addGap(28, 28, 28)
  351.                 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
  352.                     .addComponent(jLabel1)
  353.                     .addComponent(jLabel2)
  354.                     .addComponent(jLabel5)
  355.                     .addComponent(jLabel6))
  356.                 .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  357.                 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  358.                     .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
  359.                         .addGroup(layout.createSequentialGroup()
  360.                             .addComponent(jButton1, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  361.                             .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  362.                             .addComponent(jButton2, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  363.                             .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  364.                             .addComponent(jButton3, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  365.                             .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  366.                             .addComponent(jButton4, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  367.                             .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  368.                             .addComponent(jButton5, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  369.                             .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  370.                             .addComponent(jButton6, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  371.                             .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  372.                             .addComponent(jButton7, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  373.                             .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  374.                             .addComponent(jButton8, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  375.                             .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  376.                             .addComponent(jButton9, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  377.                             .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  378.                             .addComponent(jButton10, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE))
  379.                         .addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)
  380.                         .addComponent(jScrollPane2, GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
  381.                     .addGroup(layout.createSequentialGroup()
  382.                         .addComponent(jButton11, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  383.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  384.                         .addComponent(jButton12, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  385.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  386.                         .addComponent(jButton13, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  387.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  388.                         .addComponent(jButton14, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  389.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  390.                         .addComponent(jButton15, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  391.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  392.                         .addComponent(jButton16, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  393.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  394.                         .addComponent(jButton17, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  395.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  396.                         .addComponent(jButton18, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  397.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  398.                         .addComponent(jButton19, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  399.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  400.                         .addComponent(jButton20, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)))
  401.                 .addGap(30, 30, 30)
  402.                 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
  403.                     .addComponent(jLabel3)
  404.                     .addComponent(jLabel4)
  405.                     .addComponent(jLabel7)
  406.                     .addComponent(jLabel8))
  407.                 .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  408.                 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
  409.                     .addGroup(layout.createSequentialGroup()
  410.                         .addComponent(jButton31, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  411.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  412.                         .addComponent(jButton32, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  413.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  414.                         .addComponent(jButton33, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  415.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  416.                         .addComponent(jButton34, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  417.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  418.                         .addComponent(jButton35, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  419.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  420.                         .addComponent(jButton36, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  421.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  422.                         .addComponent(jButton37, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  423.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  424.                         .addComponent(jButton38, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  425.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  426.                         .addComponent(jButton39, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  427.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  428.                         .addComponent(jButton40, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE))
  429.                     .addGroup(layout.createSequentialGroup()
  430.                         .addComponent(jButton21, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  431.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  432.                         .addComponent(jButton22, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  433.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  434.                         .addComponent(jButton23, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  435.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  436.                         .addComponent(jButton24, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  437.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  438.                         .addComponent(jButton25, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  439.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  440.                         .addComponent(jButton26, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  441.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  442.                         .addComponent(jButton27, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  443.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  444.                         .addComponent(jButton28, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  445.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  446.                         .addComponent(jButton29, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
  447.                         .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
  448.                         .addComponent(jButton30, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE))
  449.                     .addComponent(jScrollPane3, GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)
  450.                     .addComponent(jScrollPane4, GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
  451.                 .addGap(30, 30, 30))
  452.         );
  453.     } 
  454. }


 
 
Pointage

Code :
  1. package pointage;
  2. import java.sql.*;
  3. public class Pointage {
  4.    
  5.     public FenPointage fen;
  6.    
  7.     String l1 = "SELECT bonnet, prenom, distance FROM Nageur WHERE actif='1' AND ligne='1' ORDER BY bonnet ASC;";
  8.     String l2 = "SELECT bonnet, prenom, distance FROM Nageur WHERE actif='1' AND ligne='2' ORDER BY bonnet ASC;";
  9.     String l3 = "SELECT bonnet, prenom, distance FROM Nageur WHERE actif='1' AND ligne='3' ORDER BY bonnet ASC;";
  10.     String l4 = "SELECT bonnet, prenom, distance FROM Nageur WHERE actif='1' AND ligne='4' ORDER BY bonnet ASC;";
  11.    
  12.     public static Object[] column1;
  13.     public static Object[] column2;
  14.     public static Object[] column3;
  15.     public static Object[] column4;
  16.     public static Object[][] data1;
  17.     public static Object[][] data2;
  18.     public static Object[][] data3;
  19.     public static Object[][] data4;
  20.  
  21.     public static void main(String[] args) {
  22.         Pointage point = new Pointage();
  23.         point.start();
  24.     }
  25.    
  26.     public Pointage(){
  27.         fen = new FenPointage();
  28.     }
  29.    
  30.     public void start(){
  31.      initLigne1(l1);
  32.      initLigne2(l2);
  33.      initLigne3(l3);
  34.      initLigne4(l4);
  35.      fen.initComponents();
  36.      fen.repaint();
  37.      fen.setVisible( true );
  38.     }
  39.     /////
  40.     //tableau ligne 1
  41.     /////
  42.     public void initLigne1(String query){
  43.     try {
  44.       Statement state =Connexion.getInstance().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
  45.       ResultSet res = state.executeQuery(query);
  46.       ResultSetMetaData meta = res.getMetaData();
  47.       Object [] colonne = new Object[meta.getColumnCount()];
  48.       for(int i = 1 ; i <= meta.getColumnCount(); i++)
  49.         colonne[i-1] = meta.getColumnName(i);
  50.       //Petite manipulation pour obtenir le nombre de lignes
  51.       res.last();
  52.       Object[][] donnee = new Object[res.getRow()][meta.getColumnCount()];
  53.       //On revient au départ
  54.       res.beforeFirst();
  55.       int j = 1;
  56.       //On remplit le tableau d'Object[][]
  57.       while(res.next()){
  58.         for(int i = 1 ; i <= meta.getColumnCount(); i++)
  59.           donnee[j-1][i-1] = res.getObject(i);
  60.         j++;
  61.       }
  62.       res.close();
  63.       state.close();
  64.       Pointage.setcolumn1(colonne);
  65.       Pointage.setdata1(donnee);     
  66.     } catch (SQLException e) {}
  67.   }
  68.    
  69.     /////
  70.     //tableau ligne 2
  71.     /////
  72.     public void initLigne2(String query){
  73.     try {
  74.       Statement state =Connexion.getInstance().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
  75.       ResultSet res = state.executeQuery(query);
  76.       ResultSetMetaData meta = res.getMetaData();
  77.       Object [] colonne = new Object[meta.getColumnCount()];
  78.       for(int i = 1 ; i <= meta.getColumnCount(); i++)
  79.         colonne[i-1] = meta.getColumnName(i);
  80.       //Petite manipulation pour obtenir le nombre de lignes
  81.       res.last();
  82.       Object[][] donnee = new Object[res.getRow()][meta.getColumnCount()];
  83.       //On revient au départ
  84.       res.beforeFirst();
  85.       int j = 1;
  86.       //On remplit le tableau d'Object[][]
  87.       while(res.next()){
  88.         for(int i = 1 ; i <= meta.getColumnCount(); i++)
  89.           donnee[j-1][i-1] = res.getObject(i);
  90.         j++;
  91.       }
  92.       res.close();
  93.       state.close();
  94.       Pointage.setcolumn2(colonne);
  95.       Pointage.setdata2(donnee);     
  96.     } catch (SQLException e) {}
  97.   }
  98.    
  99.     /////
  100.     //tableau ligne 3
  101.     /////
  102.     public void initLigne3(String query){
  103.     try {
  104.       Statement state =Connexion.getInstance().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
  105.       ResultSet res = state.executeQuery(query);
  106.       ResultSetMetaData meta = res.getMetaData();
  107.       Object [] colonne = new Object[meta.getColumnCount()];
  108.       for(int i = 1 ; i <= meta.getColumnCount(); i++)
  109.         colonne[i-1] = meta.getColumnName(i);
  110.       //Petite manipulation pour obtenir le nombre de lignes
  111.       res.last();
  112.       Object[][] donnee = new Object[res.getRow()][meta.getColumnCount()];
  113.       //On revient au départ
  114.       res.beforeFirst();
  115.       int j = 1;
  116.       //On remplit le tableau d'Object[][]
  117.       while(res.next()){
  118.         for(int i = 1 ; i <= meta.getColumnCount(); i++)
  119.           donnee[j-1][i-1] = res.getObject(i);
  120.         j++;
  121.       }
  122.       res.close();
  123.       state.close();
  124.       Pointage.setcolumn3(colonne);
  125.       Pointage.setdata3(donnee);     
  126.     } catch (SQLException e) {}
  127.   }
  128.    
  129.     /////
  130.     //tableau ligne 4
  131.     /////
  132.     public void initLigne4(String query){
  133.     try {
  134.       Statement state =Connexion.getInstance().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
  135.       ResultSet res = state.executeQuery(query);
  136.       ResultSetMetaData meta = res.getMetaData();
  137.       Object [] colonne = new Object[meta.getColumnCount()];
  138.       for(int i = 1 ; i <= meta.getColumnCount(); i++)
  139.         colonne[i-1] = meta.getColumnName(i);
  140.       //Petite manipulation pour obtenir le nombre de lignes
  141.       res.last();
  142.       Object[][] donnee = new Object[res.getRow()][meta.getColumnCount()];
  143.       //On revient au départ
  144.       res.beforeFirst();
  145.       int j = 1;
  146.       //On remplit le tableau d'Object[][]
  147.       while(res.next()){
  148.         for(int i = 1 ; i <= meta.getColumnCount(); i++)
  149.           donnee[j-1][i-1] = res.getObject(i);
  150.         j++;
  151.       }
  152.       res.close();
  153.       state.close();
  154.       Pointage.setcolumn4(colonne);
  155.       Pointage.setdata4(donnee);     
  156.     } catch (SQLException e) {}
  157.   }
  158.    
  159.     ////////////////////////////////////////////////////////////////////////////
  160.     public static Object[][] getdata1 (){
  161.         return data1;
  162.     };
  163.     public static Object[][] getdata2 (){
  164.         return data2;
  165.     };
  166.     public static Object[][] getdata3 (){
  167.         return data3;
  168.     };
  169.     public static Object[][] getdata4 (){
  170.         return data4;
  171.     };
  172.     ////////////////////////////////////////////////////////////////////////////
  173.     public static Object[] getcolumn1 (){
  174.         return column1;
  175.     };
  176.     public static Object[] getcolumn2 (){
  177.         return column2;
  178.     };
  179.     public static Object[] getcolumn3 (){
  180.         return column3;
  181.     };
  182.     public static Object[] getcolumn4 (){
  183.         return column4;
  184.     };
  185.     ////////////////////////////////////////////////////////////////////////////
  186.     public static void setdata1 (Object dat[][]){
  187.         data1= dat;
  188.     };
  189.     public static void setdata2 (Object dat[][]){
  190.         data2= dat;
  191.     };
  192.     public static void setdata3 (Object dat[][]){
  193.         data3= dat;
  194.     };
  195.     public static void setdata4 (Object dat[][]){
  196.         data4= dat;
  197.     };
  198.     ////////////////////////////////////////////////////////////////////////////
  199.     public static void setcolumn1 (Object col[]){
  200.         column1= col;
  201.     };
  202.     public static void setcolumn2 (Object col[]){
  203.         column2= col;
  204.     };
  205.     public static void setcolumn3 (Object col[]){
  206.         column3= col;
  207.     };
  208.     public static void setcolumn4 (Object col[]){
  209.         column4= col;
  210.     };
  211.    
  212.     public void stop(){
  213.     fen.setVisible( false );
  214.   }
  215. }


 
 
ModifBoutons

Code :
  1. package pointage;
  2. import java.awt.event.ActionListener;
  3. import java.awt.event.ActionEvent;
  4. import java.sql.*;
  5. import javax.swing.JButton;
  6. public class ModifBoutons implements ActionListener {
  7.    
  8.     public void actionPerformed(ActionEvent événement) {
  9.          Pointage p = new Pointage();
  10.          String ligne="0";
  11.          String bonnet;
  12.          String nomboutonclique;
  13.          String updist;
  14.          String uptemps;
  15.          String upvitesse;       
  16.        
  17.          nomboutonclique = ((JButton) événement.getSource()).getName() ;
  18.          System.out.println("nom du bouton : "+nomboutonclique);
  19.          if (nomboutonclique=="jButton1"||nomboutonclique=="jButton2"||nomboutonclique=="jButton3"||nomboutonclique=="jButton4"||
  20.              nomboutonclique=="jButton5"||nomboutonclique=="jButton6"||nomboutonclique=="jButton7"||nomboutonclique=="jButton8"||
  21.              nomboutonclique=="jButton9"||nomboutonclique=="jButton9" ){
  22.          ligne="1";
  23.          }
  24.          if (nomboutonclique=="jButton11"||nomboutonclique=="jButton12"||nomboutonclique=="jButton13"||nomboutonclique=="jButton14"||
  25.              nomboutonclique=="jButton15"||nomboutonclique=="jButton16"||nomboutonclique=="jButton17"||nomboutonclique=="jButton18"||
  26.              nomboutonclique=="jButton19"||nomboutonclique=="jButton19" ){
  27.          ligne="2";
  28.          }
  29.          if (nomboutonclique=="jButton21"||nomboutonclique=="jButton22"||nomboutonclique=="jButton23"||nomboutonclique=="jButton24"||
  30.              nomboutonclique=="jButton25"||nomboutonclique=="jButton26"||nomboutonclique=="jButton27"||nomboutonclique=="jButton28"||
  31.              nomboutonclique=="jButton29"||nomboutonclique=="jButton29" ){
  32.          ligne="3";
  33.          }
  34.          if (nomboutonclique=="jButton31"||nomboutonclique=="jButton32"||nomboutonclique=="jButton33"||nomboutonclique=="jButton34"||
  35.              nomboutonclique=="jButton35"||nomboutonclique=="jButton36"||nomboutonclique=="jButton37"||nomboutonclique=="jButton38"||
  36.              nomboutonclique=="jButton39"||nomboutonclique=="jButton39" ){
  37.          ligne="4";
  38.          }
  39.        
  40.          JButton titreboutonclique = (JButton) événement.getSource();
  41.          bonnet = titreboutonclique.getText();
  42.          System.out.println("numéro du ligne : "+ligne);
  43.          System.out.println("numéro du bonnet : "+bonnet);
  44.        
  45.          updist = "UPDATE Nageur SET distance = distance+50 WHERE actif='1' AND ligne = '"+ligne+"' AND bonnet = '"+bonnet+"';";
  46.          uptemps= "UPDATE Nageur SET temps = CURRENT_TIME()-heure_depart WHERE actif='1' AND  ligne = '"+ligne+"' AND bonnet = '"+bonnet+"';";
  47.          upvitesse = "UPDATE Nageur SET vitesse = distance*3.6/TIME_TO_SEC(temps) WHERE actif='1' AND ligne = '"+ligne+"' AND bonnet = '"+bonnet+"';";
  48.        
  49.          try {
  50.             Statement state = Connexion.getInstance().createStatement();
  51.             int updatedist = state.executeUpdate(updist);
  52.             int updatetemps = state.executeUpdate(uptemps);
  53.             int updatevitesse = state.executeUpdate(upvitesse);
  54.             System.out.println("distance : "+updatedist+" temps : "+updatetemps+" vitesse : "+updatevitesse);
  55.             state.close();
  56.            
  57.          } catch (SQLException e) {}
  58.     }
  59.   }


 
 
Juste pour info, j'ai bien ententu essayé de faire un p.start à la fin du actionPerformed mais résultat, une seconde fenêtre à jour se lance en plus de la première donc ce n'est pas pratique. Il me faut juste la réinitialisation des jScrollPane :D
 
Merci à celui ou celle qui pourra résoudre ce soucis qui à l'air simple sur le papier.
 
Bonne soirée,
 
Jérémy


 
 
Bonsoir,
 
Si j'ai bien compris le problème, les données sont mises à jour dans la BDD mais pas sur l'affichage. Pour mettre à jour la JTable, on peut utiliser après avoir mis à jour les données (Obect[][] data) :

Code :
  1. ( (AbstractTableModel) table.getModel()).fireTableDataChanged();


 
Un petit exemple simple :

Code :
  1. /*
  2. * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. *   - Redistributions of source code must retain the above copyright
  9. *     notice, this list of conditions and the following disclaimer.
  10. *
  11. *   - Redistributions in binary form must reproduce the above copyright
  12. *     notice, this list of conditions and the following disclaimer in the
  13. *     documentation and/or other materials provided with the distribution.
  14. *
  15. *   - Neither the name of Oracle or the names of its
  16. *     contributors may be used to endorse or promote products derived
  17. *     from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22. * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  25. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. */
  31.  
  32. /*
  33. * SimpleTableDemo.java requires no other files.
  34. */
  35. import javax.swing.JButton;
  36. import javax.swing.JFrame;
  37. import javax.swing.JPanel;
  38. import javax.swing.JScrollPane;
  39. import javax.swing.JTable;
  40. import javax.swing.table.AbstractTableModel;
  41. import java.awt.Dimension;
  42. import java.awt.GridLayout;
  43. import java.awt.event.ActionEvent;
  44. import java.awt.event.ActionListener;
  45. import java.util.Arrays;
  46. import java.util.Vector;
  47. /**
  48. *  
  49. * @see http://forum.hardware.fr/hfr/Progr [...] 1229_1.htm
  50. * @see http://docs.oracle.com/javase/tuto [...] table.html
  51. * @see http://docs.oracle.com/javase/tuto [...] html?code=
  52. * http://docs.oracle.com/javase/tuto [...] eDemo.java
  53. *
  54. */
  55. public class SimpleTableDemo extends JPanel {
  56.    
  57.     private String[] columnNamesArray = {"First Name",
  58.             "Last Name",
  59.             "Sport",
  60.             "# of Years",
  61.             "Vegetarian"};
  62.    
  63.     private Vector<String> columnNames;
  64.    
  65.     private Object[][] dataArray = {
  66.             {"Kathy", "Smith",
  67.              "Snowboarding", new Integer(5), new Boolean(false)},
  68.             {"John", "Doe",
  69.              "Rowing", new Integer(3), new Boolean(true)},
  70.             {"Sue", "Black",
  71.              "Knitting", new Integer(2), new Boolean(false)},
  72.             {"Jane", "White",
  73.              "Speed reading", new Integer(20), new Boolean(true)},
  74.             {"Joe", "Brown",
  75.              "Pool", new Integer(10), new Boolean(false)}
  76.             };
  77.    
  78.     private Vector<Vector<Object>> data;
  79.    
  80.     private JTable table;
  81.    
  82.     public SimpleTableDemo() {
  83.         super(new GridLayout(1,0));
  84.         columnNames = new Vector<>(Arrays.asList(columnNamesArray));       
  85.         data = new Vector<>();
  86.        
  87.         for(Object[] line : dataArray) {
  88.          data.add(new Vector<>(Arrays.asList(line)));
  89.         }
  90.         table = new JTable(data, columnNames);
  91.         table.setPreferredScrollableViewportSize(new Dimension(500, 70));
  92.         table.setFillsViewportHeight(true);
  93.         //Create the scroll pane and add the table to it.
  94.         JScrollPane scrollPane = new JScrollPane(table);
  95.         //Add the scroll pane to this panel.
  96.         add(scrollPane);
  97.     }
  98.    
  99.     private void addLineTable() {
  100.      int nbRows = data.size();
  101.      Object[] row = {"first name " + nbRows, "last name " + nbRows, "sport " + nbRows, new Integer(5), new Boolean(false)};
  102.      data.add(new Vector<>(Arrays.asList(row)));
  103.      ( (AbstractTableModel) table.getModel()).fireTableDataChanged();
  104.     }
  105.     /**
  106.      * Create the GUI and show it.  For thread safety,
  107.      * this method should be invoked from the
  108.      * event-dispatching thread.
  109.      */
  110.     private static void createAndShowGUI() {
  111.         //Create and set up the window.
  112.         JFrame frame = new JFrame("SimpleTableDemo" );
  113.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  114.         //Create and set up the content pane.
  115.         final SimpleTableDemo newContentPane = new SimpleTableDemo();
  116.         frame.add("Center", newContentPane);
  117.        
  118.         JButton addButton = new JButton("Add" );
  119.         addButton.addActionListener(new ActionListener() {
  120.   @Override
  121.   public void actionPerformed(ActionEvent arg0) {
  122.    newContentPane.addLineTable();
  123.   }
  124.  });
  125.        
  126.         JPanel southPanel = new JPanel();
  127.         southPanel.add(addButton);
  128.         frame.add("South", southPanel);
  129.         //Display the window.
  130.         frame.setSize(640, 280);
  131.         frame.setLocationRelativeTo(null);
  132.         frame.setVisible(true);
  133.     }
  134.     public static void main(String[] args) {
  135.         //Schedule a job for the event-dispatching thread:
  136.         //creating and showing this application's GUI.
  137.         javax.swing.SwingUtilities.invokeLater(new Runnable() {
  138.             public void run() {
  139.                 createAndShowGUI();
  140.             }
  141.         });
  142.     }
  143. }


n°2217788
jeremyl332​40
Posté le 27-01-2014 à 20:49:45  profilanswer
 

Bonsoir.
Tu as tout à fait compris ce que je cherche à faire.
Je vais essayer de mettre en place cette méthode même si je sens que je vais me casser les dents avec mes 4 jtables et 40 boutons^^
 
En tout cas merci et je laisserai des nouvelles qu'elles soient bonnes ou pas.
 
Bonne soirée

n°2217823
honrisse
Posté le 28-01-2014 à 10:16:41  profilanswer
 

Bonjour,
J'ai modifié rapidement le code et commenté tout ce qui est bdd mais quelque chose comme ça permet de faire la mise à jour de l'affichage :

Code :
  1. package pointage;
  2. import java.awt.event.ActionListener;
  3. import java.awt.event.ActionEvent;
  4. import java.sql.*;
  5. import javax.swing.JButton;
  6. public class ModifBoutons implements ActionListener {
  7. private FenPointage fen;
  8. public ModifBoutons(FenPointage f) {
  9.  fen = f;
  10. }
  11. public void actionPerformed(ActionEvent événement) {
  12.  Pointage p = new Pointage();
  13.  String ligne = "0";
  14.  String bonnet;
  15.  String nomboutonclique;
  16.  String updist;
  17.  String uptemps;
  18.  String upvitesse;
  19.  nomboutonclique = ((JButton) événement.getSource()).getName();
  20.  System.out.println("nom du bouton : " + nomboutonclique);
  21.  if (nomboutonclique == "jButton1" || nomboutonclique == "jButton2"
  22.    || nomboutonclique == "jButton3"
  23.    || nomboutonclique == "jButton4"
  24.    || nomboutonclique == "jButton5"
  25.    || nomboutonclique == "jButton6"
  26.    || nomboutonclique == "jButton7"
  27.    || nomboutonclique == "jButton8"
  28.    || nomboutonclique == "jButton9"
  29.    || nomboutonclique == "jButton9" ) {
  30.   ligne = "1";
  31.  }
  32.  if (nomboutonclique == "jButton11" || nomboutonclique == "jButton12"
  33.    || nomboutonclique == "jButton13"
  34.    || nomboutonclique == "jButton14"
  35.    || nomboutonclique == "jButton15"
  36.    || nomboutonclique == "jButton16"
  37.    || nomboutonclique == "jButton17"
  38.    || nomboutonclique == "jButton18"
  39.    || nomboutonclique == "jButton19"
  40.    || nomboutonclique == "jButton19" ) {
  41.   ligne = "2";
  42.  }
  43.  if (nomboutonclique == "jButton21" || nomboutonclique == "jButton22"
  44.    || nomboutonclique == "jButton23"
  45.    || nomboutonclique == "jButton24"
  46.    || nomboutonclique == "jButton25"
  47.    || nomboutonclique == "jButton26"
  48.    || nomboutonclique == "jButton27"
  49.    || nomboutonclique == "jButton28"
  50.    || nomboutonclique == "jButton29"
  51.    || nomboutonclique == "jButton29" ) {
  52.   ligne = "3";
  53.  }
  54.  if (nomboutonclique == "jButton31" || nomboutonclique == "jButton32"
  55.    || nomboutonclique == "jButton33"
  56.    || nomboutonclique == "jButton34"
  57.    || nomboutonclique == "jButton35"
  58.    || nomboutonclique == "jButton36"
  59.    || nomboutonclique == "jButton37"
  60.    || nomboutonclique == "jButton38"
  61.    || nomboutonclique == "jButton39"
  62.    || nomboutonclique == "jButton39" ) {
  63.   ligne = "4";
  64.  }
  65.  JButton titreboutonclique = (JButton) événement.getSource();
  66.  bonnet = titreboutonclique.getText();
  67.  System.out.println("numéro du ligne : " + ligne);
  68.  System.out.println("numéro du bonnet : " + bonnet);
  69.  updist = "UPDATE Nageur SET distance = distance+50 WHERE actif='1' AND ligne = '"
  70.    + ligne + "' AND bonnet = '" + bonnet + "';";
  71.  uptemps = "UPDATE Nageur SET temps = CURRENT_TIME()-heure_depart WHERE actif='1' AND  ligne = '"
  72.    + ligne + "' AND bonnet = '" + bonnet + "';";
  73.  upvitesse = "UPDATE Nageur SET vitesse = distance*3.6/TIME_TO_SEC(temps) WHERE actif='1' AND ligne = '"
  74.    + ligne + "' AND bonnet = '" + bonnet + "';";
  75. //  try {
  76. //   Statement state = Connexion.getInstance().createStatement();
  77. //   int updatedist = state.executeUpdate(updist);
  78. //   int updatetemps = state.executeUpdate(uptemps);
  79. //   int updatevitesse = state.executeUpdate(upvitesse);
  80. //   System.out.println("distance : " + updatedist + " temps : "
  81. //     + updatetemps + " vitesse : " + updatevitesse);
  82. //   state.close();
  83. //
  84. //  } catch (SQLException e) {
  85. //  }
  86.  switch(ligne) {
  87.  case "1" :
  88.   if(nomboutonclique == "jButton1" ) {
  89.    int val = (int) Pointage.data1[0][2];
  90.    Pointage.data1[0][2] = val + 50;
  91.    fen.jTable1.getModel().setValueAt(Pointage.data1[0][2], 0, 2);
  92.   }
  93.   break;
  94.  case "2" :
  95.   if(nomboutonclique == "jButton11" ) {
  96.    int val = (int) Pointage.data2[0][2];
  97.    Pointage.data2[0][2] = val + 50;
  98.    fen.jTable2.getModel().setValueAt(Pointage.data2[0][2], 0, 2);
  99.   }
  100.   break;
  101.  case "3" :
  102.   if(nomboutonclique == "jButton21" ) {
  103.    int val = (int) Pointage.data3[0][2];
  104.    Pointage.data3[0][2] = val + 50;
  105.    fen.jTable3.getModel().setValueAt(Pointage.data3[0][2], 0, 2);
  106.   }
  107.   break;
  108.  case "4" :
  109.   if(nomboutonclique == "jButton31" ) {
  110.    int val = (int) Pointage.data4[0][2];
  111.    Pointage.data4[0][2] = val + 50;
  112.    fen.jTable4.getModel().setValueAt(Pointage.data4[0][2], 0, 2);
  113.   }
  114.   break;
  115.  default :
  116.   break;
  117.  }
  118. }
  119. }


 

Code :
  1. package pointage;
  2. import javax.swing.JButton;
  3. import javax.swing.JLabel;
  4. import javax.swing.JScrollPane;
  5. import javax.swing.JTable;
  6. import javax.swing.GroupLayout;
  7. import javax.swing.LayoutStyle;
  8. public class FenPointage extends javax.swing.JFrame {
  9. public JButton jButton1;
  10. public JButton jButton2;
  11. public JButton jButton3;
  12. public JButton jButton4;
  13. public JButton jButton5;
  14. public JButton jButton6;
  15. public JButton jButton7;
  16. public JButton jButton8;
  17. public JButton jButton9;
  18. public JButton jButton10;
  19. public JButton jButton11;
  20. public JButton jButton12;
  21. public JButton jButton13;
  22. public JButton jButton14;
  23. public JButton jButton15;
  24. public JButton jButton16;
  25. public JButton jButton17;
  26. public JButton jButton18;
  27. public JButton jButton19;
  28. public JButton jButton20;
  29. public JButton jButton21;
  30. public JButton jButton22;
  31. public JButton jButton23;
  32. public JButton jButton24;
  33. public JButton jButton25;
  34. public JButton jButton26;
  35. public JButton jButton27;
  36. public JButton jButton28;
  37. public JButton jButton29;
  38. public JButton jButton30;
  39. public JButton jButton31;
  40. public JButton jButton32;
  41. public JButton jButton33;
  42. public JButton jButton34;
  43. public JButton jButton35;
  44. public JButton jButton36;
  45. public JButton jButton37;
  46. public JButton jButton38;
  47. public JButton jButton39;
  48. public JButton jButton40;
  49. private JLabel jLabel1;
  50. private JLabel jLabel2;
  51. private JLabel jLabel3;
  52. private JLabel jLabel4;
  53. private JLabel jLabel5;
  54. private JLabel jLabel6;
  55. private JLabel jLabel7;
  56. private JLabel jLabel8;
  57. private JScrollPane jScrollPane1;
  58. private JScrollPane jScrollPane2;
  59. private JScrollPane jScrollPane3;
  60. private JScrollPane jScrollPane4;
  61. protected JTable jTable1;
  62. protected JTable jTable2;
  63. protected JTable jTable3;
  64. protected JTable jTable4;
  65. public FenPointage() {
  66.  setSize(650, 600);
  67.  setTitle("Pointage des nageurs" );
  68.  setLocationRelativeTo(null);
  69.  setDefaultCloseOperation(EXIT_ON_CLOSE);
  70. }
  71. public void initComponents() {
  72.  jScrollPane1 = new JScrollPane();
  73.  jScrollPane2 = new JScrollPane();
  74.  jScrollPane3 = new JScrollPane();
  75.  jScrollPane4 = new JScrollPane();
  76.  jTable1 = new JTable();
  77.  jTable2 = new JTable();
  78.  jTable3 = new JTable();
  79.  jTable4 = new JTable();
  80.  jLabel1 = new JLabel();
  81.  jLabel2 = new JLabel();
  82.  jLabel3 = new JLabel();
  83.  jLabel4 = new JLabel();
  84.  jLabel5 = new JLabel();
  85.  jLabel6 = new JLabel();
  86.  jLabel7 = new JLabel();
  87.  jLabel8 = new JLabel();
  88.  jButton1 = new JButton();
  89.  jButton2 = new JButton();
  90.  jButton3 = new JButton();
  91.  jButton4 = new JButton();
  92.  jButton5 = new JButton();
  93.  jButton6 = new JButton();
  94.  jButton7 = new JButton();
  95.  jButton8 = new JButton();
  96.  jButton9 = new JButton();
  97.  jButton10 = new JButton();
  98.  jButton11 = new JButton();
  99.  jButton12 = new JButton();
  100.  jButton13 = new JButton();
  101.  jButton14 = new JButton();
  102.  jButton15 = new JButton();
  103.  jButton16 = new JButton();
  104.  jButton17 = new JButton();
  105.  jButton18 = new JButton();
  106.  jButton19 = new JButton();
  107.  jButton20 = new JButton();
  108.  jButton21 = new JButton();
  109.  jButton22 = new JButton();
  110.  jButton23 = new JButton();
  111.  jButton24 = new JButton();
  112.  jButton25 = new JButton();
  113.  jButton26 = new JButton();
  114.  jButton27 = new JButton();
  115.  jButton28 = new JButton();
  116.  jButton29 = new JButton();
  117.  jButton30 = new JButton();
  118.  jButton31 = new JButton();
  119.  jButton32 = new JButton();
  120.  jButton33 = new JButton();
  121.  jButton34 = new JButton();
  122.  jButton35 = new JButton();
  123.  jButton36 = new JButton();
  124.  jButton37 = new JButton();
  125.  jButton38 = new JButton();
  126.  jButton39 = new JButton();
  127.  jButton40 = new JButton();
  128.  ModifBoutons modif = new ModifBoutons(this);
  129.  jButton1.addActionListener(modif);
  130.  jButton2.addActionListener(modif);
  131.  jButton3.addActionListener(modif);
  132.  jButton4.addActionListener(modif);
  133.  jButton5.addActionListener(modif);
  134.  jButton6.addActionListener(modif);
  135.  jButton7.addActionListener(modif);
  136.  jButton8.addActionListener(modif);
  137.  jButton9.addActionListener(modif);
  138.  jButton10.addActionListener(modif);
  139.  jButton11.addActionListener(modif);
  140.  jButton12.addActionListener(modif);
  141.  jButton13.addActionListener(modif);
  142.  jButton14.addActionListener(modif);
  143.  jButton15.addActionListener(modif);
  144.  jButton16.addActionListener(modif);
  145.  jButton17.addActionListener(modif);
  146.  jButton18.addActionListener(modif);
  147.  jButton19.addActionListener(modif);
  148.  jButton20.addActionListener(modif);
  149.  jButton21.addActionListener(modif);
  150.  jButton22.addActionListener(modif);
  151.  jButton23.addActionListener(modif);
  152.  jButton24.addActionListener(modif);
  153.  jButton25.addActionListener(modif);
  154.  jButton25.addActionListener(modif);
  155.  jButton26.addActionListener(modif);
  156.  jButton27.addActionListener(modif);
  157.  jButton28.addActionListener(modif);
  158.  jButton29.addActionListener(modif);
  159.  jButton30.addActionListener(modif);
  160.  jButton31.addActionListener(modif);
  161.  jButton32.addActionListener(modif);
  162.  jButton33.addActionListener(modif);
  163.  jButton34.addActionListener(modif);
  164.  jButton35.addActionListener(modif);
  165.  jButton36.addActionListener(modif);
  166.  jButton37.addActionListener(modif);
  167.  jButton38.addActionListener(modif);
  168.  jButton39.addActionListener(modif);
  169.  jButton40.addActionListener(modif);
  170.  jTable1.setModel(new javax.swing.table.DefaultTableModel(Pointage
  171.    .getdata1(), Pointage.getcolumn1()));
  172.  jScrollPane1.setViewportView(jTable1);
  173.  jTable2.setModel(new javax.swing.table.DefaultTableModel(Pointage
  174.    .getdata2(), Pointage.getcolumn2()));
  175.  jScrollPane2.setViewportView(jTable2);
  176.  jTable3.setModel(new javax.swing.table.DefaultTableModel(Pointage
  177.    .getdata3(), Pointage.getcolumn3()));
  178.  jScrollPane3.setViewportView(jTable3);
  179.  jTable4.setModel(new javax.swing.table.DefaultTableModel(Pointage
  180.    .getdata4(), Pointage.getcolumn4()));
  181.  jScrollPane4.setViewportView(jTable4);
  182.  jButton1.setText("1" );
  183.  jButton1.setName("jButton1" );
  184.  jButton2.setText("2" );
  185.  jButton2.setName("jButton2" );
  186.  jButton3.setText("3" );
  187.  jButton3.setName("jButton3" );
  188.  jButton4.setText("4" );
  189.  jButton4.setName("jButton4" );
  190.  jButton5.setText("5" );
  191.  jButton5.setName("jButton5" );
  192.  jButton6.setText("6" );
  193.  jButton6.setName("jButton6" );
  194.  jButton7.setText("7" );
  195.  jButton7.setName("jButton7" );
  196.  jButton8.setText("8" );
  197.  jButton8.setName("jButton8" );
  198.  jButton9.setText("9" );
  199.  jButton9.setName("jButton9" );
  200.  jButton10.setText("10" );
  201.  jButton10.setName("jButton10" );
  202.  jButton11.setText("1" );
  203.  jButton11.setName("jButton11" );
  204.  jButton12.setText("2" );
  205.  jButton12.setName("jButton12" );
  206.  jButton13.setText("3" );
  207.  jButton13.setName("jButton13" );
  208.  jButton14.setText("4" );
  209.  jButton14.setName("jButton14" );
  210.  jButton15.setText("5" );
  211.  jButton15.setName("jButton15" );
  212.  jButton16.setText("6" );
  213.  jButton16.setName("jButton16" );
  214.  jButton17.setText("7" );
  215.  jButton17.setName("jButton17" );
  216.  jButton18.setText("8" );
  217.  jButton18.setName("jButton18" );
  218.  jButton19.setText("9" );
  219.  jButton19.setName("jButton19" );
  220.  jButton20.setText("10" );
  221.  jButton20.setName("jButton20" );
  222.  jButton21.setText("1" );
  223.  jButton21.setName("jButton21" );
  224.  jButton22.setText("2" );
  225.  jButton22.setName("jButton22" );
  226.  jButton23.setText("3" );
  227.  jButton23.setName("jButton23" );
  228.  jButton24.setText("4" );
  229.  jButton24.setName("jButton24" );
  230.  jButton25.setText("5" );
  231.  jButton25.setName("jButton25" );
  232.  jButton26.setText("6" );
  233.  jButton26.setName("jButton26" );
  234.  jButton27.setText("7" );
  235.  jButton27.setName("jButton27" );
  236.  jButton28.setText("8" );
  237.  jButton28.setName("jButton28" );
  238.  jButton29.setText("9" );
  239.  jButton29.setName("jButton29" );
  240.  jButton30.setText("10" );
  241.  jButton30.setName("jButton30" );
  242.  jButton31.setText("1" );
  243.  jButton31.setName("jButton31" );
  244.  jButton32.setText("2" );
  245.  jButton32.setName("jButton32" );
  246.  jButton33.setText("3" );
  247.  jButton33.setName("jButton33" );
  248.  jButton34.setText("4" );
  249.  jButton34.setName("jButton34" );
  250.  jButton35.setText("5" );
  251.  jButton35.setName("jButton35" );
  252.  jButton36.setText("6" );
  253.  jButton36.setName("jButton36" );
  254.  jButton37.setText("7" );
  255.  jButton37.setName("jButton37" );
  256.  jButton38.setText("8" );
  257.  jButton38.setName("jButton38" );
  258.  jButton39.setText("9" );
  259.  jButton39.setName("jButton39" );
  260.  jButton40.setText("10" );
  261.  jButton40.setName("jButton40" );
  262.  jLabel1.setText("Ligne 1" );
  263.  jLabel2.setText("Ligne 2" );
  264.  jLabel3.setText("Ligne 3" );
  265.  jLabel4.setText("Ligne 4" );
  266.  jLabel5.setText("bonnet" );
  267.  jLabel6.setText("bonnet" );
  268.  jLabel7.setText("bonnet" );
  269.  jLabel8.setText("bonnet" );
  270.  GroupLayout layout = new GroupLayout(getContentPane());
  271.  getContentPane().setLayout(layout);
  272.  layout.setHorizontalGroup(layout
  273.    .createParallelGroup(GroupLayout.Alignment.LEADING)
  274.    .addGroup(
  275.      layout.createSequentialGroup()
  276.        .addGap(30, 30, 30)
  277.        .addGroup(
  278.          layout.createParallelGroup(
  279.            GroupLayout.Alignment.LEADING)
  280.            .addGroup(
  281.              layout.createParallelGroup(
  282.                GroupLayout.Alignment.TRAILING)
  283.                .addComponent(
  284.                  jButton10,
  285.                  GroupLayout.PREFERRED_SIZE,
  286.                  50,
  287.                  GroupLayout.PREFERRED_SIZE)
  288.                .addComponent(
  289.                  jButton1,
  290.                  GroupLayout.PREFERRED_SIZE,
  291.                  50,
  292.                  GroupLayout.PREFERRED_SIZE)
  293.                .addComponent(
  294.                  jButton2,
  295.                  GroupLayout.PREFERRED_SIZE,
  296.                  50,
  297.                  GroupLayout.PREFERRED_SIZE)
  298.                .addComponent(
  299.                  jButton3,
  300.                  GroupLayout.PREFERRED_SIZE,
  301.                  50,
  302.                  GroupLayout.PREFERRED_SIZE)
  303.                .addComponent(
  304.                  jButton4,
  305.                  GroupLayout.PREFERRED_SIZE,
  306.                  50,
  307.                  GroupLayout.PREFERRED_SIZE)
  308.                .addComponent(
  309.                  jButton5,
  310.                  GroupLayout.PREFERRED_SIZE,
  311.                  50,
  312.                  GroupLayout.PREFERRED_SIZE)
  313.                .addComponent(
  314.                  jButton6,
  315.                  GroupLayout.PREFERRED_SIZE,
  316.                  50,
  317.                  GroupLayout.PREFERRED_SIZE)
  318.                .addComponent(
  319.                  jButton7,
  320.                  GroupLayout.PREFERRED_SIZE,
  321.                  50,
  322.                  GroupLayout.PREFERRED_SIZE)
  323.                .addComponent(
  324.                  jButton8,
  325.                  GroupLayout.PREFERRED_SIZE,
  326.                  50,
  327.                  GroupLayout.PREFERRED_SIZE)
  328.                .addComponent(
  329.                  jButton9,
  330.                  GroupLayout.PREFERRED_SIZE,
  331.                  50,
  332.                  GroupLayout.PREFERRED_SIZE)
  333.                .addComponent(
  334.                  jButton21,
  335.                  GroupLayout.PREFERRED_SIZE,
  336.                  50,
  337.                  GroupLayout.PREFERRED_SIZE)
  338.                .addComponent(
  339.                  jButton22,
  340.                  GroupLayout.PREFERRED_SIZE,
  341.                  50,
  342.                  GroupLayout.PREFERRED_SIZE)
  343.                .addComponent(
  344.                  jButton23,
  345.                  GroupLayout.PREFERRED_SIZE,
  346.                  50,
  347.                  GroupLayout.PREFERRED_SIZE)
  348.                .addComponent(
  349.                  jButton24,
  350.                  GroupLayout.PREFERRED_SIZE,
  351.                  50,
  352.                  GroupLayout.PREFERRED_SIZE)
  353.                .addComponent(
  354.                  jButton25,
  355.                  GroupLayout.PREFERRED_SIZE,
  356.                  50,
  357.                  GroupLayout.PREFERRED_SIZE)
  358.                .addComponent(
  359.                  jButton26,
  360.                  GroupLayout.PREFERRED_SIZE,
  361.                  50,
  362.                  GroupLayout.PREFERRED_SIZE)
  363.                .addComponent(
  364.                  jButton27,
  365.                  GroupLayout.PREFERRED_SIZE,
  366.                  50,
  367.                  GroupLayout.PREFERRED_SIZE)
  368.                .addComponent(
  369.                  jButton28,
  370.                  GroupLayout.PREFERRED_SIZE,
  371.                  50,
  372.                  GroupLayout.PREFERRED_SIZE)
  373.                .addComponent(
  374.                  jButton29,
  375.                  GroupLayout.PREFERRED_SIZE,
  376.                  50,
  377.                  GroupLayout.PREFERRED_SIZE)
  378.                .addComponent(
  379.                  jButton30,
  380.                  GroupLayout.PREFERRED_SIZE,
  381.                  50,
  382.                  GroupLayout.PREFERRED_SIZE))
  383.            .addComponent(jLabel5)
  384.            .addComponent(jLabel7))
  385.        .addPreferredGap(
  386.          LayoutStyle.ComponentPlacement.RELATED)
  387.        .addGroup(
  388.          layout.createParallelGroup(
  389.            GroupLayout.Alignment.LEADING,
  390.            false)
  391.            .addGroup(
  392.              GroupLayout.Alignment.TRAILING,
  393.              layout.createSequentialGroup()
  394.                .addGroup(
  395.                  layout.createParallelGroup(
  396.                    GroupLayout.Alignment.LEADING)
  397.                    .addComponent(
  398.                      jScrollPane1,
  399.                      GroupLayout.PREFERRED_SIZE,
  400.                      200,
  401.                      GroupLayout.PREFERRED_SIZE)
  402.                    .addComponent(
  403.                      jLabel1))
  404.                .addPreferredGap(
  405.                  LayoutStyle.ComponentPlacement.RELATED,
  406.                  50,
  407.                  Short.MAX_VALUE)
  408.                .addGroup(
  409.                  layout.createParallelGroup(
  410.                    GroupLayout.Alignment.LEADING)
  411.                    .addComponent(
  412.                      jLabel6)
  413.                    .addGroup(
  414.                      layout.createParallelGroup(
  415.                        GroupLayout.Alignment.LEADING)
  416.                        .addComponent(
  417.                          jButton11,
  418.                          GroupLayout.Alignment.TRAILING,
  419.                          GroupLayout.PREFERRED_SIZE,
  420.                          50,
  421.                          GroupLayout.PREFERRED_SIZE)
  422.                        .addComponent(
  423.                          jButton12,
  424.                          GroupLayout.Alignment.TRAILING,
  425.                          GroupLayout.PREFERRED_SIZE,
  426.                          50,
  427.                          GroupLayout.PREFERRED_SIZE)
  428.                        .addComponent(
  429.                          jButton13,
  430.                          GroupLayout.Alignment.TRAILING,
  431.                          GroupLayout.PREFERRED_SIZE,
  432.                          50,
  433.                          GroupLayout.PREFERRED_SIZE)
  434.                        .addComponent(
  435.                          jButton14,
  436.                          GroupLayout.Alignment.TRAILING,
  437.                          GroupLayout.PREFERRED_SIZE,
  438.                          50,
  439.                          GroupLayout.PREFERRED_SIZE)
  440.                        .addComponent(
  441.                          jButton15,
  442.                          GroupLayout.Alignment.TRAILING,
  443.                          GroupLayout.PREFERRED_SIZE,
  444.                          50,
  445.                          GroupLayout.PREFERRED_SIZE)
  446.                        .addComponent(
  447.                          jButton16,
  448.                          GroupLayout.Alignment.TRAILING,
  449.                          GroupLayout.PREFERRED_SIZE,
  450.                          50,
  451.                          GroupLayout.PREFERRED_SIZE)
  452.                        .addComponent(
  453.                          jButton17,
  454.                          GroupLayout.Alignment.TRAILING,
  455.                          GroupLayout.PREFERRED_SIZE,
  456.                          50,
  457.                          GroupLayout.PREFERRED_SIZE)
  458.                        .addComponent(
  459.                          jButton18,
  460.                          GroupLayout.Alignment.TRAILING,
  461.                          GroupLayout.PREFERRED_SIZE,
  462.                          50,
  463.                          GroupLayout.PREFERRED_SIZE)
  464.                        .addComponent(
  465.                          jButton19,
  466.                          GroupLayout.Alignment.TRAILING,
  467.                          GroupLayout.PREFERRED_SIZE,
  468.                          50,
  469.                          GroupLayout.PREFERRED_SIZE)
  470.                        .addComponent(
  471.                          jButton20,
  472.                          GroupLayout.Alignment.TRAILING,
  473.                          GroupLayout.PREFERRED_SIZE,
  474.                          50,
  475.                          GroupLayout.PREFERRED_SIZE))))
  476.            .addGroup(
  477.              GroupLayout.Alignment.TRAILING,
  478.              layout.createSequentialGroup()
  479.                .addGroup(
  480.                  layout.createParallelGroup(
  481.                    GroupLayout.Alignment.LEADING)
  482.                    .addComponent(
  483.                      jScrollPane3,
  484.                      GroupLayout.PREFERRED_SIZE,
  485.                      200,
  486.                      GroupLayout.PREFERRED_SIZE)
  487.                    .addComponent(
  488.                      jLabel3))
  489.                .addPreferredGap(
  490.                  LayoutStyle.ComponentPlacement.RELATED,
  491.                  GroupLayout.DEFAULT_SIZE,
  492.                  Short.MAX_VALUE)
  493.                .addGroup(
  494.                  layout.createParallelGroup(
  495.                    GroupLayout.Alignment.LEADING)
  496.                    .addComponent(
  497.                      jLabel8)
  498.                    .addGroup(
  499.                      layout.createParallelGroup(
  500.                        GroupLayout.Alignment.LEADING)
  501.                        .addComponent(
  502.                          jButton31,
  503.                          GroupLayout.Alignment.TRAILING,
  504.                          GroupLayout.PREFERRED_SIZE,
  505.                          50,
  506.                          GroupLayout.PREFERRED_SIZE)
  507.                        .addComponent(
  508.                          jButton32,
  509.                          GroupLayout.Alignment.TRAILING,
  510.                          GroupLayout.PREFERRED_SIZE,
  511.                          50,
  512.                          GroupLayout.PREFERRED_SIZE)
  513.                        .addComponent(
  514.                          jButton33,
  515.                          GroupLayout.Alignment.TRAILING,
  516.                          GroupLayout.PREFERRED_SIZE,
  517.                          50,
  518.                          GroupLayout.PREFERRED_SIZE)
  519.                        .addComponent(
  520.                          jButton34,
  521.                          GroupLayout.Alignment.TRAILING,
  522.                          GroupLayout.PREFERRED_SIZE,
  523.                          50,
  524.                          GroupLayout.PREFERRED_SIZE)
  525.                        .addComponent(
  526.                          jButton35,
  527.                          GroupLayout.Alignment.TRAILING,
  528.                          GroupLayout.PREFERRED_SIZE,
  529.                          50,
  530.                          GroupLayout.PREFERRED_SIZE)
  531.                        .addComponent(
  532.                          jButton36,
  533.                          GroupLayout.Alignment.TRAILING,
  534.                          GroupLayout.PREFERRED_SIZE,
  535.                          50,
  536.                          GroupLayout.PREFERRED_SIZE)
  537.                        .addComponent(
  538.                          jButton37,
  539.                          GroupLayout.Alignment.TRAILING,
  540.                          GroupLayout.PREFERRED_SIZE,
  541.                          50,
  542.                          GroupLayout.PREFERRED_SIZE)
  543.                        .addComponent(
  544.                          jButton38,
  545.                          GroupLayout.Alignment.TRAILING,
  546.                          GroupLayout.PREFERRED_SIZE,
  547.                          50,
  548.                          GroupLayout.PREFERRED_SIZE)
  549.                        .addComponent(
  550.                          jButton39,
  551.                          GroupLayout.Alignment.TRAILING,
  552.                          GroupLayout.PREFERRED_SIZE,
  553.                          50,
  554.                          GroupLayout.PREFERRED_SIZE)
  555.                        .addComponent(
  556.                          jButton40,
  557.                          GroupLayout.Alignment.TRAILING,
  558.                          GroupLayout.PREFERRED_SIZE,
  559.                          50,
  560.                          GroupLayout.PREFERRED_SIZE)))))
  561.        .addPreferredGap(
  562.          LayoutStyle.ComponentPlacement.RELATED)
  563.        .addGroup(
  564.          layout.createParallelGroup(
  565.            GroupLayout.Alignment.LEADING)
  566.            .addComponent(jLabel4)
  567.            .addComponent(jLabel2)
  568.            .addComponent(
  569.              jScrollPane2,
  570.              GroupLayout.PREFERRED_SIZE,
  571.              200,
  572.              GroupLayout.PREFERRED_SIZE)
  573.            .addComponent(
  574.              jScrollPane4,
  575.              GroupLayout.PREFERRED_SIZE,
  576.              200,
  577.              GroupLayout.PREFERRED_SIZE))
  578.        .addGap(30, 30, 30)));
  579.  layout.setVerticalGroup(layout
  580.    .createParallelGroup(GroupLayout.Alignment.LEADING)
  581.    .addGroup(
  582.      layout.createSequentialGroup()
  583.        .addGap(28, 28, 28)
  584.        .addGroup(
  585.          layout.createParallelGroup(
  586.            GroupLayout.Alignment.BASELINE)
  587.            .addComponent(jLabel1)
  588.            .addComponent(jLabel2)
  589.            .addComponent(jLabel5)
  590.            .addComponent(jLabel6))
  591.        .addPreferredGap(
  592.          LayoutStyle.ComponentPlacement.RELATED)
  593.        .addGroup(
  594.          layout.createParallelGroup(
  595.            GroupLayout.Alignment.LEADING)
  596.            .addGroup(
  597.              layout.createParallelGroup(
  598.                GroupLayout.Alignment.LEADING,
  599.                false)
  600.                .addGroup(
  601.                  layout.createSequentialGroup()
  602.                    .addComponent(
  603.                      jButton1,
  604.                      GroupLayout.PREFERRED_SIZE,
  605.                      15,
  606.                      GroupLayout.PREFERRED_SIZE)
  607.                    .addPreferredGap(
  608.                      LayoutStyle.ComponentPlacement.RELATED)
  609.                    .addComponent(
  610.                      jButton2,
  611.                      GroupLayout.PREFERRED_SIZE,
  612.                      15,
  613.                      GroupLayout.PREFERRED_SIZE)
  614.                    .addPreferredGap(
  615.                      LayoutStyle.ComponentPlacement.RELATED)
  616.                    .addComponent(
  617.                      jButton3,
  618.                      GroupLayout.PREFERRED_SIZE,
  619.                      15,
  620.                      GroupLayout.PREFERRED_SIZE)
  621.                    .addPreferredGap(
  622.                      LayoutStyle.ComponentPlacement.RELATED)
  623.                    .addComponent(
  624.                      jButton4,
  625.                      GroupLayout.PREFERRED_SIZE,
  626.                      15,
  627.                      GroupLayout.PREFERRED_SIZE)
  628.                    .addPreferredGap(
  629.                      LayoutStyle.ComponentPlacement.RELATED)
  630.                    .addComponent(
  631.                      jButton5,
  632.                      GroupLayout.PREFERRED_SIZE,
  633.                      15,
  634.                      GroupLayout.PREFERRED_SIZE)
  635.                    .addPreferredGap(
  636.                      LayoutStyle.ComponentPlacement.RELATED)
  637.                    .addComponent(
  638.                      jButton6,
  639.                      GroupLayout.PREFERRED_SIZE,
  640.                      15,
  641.                      GroupLayout.PREFERRED_SIZE)
  642.                    .addPreferredGap(
  643.                      LayoutStyle.ComponentPlacement.RELATED)
  644.                    .addComponent(
  645.                      jButton7,
  646.                      GroupLayout.PREFERRED_SIZE,
  647.                      15,
  648.                      GroupLayout.PREFERRED_SIZE)
  649.                    .addPreferredGap(
  650.                      LayoutStyle.ComponentPlacement.RELATED)
  651.                    .addComponent(
  652.                      jButton8,
  653.                      GroupLayout.PREFERRED_SIZE,
  654.                      15,
  655.                      GroupLayout.PREFERRED_SIZE)
  656.                    .addPreferredGap(
  657.                      LayoutStyle.ComponentPlacement.RELATED)
  658.                    .addComponent(
  659.                      jButton9,
  660.                      GroupLayout.PREFERRED_SIZE,
  661.                      15,
  662.                      GroupLayout.PREFERRED_SIZE)
  663.                    .addPreferredGap(
  664.                      LayoutStyle.ComponentPlacement.RELATED)
  665.                    .addComponent(
  666.                      jButton10,
  667.                      GroupLayout.PREFERRED_SIZE,
  668.                      15,
  669.                      GroupLayout.PREFERRED_SIZE))
  670.                .addComponent(
  671.                  jScrollPane1,
  672.                  GroupLayout.DEFAULT_SIZE,
  673.                  225,
  674.                  Short.MAX_VALUE)
  675.                .addComponent(
  676.                  jScrollPane2,
  677.                  GroupLayout.PREFERRED_SIZE,
  678.                  0,
  679.                  Short.MAX_VALUE))
  680.            .addGroup(
  681.              layout.createSequentialGroup()
  682.                .addComponent(
  683.                  jButton11,
  684.                  GroupLayout.PREFERRED_SIZE,
  685.                  15,
  686.                  GroupLayout.PREFERRED_SIZE)
  687.                .addPreferredGap(
  688.                  LayoutStyle.ComponentPlacement.RELATED)
  689.                .addComponent(
  690.                  jButton12,
  691.                  GroupLayout.PREFERRED_SIZE,
  692.                  15,
  693.                  GroupLayout.PREFERRED_SIZE)
  694.                .addPreferredGap(
  695.                  LayoutStyle.ComponentPlacement.RELATED)
  696.                .addComponent(
  697.                  jButton13,
  698.                  GroupLayout.PREFERRED_SIZE,
  699.                  15,
  700.                  GroupLayout.PREFERRED_SIZE)
  701.                .addPreferredGap(
  702.                  LayoutStyle.ComponentPlacement.RELATED)
  703.                .addComponent(
  704.                  jButton14,
  705.                  GroupLayout.PREFERRED_SIZE,
  706.                  15,
  707.                  GroupLayout.PREFERRED_SIZE)
  708.                .addPreferredGap(
  709.                  LayoutStyle.ComponentPlacement.RELATED)
  710.                .addComponent(
  711.                  jButton15,
  712.                  GroupLayout.PREFERRED_SIZE,
  713.                  15,
  714.                  GroupLayout.PREFERRED_SIZE)
  715.                .addPreferredGap(
  716.                  LayoutStyle.ComponentPlacement.RELATED)
  717.                .addComponent(
  718.                  jButton16,
  719.                  GroupLayout.PREFERRED_SIZE,
  720.                  15,
  721.                  GroupLayout.PREFERRED_SIZE)
  722.                .addPreferredGap(
  723.                  LayoutStyle.ComponentPlacement.RELATED)
  724.                .addComponent(
  725.                  jButton17,
  726.                  GroupLayout.PREFERRED_SIZE,
  727.                  15,
  728.                  GroupLayout.PREFERRED_SIZE)
  729.                .addPreferredGap(
  730.                  LayoutStyle.ComponentPlacement.RELATED)
  731.                .addComponent(
  732.                  jButton18,
  733.                  GroupLayout.PREFERRED_SIZE,
  734.                  15,
  735.                  GroupLayout.PREFERRED_SIZE)
  736.                .addPreferredGap(
  737.                  LayoutStyle.ComponentPlacement.RELATED)
  738.                .addComponent(
  739.                  jButton19,
  740.                  GroupLayout.PREFERRED_SIZE,
  741.                  15,
  742.                  GroupLayout.PREFERRED_SIZE)
  743.                .addPreferredGap(
  744.                  LayoutStyle.ComponentPlacement.RELATED)
  745.                .addComponent(
  746.                  jButton20,
  747.                  GroupLayout.PREFERRED_SIZE,
  748.                  15,
  749.                  GroupLayout.PREFERRED_SIZE)))
  750.        .addGap(30, 30, 30)
  751.        .addGroup(
  752.          layout.createParallelGroup(
  753.            GroupLayout.Alignment.BASELINE)
  754.            .addComponent(jLabel3)
  755.            .addComponent(jLabel4)
  756.            .addComponent(jLabel7)
  757.            .addComponent(jLabel8))
  758.        .addPreferredGap(
  759.          LayoutStyle.ComponentPlacement.RELATED)
  760.        .addGroup(
  761.          layout.createParallelGroup(
  762.            GroupLayout.Alignment.LEADING,
  763.            false)
  764.            .addGroup(
  765.              layout.createSequentialGroup()
  766.                .addComponent(
  767.                  jButton31,
  768.                  GroupLayout.PREFERRED_SIZE,
  769.                  15,
  770.                  GroupLayout.PREFERRED_SIZE)
  771.                .addPreferredGap(
  772.                  LayoutStyle.ComponentPlacement.RELATED)
  773.                .addComponent(
  774.                  jButton32,
  775.                  GroupLayout.PREFERRED_SIZE,
  776.                  15,
  777.                  GroupLayout.PREFERRED_SIZE)
  778.                .addPreferredGap(
  779.                  LayoutStyle.ComponentPlacement.RELATED)
  780.                .addComponent(
  781.                  jButton33,
  782.                  GroupLayout.PREFERRED_SIZE,
  783.                  15,
  784.                  GroupLayout.PREFERRED_SIZE)
  785.                .addPreferredGap(
  786.                  LayoutStyle.ComponentPlacement.RELATED)
  787.                .addComponent(
  788.                  jButton34,
  789.                  GroupLayout.PREFERRED_SIZE,
  790.                  15,
  791.                  GroupLayout.PREFERRED_SIZE)
  792.                .addPreferredGap(
  793.                  LayoutStyle.ComponentPlacement.RELATED)
  794.                .addComponent(
  795.                  jButton35,
  796.                  GroupLayout.PREFERRED_SIZE,
  797.                  15,
  798.                  GroupLayout.PREFERRED_SIZE)
  799.                .addPreferredGap(
  800.                  LayoutStyle.ComponentPlacement.RELATED)
  801.                .addComponent(
  802.                  jButton36,
  803.                  GroupLayout.PREFERRED_SIZE,
  804.                  15,
  805.                  GroupLayout.PREFERRED_SIZE)
  806.                .addPreferredGap(
  807.                  LayoutStyle.ComponentPlacement.RELATED)
  808.                .addComponent(
  809.                  jButton37,
  810.                  GroupLayout.PREFERRED_SIZE,
  811.                  15,
  812.                  GroupLayout.PREFERRED_SIZE)
  813.                .addPreferredGap(
  814.                  LayoutStyle.ComponentPlacement.RELATED)
  815.                .addComponent(
  816.                  jButton38,
  817.                  GroupLayout.PREFERRED_SIZE,
  818.                  15,
  819.                  GroupLayout.PREFERRED_SIZE)
  820.                .addPreferredGap(
  821.                  LayoutStyle.ComponentPlacement.RELATED)
  822.                .addComponent(
  823.                  jButton39,
  824.                  GroupLayout.PREFERRED_SIZE,
  825.                  15,
  826.                  GroupLayout.PREFERRED_SIZE)
  827.                .addPreferredGap(
  828.                  LayoutStyle.ComponentPlacement.RELATED)
  829.                .addComponent(
  830.                  jButton40,
  831.                  GroupLayout.PREFERRED_SIZE,
  832.                  15,
  833.                  GroupLayout.PREFERRED_SIZE))
  834.            .addGroup(
  835.              layout.createSequentialGroup()
  836.                .addComponent(
  837.                  jButton21,
  838.                  GroupLayout.PREFERRED_SIZE,
  839.                  15,
  840.                  GroupLayout.PREFERRED_SIZE)
  841.                .addPreferredGap(
  842.                  LayoutStyle.ComponentPlacement.RELATED)
  843.                .addComponent(
  844.                  jButton22,
  845.                  GroupLayout.PREFERRED_SIZE,
  846.                  15,
  847.                  GroupLayout.PREFERRED_SIZE)
  848.                .addPreferredGap(
  849.                  LayoutStyle.ComponentPlacement.RELATED)
  850.                .addComponent(
  851.                  jButton23,
  852.                  GroupLayout.PREFERRED_SIZE,
  853.                  15,
  854.                  GroupLayout.PREFERRED_SIZE)
  855.                .addPreferredGap(
  856.                  LayoutStyle.ComponentPlacement.RELATED)
  857.                .addComponent(
  858.                  jButton24,
  859.                  GroupLayout.PREFERRED_SIZE,
  860.                  15,
  861.                  GroupLayout.PREFERRED_SIZE)
  862.                .addPreferredGap(
  863.                  LayoutStyle.ComponentPlacement.RELATED)
  864.                .addComponent(
  865.                  jButton25,
  866.                  GroupLayout.PREFERRED_SIZE,
  867.                  15,
  868.                  GroupLayout.PREFERRED_SIZE)
  869.                .addPreferredGap(
  870.                  LayoutStyle.ComponentPlacement.RELATED)
  871.                .addComponent(
  872.                  jButton26,
  873.                  GroupLayout.PREFERRED_SIZE,
  874.                  15,
  875.                  GroupLayout.PREFERRED_SIZE)
  876.                .addPreferredGap(
  877.                  LayoutStyle.ComponentPlacement.RELATED)
  878.                .addComponent(
  879.                  jButton27,
  880.                  GroupLayout.PREFERRED_SIZE,
  881.                  15,
  882.                  GroupLayout.PREFERRED_SIZE)
  883.                .addPreferredGap(
  884.                  LayoutStyle.ComponentPlacement.RELATED)
  885.                .addComponent(
  886.                  jButton28,
  887.                  GroupLayout.PREFERRED_SIZE,
  888.                  15,
  889.                  GroupLayout.PREFERRED_SIZE)
  890.                .addPreferredGap(
  891.                  LayoutStyle.ComponentPlacement.RELATED)
  892.                .addComponent(
  893.                  jButton29,
  894.                  GroupLayout.PREFERRED_SIZE,
  895.                  15,
  896.                  GroupLayout.PREFERRED_SIZE)
  897.                .addPreferredGap(
  898.                  LayoutStyle.ComponentPlacement.RELATED)
  899.                .addComponent(
  900.                  jButton30,
  901.                  GroupLayout.PREFERRED_SIZE,
  902.                  15,
  903.                  GroupLayout.PREFERRED_SIZE))
  904.            .addComponent(
  905.              jScrollPane3,
  906.              GroupLayout.DEFAULT_SIZE,
  907.              225, Short.MAX_VALUE)
  908.            .addComponent(
  909.              jScrollPane4,
  910.              GroupLayout.PREFERRED_SIZE,
  911.              0, Short.MAX_VALUE))
  912.        .addGap(30, 30, 30)));
  913. }
  914. }


 

Code :
  1. package pointage;
  2. import java.sql.*;
  3. public class Pointage {
  4. public FenPointage fen;
  5. String l1 = "SELECT bonnet, prenom, distance FROM Nageur WHERE actif='1' AND ligne='1' ORDER BY bonnet ASC;";
  6. String l2 = "SELECT bonnet, prenom, distance FROM Nageur WHERE actif='1' AND ligne='2' ORDER BY bonnet ASC;";
  7. String l3 = "SELECT bonnet, prenom, distance FROM Nageur WHERE actif='1' AND ligne='3' ORDER BY bonnet ASC;";
  8. String l4 = "SELECT bonnet, prenom, distance FROM Nageur WHERE actif='1' AND ligne='4' ORDER BY bonnet ASC;";
  9. public static Object[] column1 = {"Bonnet", "Prenom", "Distance"};
  10. public static Object[] column2 = {"Bonnet", "Prenom", "Distance"};
  11. public static Object[] column3 = {"Bonnet", "Prenom", "Distance"};
  12. public static Object[] column4 = {"Bonnet", "Prenom", "Distance"};
  13. public static Object[][] data1 = {{1, "Jeremy", 3300}};
  14. public static Object[][] data2 = {{2, "f54g", 600}};
  15. public static Object[][] data3 = {{1, "muche", 100}};
  16. public static Object[][] data4 = {{1, "f454g", 1000}};
  17. public static void main(String[] args) {
  18.  Pointage point = new Pointage();
  19.  point.start();
  20. }
  21. public Pointage() {
  22.  fen = new FenPointage();
  23. }
  24. public void start() {
  25. //  initLigne1(l1);
  26. //  initLigne2(l2);
  27. //  initLigne3(l3);
  28. //  initLigne4(l4);
  29.  fen.initComponents();
  30.  fen.repaint();
  31.  fen.setVisible(true);
  32. }
  33. // ///
  34. // tableau ligne 1
  35. // ///
  36. public void initLigne1(String query) {
  37.  try {
  38.   Statement state = Connexion.getInstance().createStatement(
  39.     ResultSet.TYPE_SCROLL_INSENSITIVE,
  40.     ResultSet.CONCUR_READ_ONLY);
  41.   ResultSet res = state.executeQuery(query);
  42.   ResultSetMetaData meta = res.getMetaData();
  43.   Object[] colonne = new Object[meta.getColumnCount()];
  44.   for (int i = 1; i <= meta.getColumnCount(); i++)
  45.    colonne[i - 1] = meta.getColumnName(i);
  46.   // Petite manipulation pour obtenir le nombre de lignes
  47.   res.last();
  48.   Object[][] donnee = new Object[res.getRow()][meta.getColumnCount()];
  49.   // On revient au départ
  50.   res.beforeFirst();
  51.   int j = 1;
  52.   // On remplit le tableau d'Object[][]
  53.   while (res.next()) {
  54.    for (int i = 1; i <= meta.getColumnCount(); i++)
  55.     donnee[j - 1][i - 1] = res.getObject(i);
  56.    j++;
  57.   }
  58.   res.close();
  59.   state.close();
  60.   Pointage.setcolumn1(colonne);
  61.   Pointage.setdata1(donnee);
  62.  } catch (SQLException e) {
  63.  }
  64. }
  65. // ///
  66. // tableau ligne 2
  67. // ///
  68. public void initLigne2(String query) {
  69.  try {
  70.   Statement state = Connexion.getInstance().createStatement(
  71.     ResultSet.TYPE_SCROLL_INSENSITIVE,
  72.     ResultSet.CONCUR_READ_ONLY);
  73.   ResultSet res = state.executeQuery(query);
  74.   ResultSetMetaData meta = res.getMetaData();
  75.   Object[] colonne = new Object[meta.getColumnCount()];
  76.   for (int i = 1; i <= meta.getColumnCount(); i++)
  77.    colonne[i - 1] = meta.getColumnName(i);
  78.   // Petite manipulation pour obtenir le nombre de lignes
  79.   res.last();
  80.   Object[][] donnee = new Object[res.getRow()][meta.getColumnCount()];
  81.   // On revient au départ
  82.   res.beforeFirst();
  83.   int j = 1;
  84.   // On remplit le tableau d'Object[][]
  85.   while (res.next()) {
  86.    for (int i = 1; i <= meta.getColumnCount(); i++)
  87.     donnee[j - 1][i - 1] = res.getObject(i);
  88.    j++;
  89.   }
  90.   res.close();
  91.   state.close();
  92.   Pointage.setcolumn2(colonne);
  93.   Pointage.setdata2(donnee);
  94.  } catch (SQLException e) {
  95.  }
  96. }
  97. // ///
  98. // tableau ligne 3
  99. // ///
  100. public void initLigne3(String query) {
  101.  try {
  102.   Statement state = Connexion.getInstance().createStatement(
  103.     ResultSet.TYPE_SCROLL_INSENSITIVE,
  104.     ResultSet.CONCUR_READ_ONLY);
  105.   ResultSet res = state.executeQuery(query);
  106.   ResultSetMetaData meta = res.getMetaData();
  107.   Object[] colonne = new Object[meta.getColumnCount()];
  108.   for (int i = 1; i <= meta.getColumnCount(); i++)
  109.    colonne[i - 1] = meta.getColumnName(i);
  110.   // Petite manipulation pour obtenir le nombre de lignes
  111.   res.last();
  112.   Object[][] donnee = new Object[res.getRow()][meta.getColumnCount()];
  113.   // On revient au départ
  114.   res.beforeFirst();
  115.   int j = 1;
  116.   // On remplit le tableau d'Object[][]
  117.   while (res.next()) {
  118.    for (int i = 1; i <= meta.getColumnCount(); i++)
  119.     donnee[j - 1][i - 1] = res.getObject(i);
  120.    j++;
  121.   }
  122.   res.close();
  123.   state.close();
  124.   Pointage.setcolumn3(colonne);
  125.   Pointage.setdata3(donnee);
  126.  } catch (SQLException e) {
  127.  }
  128. }
  129. // ///
  130. // tableau ligne 4
  131. // ///
  132. public void initLigne4(String query) {
  133.  try {
  134.   Statement state = Connexion.getInstance().createStatement(
  135.     ResultSet.TYPE_SCROLL_INSENSITIVE,
  136.     ResultSet.CONCUR_READ_ONLY);
  137.   ResultSet res = state.executeQuery(query);
  138.   ResultSetMetaData meta = res.getMetaData();
  139.   Object[] colonne = new Object[meta.getColumnCount()];
  140.   for (int i = 1; i <= meta.getColumnCount(); i++)
  141.    colonne[i - 1] = meta.getColumnName(i);
  142.   // Petite manipulation pour obtenir le nombre de lignes
  143.   res.last();
  144.   Object[][] donnee = new Object[res.getRow()][meta.getColumnCount()];
  145.   // On revient au départ
  146.   res.beforeFirst();
  147.   int j = 1;
  148.   // On remplit le tableau d'Object[][]
  149.   while (res.next()) {
  150.    for (int i = 1; i <= meta.getColumnCount(); i++)
  151.     donnee[j - 1][i - 1] = res.getObject(i);
  152.    j++;
  153.   }
  154.   res.close();
  155.   state.close();
  156.   Pointage.setcolumn4(colonne);
  157.   Pointage.setdata4(donnee);
  158.  } catch (SQLException e) {
  159.  }
  160. }
  161. // //////////////////////////////////////////////////////////////////////////
  162. public static Object[][] getdata1() {
  163.  return data1;
  164. };
  165. public static Object[][] getdata2() {
  166.  return data2;
  167. };
  168. public static Object[][] getdata3() {
  169.  return data3;
  170. };
  171. public static Object[][] getdata4() {
  172.  return data4;
  173. };
  174. // //////////////////////////////////////////////////////////////////////////
  175. public static Object[] getcolumn1() {
  176.  return column1;
  177. };
  178. public static Object[] getcolumn2() {
  179.  return column2;
  180. };
  181. public static Object[] getcolumn3() {
  182.  return column3;
  183. };
  184. public static Object[] getcolumn4() {
  185.  return column4;
  186. };
  187. // //////////////////////////////////////////////////////////////////////////
  188. public static void setdata1(Object dat[][]) {
  189.  data1 = dat;
  190. };
  191. public static void setdata2(Object dat[][]) {
  192.  data2 = dat;
  193. };
  194. public static void setdata3(Object dat[][]) {
  195.  data3 = dat;
  196. };
  197. public static void setdata4(Object dat[][]) {
  198.  data4 = dat;
  199. };
  200. // //////////////////////////////////////////////////////////////////////////
  201. public static void setcolumn1(Object col[]) {
  202.  column1 = col;
  203. };
  204. public static void setcolumn2(Object col[]) {
  205.  column2 = col;
  206. };
  207. public static void setcolumn3(Object col[]) {
  208.  column3 = col;
  209. };
  210. public static void setcolumn4(Object col[]) {
  211.  column4 = col;
  212. };
  213. public void stop() {
  214.  fen.setVisible(false);
  215. }
  216. }


 

Code :
  1. package pointage;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.SQLException;
  5. import javax.swing.JOptionPane;
  6. public class Connexion {
  7. private static String url = "jdbc:mysql://localhost:3306/bdd_anl";
  8. private static String user = "java";
  9. private static String passwd = "anl";
  10. private static Connection connect;
  11. public static Connection getInstance() {
  12.  if (connect == null) {
  13.   try {
  14.    connect = DriverManager.getConnection(url, user, passwd);
  15.    System.out.println("connexion etablie" );
  16.   } catch (SQLException e) {
  17.    JOptionPane.showMessageDialog(null, e.getMessage(),
  18.      "ERREUR DE CONNEXION ! ", JOptionPane.ERROR_MESSAGE);
  19.   }
  20.  }
  21.  return connect;
  22. }
  23. }

n°2217848
jeremyl332​40
Posté le 28-01-2014 à 13:19:09  profilanswer
 

Ah oui, t'as beaucoup bossé, merci pour ton temps.
La structure est là, le fonctionnement aussi. Il faut que je retouche l'action pour certain boutons qui ne sont pas bien associé sinon le rafraîchissement est bon.
 
J'ai remarqué une chose importante à laquelle je pensais que ça se ferait tout seul aussi c'est que quand on ajoute un nageur actif, celui-ci serait automatiquement ajouté d'un l'une des 4 jtable suivant son numéro de ligne hors là il faut quand même que je relance l'appli pour que la correction se fasse.
Cette modif serait faite par une autre appli qui touche la même DB.
 
A ton avis, est-ce que cela va changer en grande partie la structure de ce programme?
 
Re-merci à nouveau car je n'ai plus cette grosse épine dans le pied.
 
Bonne journée.

n°2217914
honrisse
Posté le 28-01-2014 à 18:17:59  profilanswer
 

jeremyl33240 a écrit :

Ah oui, t'as beaucoup bossé, merci pour ton temps.
La structure est là, le fonctionnement aussi. Il faut que je retouche l'action pour certain boutons qui ne sont pas bien associé sinon le rafraîchissement est bon.
 
J'ai remarqué une chose importante à laquelle je pensais que ça se ferait tout seul aussi c'est que quand on ajoute un nageur actif, celui-ci serait automatiquement ajouté d'un l'une des 4 jtable suivant son numéro de ligne hors là il faut quand même que je relance l'appli pour que la correction se fasse.
Cette modif serait faite par une autre appli qui touche la même DB.
 
A ton avis, est-ce que cela va changer en grande partie la structure de ce programme?
 
Re-merci à nouveau car je n'ai plus cette grosse épine dans le pied.
 
Bonne journée.


 
Si un nageur dans la ligne 1 et avec bonnet=5 n'existe pas dans la BDD il faut rajouter les actions lorsque l'on clique sur le bouton jbutton5 (ajouter une nouvelle ligne dans le tableau général data, mettre à jour la jtable puis tout sauvegarder dans la BDD).
 
L'architecture générale ne devrait pas trop changer, il faut juste rajouter les actions à réaliser après un appuie sur le bouton correspondant.
 
Si j'ai bien compris comment doit fonctionner le programme, le code suivant (dans le fichier ModifBoutons.java à la place de l'ancien switch(ligne){}) permet de rajouter automatiquement une ligne dans la jtable si le bonnet n'existe pas :

Code :
  1. switch(ligne) {
  2.  case "1" :
  3.   //Map permet de faire le lien entre le numero de bonnet (key dans la map)
  4.   //et l'index (value dans la map) dans le tableau Pointage.data1
  5.   Map<Integer, Integer> map = new HashMap<>();
  6.   for(int i = 0; i<Pointage.data1.length; i++) {
  7.    map.put((Integer) Pointage.data1[i][0], i);
  8.   }
  9.   boolean containBonnet = false;
  10.   int currentBonnet = 1;
  11.   switch(nomboutonclique) {
  12.   case "jButton1":
  13.    if(map.containsKey(1)) {
  14.     //Le bonnet existe dans le tableau Pointage.data1
  15.     containBonnet = true;
  16.    }
  17.    currentBonnet = 1;
  18.    break;
  19.   case "jButton2":
  20.    if(map.containsKey(2)) {
  21.     containBonnet = true;
  22.    }
  23.    currentBonnet = 2;
  24.    break;
  25.   case "jButton3":
  26.    if(map.containsKey(3)) {
  27.     containBonnet = true;
  28.    }
  29.    currentBonnet = 3;
  30.    break;
  31.   case "jButton4":
  32.    if(map.containsKey(4)) {
  33.     containBonnet = true;
  34.    }
  35.    currentBonnet = 4;
  36.    break;
  37.   case "jButton5":
  38.    if(map.containsKey(5)) {
  39.     containBonnet = true;
  40.    }
  41.    currentBonnet = 5;
  42.    break;
  43.   case "jButton6":
  44.    if(map.containsKey(6)) {
  45.     containBonnet = true;
  46.    }
  47.    currentBonnet = 6;
  48.    break;
  49.   case "jButton7":
  50.    if(map.containsKey(7)) {
  51.     containBonnet = true;
  52.    }
  53.    currentBonnet = 7;
  54.    break;
  55.   case "jButton8":
  56.    if(map.containsKey(8)) {
  57.     containBonnet = true;
  58.    }
  59.    currentBonnet = 8;
  60.    break;
  61.   case "jButton9":
  62.    if(map.containsKey(9)) {
  63.     containBonnet = true;
  64.    }
  65.    currentBonnet = 9;
  66.    break;
  67.   case "jButton10":
  68.    if(map.containsKey(10)) {
  69.     containBonnet = true;
  70.    }
  71.    currentBonnet = 10;
  72.    break;
  73.   default:
  74.    break;
  75.   }
  76.   if(containBonnet) {
  77.    //Si le bonnet existe deja, on ajoute 50 en distance
  78.    int val = (int) Pointage.data1[map.get(currentBonnet)][2];
  79.    Pointage.data1[map.get(currentBonnet)][2] = val + 50;
  80.    fen.jTable1.getModel().setValueAt(Pointage.data1[map.get(currentBonnet)][2], map.get(currentBonnet), 2);
  81.   } else {
  82.    //On demande le nouveau nom
  83.    String newName = "nageur" + currentBonnet;
  84.    String input = JOptionPane.showInputDialog(fen, "New name" );
  85.    if(input != null) {
  86.     newName = input;
  87.    }
  88.    //Sinon, on ajoute une ligne dans le tableau Pointage.data1
  89.    ((javax.swing.table.DefaultTableModel)fen.jTable1.getModel()).insertRow(fen.jTable1.getModel().getRowCount(),
  90.      new Object[]{currentBonnet, newName, 0});
  91.    //Agrandissement du tableau Pointage.data1 en creant un tableau temporaire plus grand de 1 en ligne
  92.    Object[][] data = new Object[Pointage.data1.length + 1][3];
  93.    //Recopie de Pointage.data1 dans data
  94.    for(int i = 0; i<Pointage.data1.length; i++) {
  95.     data[i] = Pointage.data1[i];
  96.    }
  97.    //Ajout de la ligne
  98.    data[data.length - 1] = new Object[]{currentBonnet, newName, 0};
  99.    Pointage.data1 = data;
  100.   }
  101.   break;
  102.  case "2" :
  103.   if(nomboutonclique == "jButton11" ) {
  104.    int val = (int) Pointage.data2[0][2];
  105.    Pointage.data2[0][2] = val + 50;
  106.    fen.jTable2.getModel().setValueAt(Pointage.data2[0][2], 0, 2);
  107.   }
  108.   break;
  109.  case "3" :
  110.   if(nomboutonclique == "jButton21" ) {
  111.    int val = (int) Pointage.data3[0][2];
  112.    Pointage.data3[0][2] = val + 50;
  113.    fen.jTable3.getModel().setValueAt(Pointage.data3[0][2], 0, 2);
  114.   }
  115.   break;
  116.  case "4" :
  117.   if(nomboutonclique == "jButton31" ) {
  118.    int val = (int) Pointage.data4[0][2];
  119.    Pointage.data4[0][2] = val + 50;
  120.    fen.jTable4.getModel().setValueAt(Pointage.data4[0][2], 0, 2);
  121.   }
  122.   break;
  123.  default :
  124.   break;
  125.  }


 
Le code est long puisqu'il faut réaliser pour chaque bouton l'action correspondante.
Si ce fonctionnement est bon, il faut faire la même chose pour les autres lignes 2,3,4 et sauvegarder dans la BDD s'il le faut, sinon on peut s'inspirer de ce code pour voir comment on rajoute des lignes dans la jtable et le tableau data.


Message édité par honrisse le 28-01-2014 à 18:19:06
n°2218001
jeremyl332​40
Posté le 29-01-2014 à 11:15:27  profilanswer
 

Je vais vous résumer ce le projet sans faire trop compliqué,
il s'agit du pointage de nageurs qui font des longueurs pendant un temps donné (1 ou 2h). Avant il s'agissait de 4 personnes qui stabilotaient sur du papier donc c'est pour ça qu'automatiser ce système m'est venu en tête.
 
Au final de ce projet, il y aura 3 interfaces dont deux sur le même PC et une autre(celle sur laquelle vous m'aidez en ce moment) sur un autre PC connecté en wifi sur le même réseau.  
La base de donnée est crée et fonctionne comme il faut pour le moment. J'ai mis le code de sa création à la fin du message.
 
Tout d'abord une interface principale qui permettra de créer les nouveaux nageurs dans la BDD mysql lors de leurs inscriptions, faire démarrer les nageurs(un ou plusieurs en même temps) en les mettant en "actif" le tout dans un menu déroulant. La même chose pour les arrêter(un ou tous) avec un menu déroulant avec case à cocher ou à sélectionner. Un dernier point pour cette fenêtre, il faudra aussi à la fin du challenge supprimer tous les nageurs inscrits (un bouton) afin de réutiliser l'application pour le prochain challenge.
Cette partie là n'est pas du tout codée sauf pour les requêtes SQL mais est faite sur le papier si vous voyez ce que je veux dire.
 
Dans un second temps, il y aura une fenêtre d'affichage qui sera sur le même PC que l'interface principale mais sur un second écran. Cette IHM permettra aux personnes du public de consulter les résultats(le classement des nageurs actif et classement total, les distances, les temps, leur vitesse moyenne). Cette IHM doit se rafraîchir toutes les x secondes pour afficher les données à jour des nageurs, mettre dans la partie "actif" ceux qui sont actif en ajoutant ou supprimant les lignes correspondantes aux nageurs.
J'ai déjà fait cette fenêtre, le rafraîchissement des données se fait mais l'affichage me pose problème pour le moment. C'est pour ça que je suis passé à la dernière IHM dont nous traitons ici.
http://hpics.li/a13e954
 
Donc sur un autre PC il me faut une appli qui se connecte à la même BDD de l'autre PC et qui se chargera de mettre à jour la distance des nageurs à chaque longueur(piscine de 25m donc le pointage se fait sur un aller-retour). Le pointeur aura sur son IHM les 4 tables qui correspondront aux 4 lignes de la piscine. Pour chaque nageur actif dans telle ligne, un bouton lui sera consacré pour incrémenter sa distance de 50m. Le pointeur pourra voir en direct la distance du nageur chose que vous m'avez résolu hier. Il faut que quand un nageur commence ou s'arrête(fait par l'IHM principale) sa ligne correspondante dans l'une des 4 tables du pointage s'ajoute ou s'efface.
 
La base de données :

Code :
  1. CREATE TABLE  bdd_anl.Nageur (
  2. id INT( 3 ) NOT NULL AUTO_INCREMENT,
  3. nom VARCHAR( 20 ) NOT NULL ,
  4. prenom VARCHAR( 20 ) NOT NULL ,
  5. sexe CHAR(1) NOT NULL ,
  6. age INT(2) NOT NULL ,
  7. nage VARCHAR(10) NOT NULL ,
  8. heure_depart TIME ,
  9. temps TIME ,
  10. distance INT(5) ,
  11. vitesse FLOAT(4, 2) ,
  12. actif BOOL NOT NULL ,
  13. ligne INT(1) ,
  14. bonnet INT(1) ,
  15. PRIMARY KEY ( id )
  16. ) ENGINE = MYISAM;


http://hpics.li/e6822bb
 
 
J'ai regardé votre code mais je ne l'ai pas implémenté car je ne pense pas qu'il corresponde à ce que je voulais faire au départ. Néanmoins je vais travailler dessus pour voir si je peux l'adapter.
 
Je vous ai expliqué l'ensemble du projet que je fais à des fins personnelle et pour le club dans lequel je nage.
Il y a encore beaucoup de boulot néanmoins vous m'avez beaucoup aidé. Je vous en remercie.
Si vous avez d'autres questions, posez-les :)
 
Bonne journée à vous.

n°2218016
honrisse
Posté le 29-01-2014 à 13:25:51  profilanswer
 

jeremyl33240 a écrit :


Donc sur un autre PC il me faut une appli qui se connecte à la même BDD de l'autre PC et qui se chargera de mettre à jour la distance des nageurs à chaque longueur(piscine de 25m donc le pointage se fait sur un aller-retour). Le pointeur aura sur son IHM les 4 tables qui correspondront aux 4 lignes de la piscine. Pour chaque nageur actif dans telle ligne, un bouton lui sera consacré pour incrémenter sa distance de 50m. Le pointeur pourra voir en direct la distance du nageur chose que vous m'avez résolu hier. Il faut que quand un nageur commence ou s'arrête(fait par l'IHM principale) sa ligne correspondante dans l'une des 4 tables du pointage s'ajoute ou s'efface.
[/code]


 
Si j'ai bien compris :  

  • il faut que lorsqu'un nageur est ajouté par l'IHM principale l'IHM de pointage se mette à jour automatiquement sans avoir à relancer l'application
  • je ne suis pas du tout compétent en BDD, mais des techniques pour écouter/notifier des modifications dans une BDD doivent exister pour que l'IHM de pointage soit prévenue d'une modification dans la BDD
  • sinon, il faut se connecter toutes les 1s à la BDD pour mettre à jour l'affichage, possible en utilisant un thread (il y aura un décalage au pire cas de 1s dans le rafraichissement de l'IHM de pointage mais sans conséquence si le temps de départ est créé par l'IHM principale)
  • une autre solution, l'IHM principale envoie un message de signal par TCP/IP par exemple pour avertir l'IHM de pointage de se reconnecter à la BDD pour rafraichir les infos


Pour les actions des boutons, vu que le seul traitement au niveau IHM est de mettre à jour la distance il y a déjà un exemple dans le code, il faut juste vérifier que si l'on clique sur jbouton5 il y ait bien un nageur dans la ligne1 avec le bonnet 5 dans la BDD.
 
N'hésitez pas à poser des questions plus spécifiques sur de nouveaux topics sur ce forum ou ailleurs.
Un truc que je fais souvent, poser la question sur google avec des termes en anglais, les résultats sont beaucoup plus nombreux.
 
Bon courage pour votre projet.

n°2218022
jeremyl332​40
Posté le 29-01-2014 à 14:25:09  profilanswer
 

point numéro 1 : exactement.
numéro 2 : c'est possible, je vais me pencher dessus dès que possible.
numéro 3 : l'heure de départ est notifié dans la BDD lors du démarrage du nageur avec l'heure courante après je ne me suis pas encore penché là dessus.
numéro 4 : ça me parait être la meilleure solution pour éviter le nombre de recherches de mises à jour sur la BDD trop conséquent. Par contre, je n'ai jamais travaillé sur ce genre de solution, il va falloir que je vois aussi.
 
Pour ce que vous avez souligné juste après, j'ai remarqué qu'il y a des exceptions si on clic sur le bouton d'un nageur qui n'est pas dans la base donc oui il faudra rajouter cette exception sans que celle-ci ne gène trop le pointeur.
 
Depuis plusieurs semaines, je n'ai jamais autant fait de requêtes Google pour ce projet, que ce soit en français ou anglais :D
 
Merci encore pour votre aide et soutien :)

n°2219005
jeremyl332​40
Posté le 08-02-2014 à 22:15:02  profilanswer
 

Bonsoir.
Après avoir penché plusieurs jours sur ces sujets je n'ai pas trouvé grand chose de concret pour résoudre ce problème de mise à jour des lignes des jscrollpane après chaque clic :/
J'ai regardé les signaux tcp mais vraiment rien qui ne m'interpelle.

mood
Publicité
Posté le 08-02-2014 à 22:15:02  profilanswer
 

n°2219117
honrisse
Posté le 10-02-2014 à 13:10:12  profilanswer
 

jeremyl33240 a écrit :

Bonsoir.
Après avoir penché plusieurs jours sur ces sujets je n'ai pas trouvé grand chose de concret pour résoudre ce problème de mise à jour des lignes des jscrollpane après chaque clic :/
J'ai regardé les signaux tcp mais vraiment rien qui ne m'interpelle.


 
Pour moi, la méthode que je trouve la plus simple à implémenter et d'utiliser un thread (http://docs.oracle.com/javase/tuto [...] hread.html) qui va se connecter toutes les secondes pour rafraichir l'affichage.
Un exemple de l'emploi de thread (premier run()) : toutes les 500ms on affiche l'heure, SwingUtilities.InvokeLater permet d'appeler du code d'affichage à partir d'un autre thread que l'EDT (Event Dispatch Thread)

Code :
  1. import java.awt.Color;
  2. import java.awt.Font;
  3. import java.text.SimpleDateFormat;
  4. import java.util.Calendar;
  5. import java.util.concurrent.Executors;
  6. import java.util.concurrent.ScheduledExecutorService;
  7. import java.util.concurrent.TimeUnit;
  8. import javax.swing.JFrame;
  9. import javax.swing.JLabel;
  10. import javax.swing.JPanel;
  11. import javax.swing.SwingUtilities;
  12. public class Main {
  13. public static void createAndShowGui() {
  14.  JFrame f = new JFrame("Digital Clock" );
  15.  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  16.  final JLabel label = new JLabel("12h00:00" );
  17.  label.setFont(new Font("Serif", Font.BOLD, 60));
  18.  label.setOpaque(true);
  19.  label.setBackground(Color.BLACK);
  20.  label.setForeground(Color.GREEN);
  21.  JPanel panel = new JPanel();
  22.  panel.add(label);
  23.  f.add(panel);
  24.  ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
  25.  scheduler.scheduleAtFixedRate(new Runnable() {
  26.   @Override
  27.   public void run() {
  28.    SwingUtilities.invokeLater(new Runnable() {
  29.     @Override
  30.     public void run() {
  31.      SimpleDateFormat sdf = new SimpleDateFormat("HH'h'mm:ss" );
  32.      label.setText(sdf.format(Calendar.getInstance().getTime()));
  33.     }
  34.    });
  35.   }
  36.  }, 0, 500, TimeUnit.MILLISECONDS);
  37.  f.pack();
  38.  f.setLocationRelativeTo(null);
  39.  f.setVisible(true);
  40. }
  41. public static void main(String[] args) {
  42.  SwingUtilities.invokeLater(new Runnable() {
  43.   @Override
  44.   public void run() {
  45.    createAndShowGui();
  46.   }
  47.  });
  48. }
  49. }


 
Sinon avec TCP, je pensais à quelque chose comme une communication client/serveur, une seule direction, où lorsque le client reçoit un message du serveur (ou l'inverse pourquoi pas), le programme se reconnecte à la BDD pour rafraichir l'affichage.
 
Serveur (affiche ce que lui envoie le client, à la place se reconnecter à la BDD et rafraichir l'affichage ?) :

Code :
  1. import java.awt.Dimension;
  2. import java.awt.GridLayout;
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.net.ServerSocket;
  7. import java.net.Socket;
  8. import javax.swing.JFrame;
  9. import javax.swing.JPanel;
  10. import javax.swing.JScrollPane;
  11. import javax.swing.JTextArea;
  12. import javax.swing.SwingUtilities;
  13. /**
  14. *  
  15. * @see http://www.jmdoudoux.fr/java/dej/chap-net.htm
  16. *
  17. */
  18. public class ServerGui extends JFrame {
  19. private int port;
  20. private JTextArea textArea;
  21. private String message = "";
  22. public ServerGui(int port) {
  23.  super("Server Gui" );
  24.  this.port = port;
  25.  initComponents();
  26.  setMinimumSize(new Dimension(400, 300));
  27.  setLocationRelativeTo(null);
  28.  setVisible(true);
  29. }
  30. private void initComponents() {
  31.  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  32.  textArea = new JTextArea();
  33.  textArea.setEditable(false);
  34.  JScrollPane scrollPane = new JScrollPane(textArea);
  35.  JPanel panel = new JPanel(new GridLayout(0, 1));
  36.  panel.add(scrollPane);
  37.  add(panel);
  38.  Thread th = new Thread(new Runnable() {
  39.   @Override
  40.   public void run() {
  41.    ServerSocket socketServeur = null;
  42.    try {
  43.     socketServeur = new ServerSocket(port);
  44.     Socket socketClient = socketServeur.accept();
  45.     boolean exit = false;
  46.     while (!exit) {
  47.      BufferedReader in = new BufferedReader(new InputStreamReader(socketClient.getInputStream()));
  48.      message = in.readLine();
  49.      if(message != null) {
  50.       SwingUtilities.invokeLater(new Runnable() {
  51.        @Override
  52.        public void run() {
  53.         textArea.append("Server read from client : " + message + "\n" );
  54.        }
  55.       });
  56.      } else {
  57.       socketClient.close();
  58.       textArea.append("socketClient.close()\n" );
  59.       exit = true;
  60.      }
  61.     }
  62.    } catch (Exception e) {
  63.     e.printStackTrace();
  64.    } finally {
  65.     try {
  66.      if(socketServeur != null)
  67.       socketServeur.close();
  68.     } catch (IOException e) {
  69.      e.printStackTrace();
  70.     }
  71.    }
  72.   }
  73.  });
  74.  th.start();
  75. }
  76. public static void main(String[] args) {
  77.  new ServerGui(9632);
  78. }
  79. }


 
Client (ici envoie du texte lorsque l'on appuie sur le bouton, à la place envoie un message lorsqu'un nageur est ajouté ?) :

Code :
  1. import java.awt.Dimension;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import java.awt.event.WindowEvent;
  5. import java.awt.event.WindowListener;
  6. import java.io.IOException;
  7. import java.io.PrintStream;
  8. import java.net.Socket;
  9. import javax.swing.JButton;
  10. import javax.swing.JFrame;
  11. import javax.swing.JPanel;
  12. import javax.swing.JTextField;
  13. /**
  14. *  
  15. * @see http://www.jmdoudoux.fr/java/dej/chap-net.htm
  16. *
  17. */
  18. public class ClientGui extends JFrame {
  19. private int port;
  20. private String address;
  21. private JTextField textField;
  22. private Socket socket = null;
  23. public ClientGui(int port, String address) {
  24.  super("Client Gui" );
  25.  this.port = port;
  26.  this.address = address;
  27.  initComponents();
  28.  setMinimumSize(new Dimension(350, 80));
  29.  setLocationRelativeTo(null);
  30.  setVisible(true);
  31. }
  32. private void initComponents() {
  33.  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  34.  textField = new JTextField("Type here text to send to server", 20);
  35.  JButton button = new JButton("Send" );
  36.  try {
  37.   socket = new Socket(address, port);
  38.  } catch (Exception e) {
  39.   e.printStackTrace();
  40.  }
  41.  button.addActionListener(new ActionListener() {
  42.   @Override
  43.   public void actionPerformed(ActionEvent arg0) {
  44.    if(socket != null) {
  45.     try {
  46.      PrintStream out = new PrintStream(socket.getOutputStream());
  47.      out.println(textField.getText());
  48.     } catch (IOException e) {
  49.      e.printStackTrace();
  50.     }
  51.    }
  52.   }
  53.  });
  54.  addWindowListener(new WindowListener() {
  55.   @Override
  56.   public void windowClosing(WindowEvent arg0) {
  57.    if(socket != null) {
  58.     try {
  59.      socket.close();
  60.     } catch (IOException e) {
  61.      e.printStackTrace();
  62.     }
  63.    }
  64.   }
  65.   @Override
  66.   public void windowClosed(WindowEvent arg0) {
  67.   }
  68.   @Override
  69.   public void windowActivated(WindowEvent arg0) {
  70.   }
  71.   @Override
  72.   public void windowDeactivated(WindowEvent e) {
  73.   }
  74.   @Override
  75.   public void windowDeiconified(WindowEvent e) {
  76.   }
  77.   @Override
  78.   public void windowIconified(WindowEvent e) {
  79.   }
  80.   @Override
  81.   public void windowOpened(WindowEvent e) {
  82.   }
  83.  });
  84.  JPanel panel = new JPanel();
  85.  panel.add(textField);
  86.  panel.add(button);
  87.  add(panel);
  88. }
  89. public static void main(String[] args) {
  90.  new ClientGui(9632, "127.0.0.1" );
  91. }
  92. }


n°2219175
jeremyl332​40
Posté le 10-02-2014 à 17:29:30  profilanswer
 

Ah ouais ça va me modifier carrément tout ce que j'ai déjà fait cette histoire.
 
Ce matin je suis tombé sur ce code qui répond plus simplement à mes attentes. A votre avis il est possible de modifier le main pour qu'au lieu d'utiliser un timer, j'update se fasse sur le clic d'un des boutons?
 

Code :
  1. import java.sql.*;
  2. import java.util.*;
  3. import javax.swing.*;
  4. import javax.swing.table.*;
  5. public class UpdateJtable extends TimerTask {
  6.    
  7.     private static JTable table = new JTable();
  8.     private static Vector columnNames = new Vector();
  9.     private static Vector data = new Vector();
  10.     private static JFrame f = new JFrame();
  11.     private static JScrollPane scrollPane = new JScrollPane();
  12.    
  13. public static void main(String[] args) {
  14.     java.util.Timer timer = new java.util.Timer();
  15.     timer.schedule(new UpdateJtable(), 0, 3000);
  16. }
  17. public void run() {
  18.     remove();
  19.     table = draw();
  20.     scrollPane.getViewport().add(table, 0);
  21.     f.getContentPane().add(scrollPane);
  22.     f.setVisible(true);
  23.     f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  24.     f.pack();
  25. }
  26. public static JTable draw() {
  27.     try {
  28.         Class.forName("com.mysql.jdbc.Driver" ).newInstance();
  29.         Connection con = DriverManager.getConnection( "jdbc:mysql://192.168.1.12:3306/bdd_anl", "java", "anl" );
  30.         String sql = "SELECT bonnet, prenom, distance, id FROM Nageur WHERE actif='1' AND ligne='1' ORDER BY bonnet ASC;";
  31.         Statement stmt = con.createStatement();
  32.         ResultSet rs = stmt.executeQuery(sql);
  33.         ResultSetMetaData md = rs.getMetaData();
  34.         int columns = md.getColumnCount()+1;
  35.         for (int i = 1; i< columns; i++) {
  36.             columnNames.addElement(md.getColumnName(i));
  37.         }
  38.         while (rs.next()) {
  39.             Vector row = new Vector(columns);
  40.             for (int i = 1; i< columns; i++) {
  41.                 row.addElement(rs.getObject(i));
  42.             }
  43.             data.addElement(row);
  44.         }
  45.         rs.close();
  46.         stmt.close();
  47.         }
  48.     catch (Exception e) {
  49.         System.out.println(e);
  50.         e.printStackTrace();
  51.     }
  52.    
  53.     table.setModel(new DefaultTableModel(data, columnNames));
  54.     TableColumn col;
  55.     table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
  56.     for (int i = 0; i<table.getColumnCount(); i++) {
  57.         col = table.getColumnModel().getColumn(i);
  58.         col.setMaxWidth(col.getMaxWidth());
  59.     }
  60.     return table;
  61. }
  62. public static void remove() {
  63.     columnNames.clear();
  64.     if (table.getRowCount() != 0) {
  65.     DefaultTableModel dm = (DefaultTableModel) table.getModel();
  66.     dm.getDataVector().removeAllElements();
  67.     }
  68. }
  69. }

Message cité 1 fois
Message édité par jeremyl33240 le 10-02-2014 à 17:56:32
n°2219193
honrisse
Posté le 10-02-2014 à 20:50:33  profilanswer
 

jeremyl33240 a écrit :

A votre avis il est possible de modifier le main pour qu'au lieu d'utiliser un timer, j'update se fasse sur le clic d'un des boutons?


 
Oui c'est possible et c'est même plus simple je crois, un bouton pour mettre à jour une JTable même pas besoin de Timer.

n°2219195
jeremyl332​40
Posté le 10-02-2014 à 21:09:50  profilanswer
 

d'accord. Je pense même que ça permettra de passer outre la solution que vous m'aviez donné pour l'incrémentation de 50 à chaque clic. La si on update à chaque clic, l'incrémentation et l'affichage se fait grâce à la relecture de la base.
Demain je me penche là dessus en vous tenant au courant.
Merci :)

n°2219328
jeremyl332​40
Posté le 12-02-2014 à 07:57:31  profilanswer
 

C'est bien plus compliqué que je le pensais d'imbriquer toutes ces classes xD

n°2219477
jeremyl332​40
Posté le 13-02-2014 à 13:16:46  profilanswer
 

Bonjour.
 
A chaque essai pour embriquer les différents codes venant du rafraichissement et de la fenêtre, je me trouve en face d'ne problème
 
 GroupLayout layout = new GroupLayout(getContentPane());
 getContentPane().setLayout(layout);
 
dans lequel netbeans ne connait pas getContentPane() alors que tout le reste est bon.
 
Avez-vous des idées?
 
Merci

n°2219587
honrisse
Posté le 13-02-2014 à 19:51:58  profilanswer
 

jeremyl33240 a écrit :

Bonjour.
 
A chaque essai pour embriquer les différents codes venant du rafraichissement et de la fenêtre, je me trouve en face d'ne problème
 
 GroupLayout layout = new GroupLayout(getContentPane());
 getContentPane().setLayout(layout);
 
dans lequel netbeans ne connait pas getContentPane() alors que tout le reste est bon.
 
Avez-vous des idées?
 
Merci


 
Bonjour,
La méthode qui appelle GetContentPane() appartient bien à une classe qui étend de JFrame ?

n°2219633
jeremyl332​40
Posté le 14-02-2014 à 11:38:07  profilanswer
 

En fait la méthode initComponents était en static alors qu'il ne fallait pas mais maintenant ça me bloque dans l'actionperformed quand j'appelle initComponents qui n'est pas static...
 
J'ai revu encore ce matin mais je pense que je mélange tout car pour le lancement, ça ne me semble pas bon du tout.
Voilà le fouilli comme pourrait dire certain :
 
UpdateJtable

Code :
  1. import java.sql.*;
  2. import java.util.*;
  3. import javax.swing.*;
  4. import javax.swing.table.*;
  5. public class UpdateJtable  {
  6.    
  7.     public static JTable table1 = new JTable();
  8.     public static JTable table2 = new JTable();
  9.     public static JTable table3 = new JTable();
  10.     public static JTable table4 = new JTable();
  11.     private static Vector columnNames1 = new Vector();
  12.     private static Vector columnNames2 = new Vector();
  13.     private static Vector columnNames3 = new Vector();
  14.     private static Vector columnNames4 = new Vector();
  15.     private static Vector data1 = new Vector();
  16.     private static Vector data2 = new Vector();
  17.     private static Vector data3 = new Vector();
  18.     private static Vector data4 = new Vector();
  19.     private static JScrollPane scrollPane1 = new JScrollPane();
  20.     private static JScrollPane scrollPane2 = new JScrollPane();
  21.     private static JFrame f = new JFrame();
  22. public static JTable draw1() {
  23.     try {
  24.         Statement state = Connexion.getInstance().createStatement();
  25.         String sql = "SELECT bonnet, prenom, distance, id FROM Nageur WHERE actif='1' AND ligne='1' ORDER BY bonnet ASC;";
  26.         ResultSet rs = state.executeQuery(sql);
  27.         ResultSetMetaData md = rs.getMetaData();
  28.         int columns = md.getColumnCount()+1;
  29.         for (int i = 1; i< columns; i++) {
  30.             columnNames1.addElement(md.getColumnName(i));
  31.         }
  32.         while (rs.next()) {
  33.             Vector row = new Vector(columns);
  34.             for (int i = 1; i< columns; i++) {
  35.                 row.addElement(rs.getObject(i));
  36.             }
  37.             data1.addElement(row);
  38.         }
  39.         rs.close();
  40.         state.close();
  41.         }
  42.     catch (Exception e) {
  43.         System.out.println(e);
  44.         e.printStackTrace();
  45.     }
  46.    
  47.     table1.setModel(new DefaultTableModel(data1, columnNames1));
  48.     TableColumn col;
  49.     table1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
  50.     for (int i = 0; i<table1.getColumnCount(); i++) {
  51.         col = table1.getColumnModel().getColumn(i);
  52.         col.setMaxWidth(col.getMaxWidth());
  53.     }
  54.     return table1;
  55. }
  56. public static JTable draw2() {
  57.     try {
  58.         Statement state = Connexion.getInstance().createStatement();
  59.         String sql = "SELECT bonnet, prenom, distance, id FROM Nageur WHERE actif='1' AND ligne='2' ORDER BY bonnet ASC;";
  60.         ResultSet rs = state.executeQuery(sql);
  61.         ResultSetMetaData md = rs.getMetaData();
  62.         int columns = md.getColumnCount()+1;
  63.         for (int i = 1; i< columns; i++) {
  64.             columnNames2.addElement(md.getColumnName(i));
  65.         }
  66.         while (rs.next()) {
  67.             Vector row = new Vector(columns);
  68.             for (int i = 1; i< columns; i++) {
  69.                 row.addElement(rs.getObject(i));
  70.             }
  71.             data2.addElement(row);
  72.         }
  73.         rs.close();
  74.         state.close();
  75.         }
  76.     catch (Exception e) {
  77.         System.out.println(e);
  78.         e.printStackTrace();
  79.     }
  80.    
  81.     table2.setModel(new DefaultTableModel(data2, columnNames2));
  82.     TableColumn col;
  83.     table2.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
  84.     for (int i = 0; i<table2.getColumnCount(); i++) {
  85.         col = table2.getColumnModel().getColumn(i);
  86.         col.setMaxWidth(col.getMaxWidth());
  87.     }
  88.     return table2;
  89. }
  90. public static JTable draw3() {
  91.     try {
  92.         Statement state = Connexion.getInstance().createStatement();
  93.         String sql = "SELECT bonnet, prenom, distance, id FROM Nageur WHERE actif='1' AND ligne='3' ORDER BY bonnet ASC;";
  94.         ResultSet rs = state.executeQuery(sql);
  95.         ResultSetMetaData md = rs.getMetaData();
  96.         int columns = md.getColumnCount()+1;
  97.         for (int i = 1; i< columns; i++) {
  98.             columnNames3.addElement(md.getColumnName(i));
  99.         }
  100.         while (rs.next()) {
  101.             Vector row = new Vector(columns);
  102.             for (int i = 1; i< columns; i++) {
  103.                 row.addElement(rs.getObject(i));
  104.             }
  105.             data3.addElement(row);
  106.         }
  107.         rs.close();
  108.         state.close();
  109.         }
  110.     catch (Exception e) {
  111.         System.out.println(e);
  112.         e.printStackTrace();
  113.     }
  114.    
  115.     table3.setModel(new DefaultTableModel(data3, columnNames3));
  116.     TableColumn col;
  117.     table3.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
  118.     for (int i = 0; i<table3.getColumnCount(); i++) {
  119.         col = table3.getColumnModel().getColumn(i);
  120.         col.setMaxWidth(col.getMaxWidth());
  121.     }
  122.     return table3;
  123. }
  124. public static JTable draw4() {
  125.     try {
  126.         Statement state = Connexion.getInstance().createStatement();
  127.         String sql = "SELECT bonnet, prenom, distance, id FROM Nageur WHERE actif='1' AND ligne='4' ORDER BY bonnet ASC;";
  128.         ResultSet rs = state.executeQuery(sql);
  129.         ResultSetMetaData md = rs.getMetaData();
  130.         int columns = md.getColumnCount()+1;
  131.         for (int i = 1; i< columns; i++) {
  132.             columnNames4.addElement(md.getColumnName(i));
  133.         }
  134.         while (rs.next()) {
  135.             Vector row = new Vector(columns);
  136.             for (int i = 1; i< columns; i++) {
  137.                 row.addElement(rs.getObject(i));
  138.             }
  139.             data4.addElement(row);
  140.         }
  141.         rs.close();
  142.         state.close();
  143.         }
  144.     catch (Exception e) {
  145.         System.out.println(e);
  146.         e.printStackTrace();
  147.     }
  148.    
  149.     table4.setModel(new DefaultTableModel(data4, columnNames4));
  150.     TableColumn col;
  151.     table4.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
  152.     for (int i = 0; i<table4.getColumnCount(); i++) {
  153.         col = table4.getColumnModel().getColumn(i);
  154.         col.setMaxWidth(col.getMaxWidth());
  155.     }
  156.     return table4;
  157. }
  158. public static void remove() {
  159.     columnNames1.clear();
  160.     columnNames2.clear();
  161.     columnNames3.clear();
  162.     columnNames4.clear();
  163.     if (table1.getRowCount() != 0) {
  164.     DefaultTableModel dm = (DefaultTableModel) table1.getModel();
  165.     dm.getDataVector().removeAllElements();
  166.     }
  167.     if (table2.getRowCount() != 0) {
  168.     DefaultTableModel dm = (DefaultTableModel) table2.getModel();
  169.     dm.getDataVector().removeAllElements();
  170.     }
  171.     if (table3.getRowCount() != 0) {
  172.     DefaultTableModel dm = (DefaultTableModel) table3.getModel();
  173.     dm.getDataVector().removeAllElements();
  174.     }
  175.     if (table4.getRowCount() != 0) {
  176.     DefaultTableModel dm = (DefaultTableModel) table4.getModel();
  177.     dm.getDataVector().removeAllElements();
  178.     }
  179. }
  180. }


 
Ensuite FenPointage avec beaucoup de blabla que j'efface pour ne blesser les yeux à personne

Code :
  1. import javax.swing.JButton;
  2. import javax.swing.JLabel;
  3. import javax.swing.JScrollPane;
  4. import javax.swing.JTable;
  5. import javax.swing.GroupLayout;
  6. import static javax.swing.JFrame.EXIT_ON_CLOSE;
  7. import javax.swing.LayoutStyle;
  8. public class FenPointage extends javax.swing.JFrame {
  9.    
  10.     public static JButton jButton1,jButton2,jButton3,jButton4,jButton5,jButton6,jButton7;
  11.     public static JButton jButton11,jButton12,jButton13,jButton14,jButton15,jButton16,jButton17;
  12.     public static JButton jButton21,jButton22,jButton23,jButton24,jButton25,jButton26,jButton27;
  13.     public static JButton jButton31,jButton32,jButton33,jButton34,jButton35,jButton36,jButton37;
  14.     public static JLabel jLabel1,jLabel2,jLabel3,jLabel4,jLabel5,jLabel6,jLabel7,jLabel8;
  15.    
  16.     public static JScrollPane jScrollPane1,jScrollPane2,jScrollPane3,jScrollPane4;
  17.    
  18.     public static JTable jTable1,jTable2,jTable3,jTable4;
  19.     public FenPointage() {
  20.         setSize(750, 465);
  21.         setTitle("Pointage des nageurs" );
  22.         setLocationRelativeTo(null);
  23.         setDefaultCloseOperation(EXIT_ON_CLOSE);       
  24.     }
  25.                        
  26.     public void initComponents() {
  27.         jScrollPane1 = new JScrollPane();
  28.         jScrollPane2 = new JScrollPane();
  29.         jScrollPane3 = new JScrollPane();
  30.         jScrollPane4 = new JScrollPane();
  31.        
  32.         jTable1 = new JTable();
  33.         jTable2 = new JTable();
  34.         jTable3 = new JTable();
  35.         jTable4 = new JTable();
  36.         jLabel1 = new JLabel();
  37.         jLabel2 = new JLabel();
  38.         jLabel3 = new JLabel();
  39.         jLabel4 = new JLabel();
  40.         jLabel5 = new JLabel();
  41.         jLabel6 = new JLabel();
  42.         jLabel7 = new JLabel();
  43.         jLabel8 = new JLabel();
  44.        
  45.         jButton1 = new JButton();
  46.         jButton2 = new JButton();
  47.         jButton3 = new JButton();
  48.         jButton4 = new JButton();
  49.         jButton5 = new JButton();
  50.         jButton6 = new JButton();
  51.         jButton7 = new JButton();
  52.        
  53.         jButton11 = new JButton();
  54.         jButton12 = new JButton();
  55.         jButton13 = new JButton();
  56.         jButton14 = new JButton();
  57.         jButton15 = new JButton();
  58.         jButton16 = new JButton();
  59.         jButton17 = new JButton();
  60.        
  61.         jButton21 = new JButton();
  62.         jButton22 = new JButton();
  63.         jButton23 = new JButton();
  64.         jButton24 = new JButton();
  65.         jButton25 = new JButton();
  66.         jButton26 = new JButton();
  67.         jButton27 = new JButton();
  68.        
  69.         jButton31 = new JButton();
  70.         jButton32 = new JButton();
  71.         jButton33 = new JButton();
  72.         jButton34 = new JButton();
  73.         jButton35 = new JButton();
  74.         jButton36 = new JButton();
  75.         jButton37 = new JButton();
  76.        
  77.         ModifBoutons modif = new ModifBoutons(this);
  78.         jButton1.addActionListener(modif);
  79.         jButton2.addActionListener(modif);
  80.         jButton3.addActionListener(modif);
  81.         jButton4.addActionListener(modif);
  82.         jButton5.addActionListener(modif);
  83.         jButton6.addActionListener(modif);
  84.         jButton7.addActionListener(modif);
  85.        
  86.         jButton11.addActionListener(modif);
  87.         jButton12.addActionListener(modif);
  88.         jButton13.addActionListener(modif);
  89.         jButton14.addActionListener(modif);
  90.         jButton15.addActionListener(modif);
  91.         jButton16.addActionListener(modif);
  92.         jButton17.addActionListener(modif);
  93.        
  94.         jButton21.addActionListener(modif);
  95.         jButton22.addActionListener(modif);
  96.         jButton23.addActionListener(modif);
  97.         jButton24.addActionListener(modif);
  98.         jButton25.addActionListener(modif);
  99.         jButton25.addActionListener(modif);
  100.         jButton26.addActionListener(modif);
  101.         jButton27.addActionListener(modif);
  102.        
  103.         jButton31.addActionListener(modif);
  104.         jButton32.addActionListener(modif);
  105.         jButton33.addActionListener(modif);
  106.         jButton34.addActionListener(modif);
  107.         jButton35.addActionListener(modif);
  108.         jButton36.addActionListener(modif);
  109.         jButton37.addActionListener(modif);
  110.         jTable1.setModel(new javax.swing.table.DefaultTableModel(Pointage.getdata1(),Pointage.getcolumn1()));     
  111.         jScrollPane1.setViewportView(jTable1);
  112.        
  113.         jTable2.setModel(new javax.swing.table.DefaultTableModel(Pointage.getdata2(),Pointage.getcolumn2()));     
  114.         jScrollPane2.setViewportView(jTable2);
  115.         jTable3.setModel(new javax.swing.table.DefaultTableModel(Pointage.getdata3(),Pointage.getcolumn3()));     
  116.         jScrollPane3.setViewportView(jTable3);
  117.         jTable4.setModel(new javax.swing.table.DefaultTableModel(Pointage.getdata4(),Pointage.getcolumn4()));     
  118.         jScrollPane4.setViewportView(jTable4);
  119.         jButton1.setText("1" );
  120.         jButton1.setName("jButton1" );
  121.         jButton2.setText("2" );
  122.         jButton2.setName("jButton2" );
  123.         jButton3.setText("3" );
  124.         jButton3.setName("jButton3" );
  125.         jButton4.setText("4" );
  126.         jButton4.setName("jButton4" );
  127.         jButton5.setText("5" );
  128.         jButton5.setName("jButton5" );
  129.         jButton6.setText("6" );
  130.         jButton6.setName("jButton6" );
  131.         jButton7.setText("7" );
  132.         jButton7.setName("jButton7" );
  133.        
  134.         jButton11.setText("1" );
  135.         jButton11.setName("jButton11" );
  136.         jButton12.setText("2" );
  137.         jButton12.setName("jButton12" );
  138.         jButton13.setText("3" );
  139.         jButton13.setName("jButton13" );
  140.         jButton14.setText("4" );
  141.         jButton14.setName("jButton14" );
  142.         jButton15.setText("5" );
  143.         jButton15.setName("jButton15" );
  144.         jButton16.setText("6" );
  145.         jButton16.setName("jButton16" );
  146.         jButton17.setText("7" );
  147.         jButton17.setName("jButton17" );
  148.        
  149.         jButton21.setText("1" );
  150.         jButton21.setName("jButton21" );
  151.         jButton22.setText("2" );
  152.         jButton22.setName("jButton22" );
  153.         jButton23.setText("3" );
  154.         jButton23.setName("jButton23" );
  155.         jButton24.setText("4" );
  156.         jButton24.setName("jButton24" );
  157.         jButton25.setText("5" );
  158.         jButton25.setName("jButton25" );
  159.         jButton26.setText("6" );
  160.         jButton26.setName("jButton26" );
  161.         jButton27.setText("7" );
  162.         jButton27.setName("jButton27" );
  163.        
  164.         jButton31.setText("1" );
  165.         jButton31.setName("jButton31" );
  166.         jButton32.setText("2" );
  167.         jButton32.setName("jButton32" );
  168.         jButton33.setText("3" );
  169.         jButton33.setName("jButton33" );
  170.         jButton34.setText("4" );
  171.         jButton34.setName("jButton34" );
  172.         jButton35.setText("5" );
  173.         jButton35.setName("jButton35" );
  174.         jButton36.setText("6" );
  175.         jButton36.setName("jButton36" );
  176.         jButton37.setText("7" );
  177.         jButton37.setName("jButton37" );
  178.        
  179.         jLabel1.setText("Ligne 1" );
  180.         jLabel2.setText("Ligne 2" );
  181.         jLabel3.setText("Ligne 3" );
  182.         jLabel4.setText("Ligne 4" );
  183.         jLabel5.setText("bonnet" );
  184.         jLabel6.setText("bonnet" );
  185.         jLabel7.setText("bonnet" );
  186.         jLabel8.setText("bonnet" );
  187.        //le blabla sur la position des composant est ici
  188.         }
  189. }


 
Ensuite la ModifBoutons  

Code :
  1. import java.awt.event.ActionListener;
  2. import java.awt.event.ActionEvent;
  3. import java.sql.*;
  4. import javax.swing.JButton;
  5. import javax.swing.JFrame;
  6. public class ModifBoutons implements ActionListener {
  7.    
  8.     private FenPointage fen;
  9.    
  10.     public ModifBoutons(FenPointage fp) {
  11.     fen = fp;
  12.     }
  13.    
  14. public void actionPerformed(ActionEvent événement) {
  15.    
  16.     UpdateJtable.remove();
  17.     FenPointage.jTable1 = UpdateJtable.draw1();
  18.     FenPointage.jTable2 = UpdateJtable.draw2();
  19.     FenPointage.jTable3 = UpdateJtable.draw3();
  20.     FenPointage.jTable4 = UpdateJtable.draw4();
  21.     FenPointage.jScrollPane1.getViewport().add(UpdateJtable.table1, 0);
  22.     FenPointage.jScrollPane2.getViewport().add(UpdateJtable.table2, 0);
  23.     FenPointage.jScrollPane3.getViewport().add(UpdateJtable.table3, 0);
  24.     FenPointage.jScrollPane4.getViewport().add(UpdateJtable.table4, 0);
  25.     FenPointage.initComponents();
  26.     UpdateJtable.setVisible(true);
  27.    
  28. Pointage p = new Pointage();
  29. String ligne = "0";
  30. String bonnet;
  31. String nomboutonclique;
  32. String updist;
  33. String uptemps;
  34. String upvitesse;
  35. nomboutonclique = ((JButton) événement.getSource()).getName();
  36. System.out.println("nom du bouton : " + nomboutonclique);
  37. if (nomboutonclique == "jButton1"
  38.    || nomboutonclique == "jButton2"
  39.    || nomboutonclique == "jButton3"
  40.    || nomboutonclique == "jButton4"
  41.    || nomboutonclique == "jButton5"
  42.    || nomboutonclique == "jButton6"
  43.    || nomboutonclique == "jButton7" ) {
  44.  ligne = "1";
  45. }
  46. if (nomboutonclique == "jButton11"
  47.    || nomboutonclique == "jButton12"
  48.    || nomboutonclique == "jButton13"
  49.    || nomboutonclique == "jButton14"
  50.    || nomboutonclique == "jButton15"
  51.    || nomboutonclique == "jButton16"
  52.    || nomboutonclique == "jButton17" ) {
  53.  ligne = "2";
  54. }
  55. if (nomboutonclique == "jButton21"
  56.    || nomboutonclique == "jButton22"
  57.    || nomboutonclique == "jButton23"
  58.    || nomboutonclique == "jButton24"
  59.    || nomboutonclique == "jButton25"
  60.    || nomboutonclique == "jButton26"
  61.    || nomboutonclique == "jButton27" ) {
  62.  ligne = "3";
  63. }
  64. if (nomboutonclique == "jButton31"
  65.    || nomboutonclique == "jButton32"
  66.    || nomboutonclique == "jButton33"
  67.    || nomboutonclique == "jButton34"
  68.    || nomboutonclique == "jButton35"
  69.    || nomboutonclique == "jButton36"
  70.    || nomboutonclique == "jButton37" ) {
  71.  ligne = "4";
  72. }
  73. JButton titreboutonclique = (JButton) événement.getSource();
  74. bonnet = titreboutonclique.getText();
  75. System.out.println("numéro du ligne : " + ligne);
  76. System.out.println("numéro du bonnet : " + bonnet);
  77. updist = "UPDATE Nageur SET distance = distance+50 WHERE actif='1' AND ligne = '"
  78.           + ligne + "' AND bonnet = '" + bonnet + "';";
  79. uptemps = "UPDATE Nageur SET temps = timediff(current_time,heure_depart) WHERE actif='1' AND  ligne = '"
  80.           + ligne + "' AND bonnet = '" + bonnet + "';";
  81. upvitesse = "UPDATE Nageur SET vitesse = distance*3.6/TIME_TO_SEC(temps) WHERE actif='1' AND ligne = '"
  82.           + ligne + "' AND bonnet = '" + bonnet + "';";
  83. System.out.println(updist);
  84. System.out.println(uptemps);
  85. System.out.println(upvitesse);
  86. try {
  87.    Statement state = Connexion.getInstance().createStatement();
  88.    int updatedist = state.executeUpdate(updist);
  89.         System.out.println("distance : " + updatedist);
  90.    int updatetemps = state.executeUpdate(uptemps);
  91.         System.out.println("temps : " + updatetemps);
  92.    int updatevitesse = state.executeUpdate(upvitesse);
  93.         System.out.println("vitesse : " + updatevitesse);
  94.    state.close();
  95.   } catch (SQLException e) {}
  96. switch(ligne) {
  97. case "1" :
  98.      for (int i=1;i<8;i++){
  99.  if(Integer.parseInt(bonnet)==i) {
  100.    int val = (int) p.data1[i-1][2];
  101.    p.data1[i-1][2] = val + 50;
  102.    fen.jTable1.getModel().setValueAt(p.data1[i-1][2], i-1, 2);
  103.  }}
  104.  break;
  105. case "2" :
  106.     for (int i=1;i<8;i++){
  107.  if(Integer.parseInt(bonnet)==i) {
  108.    int val = (int) p.data2[i-1][2];
  109.    p.data2[i-1][2] = val + 50;
  110.    fen.jTable2.getModel().setValueAt(p.data2[i-1][2], i-1, 2);
  111.  }}
  112.  break;
  113. case "3" :
  114.     for (int i=1;i<8;i++){
  115.  if(Integer.parseInt(bonnet)==i) {
  116.    int val = (int) p.data3[i-1][2];
  117.    p.data3[i-1][2] = val + 50;
  118.    fen.jTable3.getModel().setValueAt(p.data3[i-1][2], i-1, 2);
  119.  }}
  120.  break;
  121. case "4" :
  122.     for (int i=1;i<8;i++){
  123.  if(Integer.parseInt(bonnet)==i) {
  124.    int val = (int) p.data4[i-1][2];
  125.    p.data4[i-1][2] = val + 50;
  126.    fen.jTable4.getModel().setValueAt(p.data4[i-1][2], i-1, 2);
  127.  }}
  128.  break;
  129. default :
  130.  break;
  131. }
  132. }
  133. }


 
Enfin Pointage

Code :
  1. import java.sql.*;
  2. public class Pointage {
  3.    
  4. public FenPointage fen;
  5. /*String l1 = "SELECT bonnet, prenom, distance, id FROM Nageur WHERE actif='1' AND ligne='1' ORDER BY bonnet ASC;";
  6. String l2 = "SELECT bonnet, prenom, distance, id FROM Nageur WHERE actif='1' AND ligne='2' ORDER BY bonnet ASC;";
  7. String l3 = "SELECT bonnet, prenom, distance, id FROM Nageur WHERE actif='1' AND ligne='3' ORDER BY bonnet ASC;";
  8. String l4 = "SELECT bonnet, prenom, distance, id FROM Nageur WHERE actif='1' AND ligne='4' ORDER BY bonnet ASC;";
  9. */
  10. public static Object[] column1;
  11. public static Object[] column2;
  12. public static Object[] column3;
  13. public static Object[] column4;
  14. public static Object[][] data1;
  15. public static Object[][] data2;
  16. public static Object[][] data3;
  17. public static Object[][] data4;
  18. public static void main(String[] args) {
  19. Pointage point = new Pointage();
  20. }
  21. public Pointage() {
  22. fen = new FenPointage();
  23. }
  24. /////////////////////////////////////////////////////////////////////////////
  25. public static Object[][] getdata1() {
  26. return data1;
  27. };
  28. public static Object[][] getdata2() {
  29. return data2;
  30. };
  31. public static Object[][] getdata3() {
  32. return data3;
  33. };
  34. public static Object[][] getdata4() {
  35. return data4;
  36. };
  37. // //////////////////////////////////////////////////////////////////////////
  38. public static Object[] getcolumn1() {
  39. return column1;
  40. };
  41. public static Object[] getcolumn2() {
  42. return column2;
  43. };
  44. public static Object[] getcolumn3() {
  45. return column3;
  46. };
  47. public static Object[] getcolumn4() {
  48. return column4;
  49. };
  50. // //////////////////////////////////////////////////////////////////////////
  51. public static void setdata1(Object dat[][]) {
  52. data1 = dat;
  53. };
  54. public static void setdata2(Object dat[][]) {
  55. data2 = dat;
  56. };
  57. public static void setdata3(Object dat[][]) {
  58. data3 = dat;
  59. };
  60. public static void setdata4(Object dat[][]) {
  61. data4 = dat;
  62. };
  63. // //////////////////////////////////////////////////////////////////////////
  64. public static void setcolumn1(Object col[]) {
  65. column1 = col;
  66. };
  67. public static void setcolumn2(Object col[]) {
  68. column2 = col;
  69. };
  70. public static void setcolumn3(Object col[]) {
  71. column3 = col;
  72. };
  73. public static void setcolumn4(Object col[]) {
  74. column4 = col;
  75. };
  76. public void stop() {
  77. fen.setVisible(false);
  78. }
  79. }


 
Vraiment désolé si ça vous fait pitier de voir ça.
 
Merci

n°2219774
honrisse
Posté le 15-02-2014 à 18:31:46  profilanswer
 

Pour ne plus avoir d'erreur, il faut utiliser l'attribut fen de la classe ModifBoutons :

Code :
  1. fen.initComponents();
  2.  fen.setVisible(true);


 
Je n'aurais pas utilisé autant le mot clé static (voir ce lien pour plus d'infos sur static : http://java.developpez.com/faq/jav [...] ClesStatic), pour moi seul Connexion est static.
J'utilise static la plupart du temps pour des méthodes où il n'y a pas nécessité qu'une instance soit créée :

Code :
  1. public class Functions {
  2.     // absolute value of an int value
  3.     public static int abs(int x) {
  4.         if (x < 0) return -x;
  5.         else       return  x;
  6.     }
  7. }


Ici, on peut directement faire :

Code :
  1. System.out.println(Functions.abs(67));


Sans static :

Code :
  1. Functions f = new Functions();
  2.  System.out.println(f.abs(67));


 
 
Pour avoir accès aux différentes méthodes il suffit de le passer en paramètre du constructeur comme ici :

Code :
  1. public class ModifBoutons implements ActionListener {
  2.  
  3.     private FenPointage fen;
  4.  
  5.     public ModifBoutons(FenPointage fp) {
  6.     fen = fp;
  7.     }


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  rafraichissement jscrollpane

 

Sujets relatifs
Probleme de JScrollPane avec JTextAreaProbleme rafraichissement
[ACCESS] Rafraichissement tables liés avec requêtes[JAVA-JEE]rafraichissement page JEE
[AJAX] Pb de rafraichissement de calquesProblème rafraichissement JLabel
[RESOLU] Rafraichissement d'une barre d'étatProblème avec le rafraichissement d'une page
Problème rafraichissement JTableprobleme de rafraichissement d'un JPanel
Plus de sujets relatifs à : rafraichissement jscrollpane


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR