honrisse | 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 :
- package pointage;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import javax.swing.JOptionPane;
- public class Connexion{
- private static String url = "jdbc:mysql://localhost:3306/bdd_anl";
- private static String user = "java";
- private static String passwd = "anl";
- private static Connection connect;
- public static Connection getInstance(){
- if(connect == null){
- try {
- connect = DriverManager.getConnection(url, user, passwd);
- System.out.println("connexion etablie" );
- } catch (SQLException e) {
- JOptionPane.showMessageDialog(null, e.getMessage(), "ERREUR DE CONNEXION ! ", JOptionPane.ERROR_MESSAGE);
- }
- }
- return connect;
- }
- }
|
FenPointage
Code :
- package pointage;
- import javax.swing.JButton;
- import javax.swing.JLabel;
- import javax.swing.JScrollPane;
- import javax.swing.JTable;
- import javax.swing.GroupLayout;
- import javax.swing.LayoutStyle;
- public class FenPointage extends javax.swing.JFrame {
-
- public JButton jButton1;
- public JButton jButton2;
- public JButton jButton3;
- public JButton jButton4;
- public JButton jButton5;
- public JButton jButton6;
- public JButton jButton7;
- public JButton jButton8;
- public JButton jButton9;
- public JButton jButton10;
- public JButton jButton11;
- public JButton jButton12;
- public JButton jButton13;
- public JButton jButton14;
- public JButton jButton15;
- public JButton jButton16;
- public JButton jButton17;
- public JButton jButton18;
- public JButton jButton19;
- public JButton jButton20;
- public JButton jButton21;
- public JButton jButton22;
- public JButton jButton23;
- public JButton jButton24;
- public JButton jButton25;
- public JButton jButton26;
- public JButton jButton27;
- public JButton jButton28;
- public JButton jButton29;
- public JButton jButton30;
- public JButton jButton31;
- public JButton jButton32;
- public JButton jButton33;
- public JButton jButton34;
- public JButton jButton35;
- public JButton jButton36;
- public JButton jButton37;
- public JButton jButton38;
- public JButton jButton39;
- public JButton jButton40;
- private JLabel jLabel1;
- private JLabel jLabel2;
- private JLabel jLabel3;
- private JLabel jLabel4;
- private JLabel jLabel5;
- private JLabel jLabel6;
- private JLabel jLabel7;
- private JLabel jLabel8;
- private JScrollPane jScrollPane1;
- private JScrollPane jScrollPane2;
- private JScrollPane jScrollPane3;
- private JScrollPane jScrollPane4;
- private JTable jTable1;
- private JTable jTable2;
- private JTable jTable3;
- private JTable jTable4;
- public FenPointage() {
- setSize(650, 600);
- setTitle("Pointage des nageurs" );
- setLocationRelativeTo(null);
- setDefaultCloseOperation(EXIT_ON_CLOSE);
-
- }
-
- public void initComponents() {
- jScrollPane1 = new JScrollPane();
- jScrollPane2 = new JScrollPane();
- jScrollPane3 = new JScrollPane();
- jScrollPane4 = new JScrollPane();
- jTable1 = new JTable();
- jTable2 = new JTable();
- jTable3 = new JTable();
- jTable4 = new JTable();
- jLabel1 = new JLabel();
- jLabel2 = new JLabel();
- jLabel3 = new JLabel();
- jLabel4 = new JLabel();
- jLabel5 = new JLabel();
- jLabel6 = new JLabel();
- jLabel7 = new JLabel();
- jLabel8 = new JLabel();
- jButton1 = new JButton();
- jButton2 = new JButton();
- jButton3 = new JButton();
- jButton4 = new JButton();
- jButton5 = new JButton();
- jButton6 = new JButton();
- jButton7 = new JButton();
- jButton8 = new JButton();
- jButton9 = new JButton();
- jButton10 = new JButton();
- jButton11 = new JButton();
- jButton12 = new JButton();
- jButton13 = new JButton();
- jButton14 = new JButton();
- jButton15 = new JButton();
- jButton16 = new JButton();
- jButton17 = new JButton();
- jButton18 = new JButton();
- jButton19 = new JButton();
- jButton20 = new JButton();
- jButton21 = new JButton();
- jButton22 = new JButton();
- jButton23 = new JButton();
- jButton24 = new JButton();
- jButton25 = new JButton();
- jButton26 = new JButton();
- jButton27 = new JButton();
- jButton28 = new JButton();
- jButton29 = new JButton();
- jButton30 = new JButton();
- jButton31 = new JButton();
- jButton32 = new JButton();
- jButton33 = new JButton();
- jButton34 = new JButton();
- jButton35 = new JButton();
- jButton36 = new JButton();
- jButton37 = new JButton();
- jButton38 = new JButton();
- jButton39 = new JButton();
- jButton40 = new JButton();
-
- ModifBoutons modif = new ModifBoutons();
- jButton1.addActionListener(modif);
- jButton2.addActionListener(modif);
- jButton3.addActionListener(modif);
- jButton4.addActionListener(modif);
- jButton5.addActionListener(modif);
- jButton6.addActionListener(modif);
- jButton7.addActionListener(modif);
- jButton8.addActionListener(modif);
- jButton9.addActionListener(modif);
- jButton10.addActionListener(modif);
- jButton11.addActionListener(modif);
- jButton12.addActionListener(modif);
- jButton13.addActionListener(modif);
- jButton14.addActionListener(modif);
- jButton15.addActionListener(modif);
- jButton16.addActionListener(modif);
- jButton17.addActionListener(modif);
- jButton18.addActionListener(modif);
- jButton19.addActionListener(modif);
- jButton20.addActionListener(modif);
- jButton21.addActionListener(modif);
- jButton22.addActionListener(modif);
- jButton23.addActionListener(modif);
- jButton24.addActionListener(modif);
- jButton25.addActionListener(modif);
- jButton25.addActionListener(modif);
- jButton26.addActionListener(modif);
- jButton27.addActionListener(modif);
- jButton28.addActionListener(modif);
- jButton29.addActionListener(modif);
- jButton30.addActionListener(modif);
- jButton31.addActionListener(modif);
- jButton32.addActionListener(modif);
- jButton33.addActionListener(modif);
- jButton34.addActionListener(modif);
- jButton35.addActionListener(modif);
- jButton36.addActionListener(modif);
- jButton37.addActionListener(modif);
- jButton38.addActionListener(modif);
- jButton39.addActionListener(modif);
- jButton40.addActionListener(modif);
-
- jTable1.setModel(new javax.swing.table.DefaultTableModel(Pointage.getdata1(),Pointage.getcolumn1()));
- jScrollPane1.setViewportView(jTable1);
- jTable2.setModel(new javax.swing.table.DefaultTableModel(Pointage.getdata2(),Pointage.getcolumn2()));
- jScrollPane2.setViewportView(jTable2);
- jTable3.setModel(new javax.swing.table.DefaultTableModel(Pointage.getdata3(),Pointage.getcolumn3()));
- jScrollPane3.setViewportView(jTable3);
- jTable4.setModel(new javax.swing.table.DefaultTableModel(Pointage.getdata4(),Pointage.getcolumn4()));
- jScrollPane4.setViewportView(jTable4);
- jButton1.setText("1" );
- jButton1.setName("jButton1" );
- jButton2.setText("2" );
- jButton2.setName("jButton2" );
- jButton3.setText("3" );
- jButton3.setName("jButton3" );
- jButton4.setText("4" );
- jButton4.setName("jButton4" );
- jButton5.setText("5" );
- jButton5.setName("jButton5" );
- jButton6.setText("6" );
- jButton6.setName("jButton6" );
- jButton7.setText("7" );
- jButton7.setName("jButton7" );
- jButton8.setText("8" );
- jButton8.setName("jButton8" );
- jButton9.setText("9" );
- jButton9.setName("jButton9" );
- jButton10.setText("10" );
- jButton10.setName("jButton10" );
- jButton11.setText("1" );
- jButton11.setName("jButton11" );
- jButton12.setText("2" );
- jButton12.setName("jButton12" );
- jButton13.setText("3" );
- jButton13.setName("jButton13" );
- jButton14.setText("4" );
- jButton14.setName("jButton14" );
- jButton15.setText("5" );
- jButton15.setName("jButton15" );
- jButton16.setText("6" );
- jButton16.setName("jButton16" );
- jButton17.setText("7" );
- jButton17.setName("jButton17" );
- jButton18.setText("8" );
- jButton18.setName("jButton18" );
- jButton19.setText("9" );
- jButton19.setName("jButton19" );
- jButton20.setText("10" );
- jButton20.setName("jButton20" );
- jButton21.setText("1" );
- jButton21.setName("jButton21" );
- jButton22.setText("2" );
- jButton22.setName("jButton22" );
- jButton23.setText("3" );
- jButton23.setName("jButton23" );
- jButton24.setText("4" );
- jButton24.setName("jButton24" );
- jButton25.setText("5" );
- jButton25.setName("jButton25" );
- jButton26.setText("6" );
- jButton26.setName("jButton26" );
- jButton27.setText("7" );
- jButton27.setName("jButton27" );
- jButton28.setText("8" );
- jButton28.setName("jButton28" );
- jButton29.setText("9" );
- jButton29.setName("jButton29" );
- jButton30.setText("10" );
- jButton30.setName("jButton30" );
- jButton31.setText("1" );
- jButton31.setName("jButton31" );
- jButton32.setText("2" );
- jButton32.setName("jButton32" );
- jButton33.setText("3" );
- jButton33.setName("jButton33" );
- jButton34.setText("4" );
- jButton34.setName("jButton34" );
- jButton35.setText("5" );
- jButton35.setName("jButton35" );
- jButton36.setText("6" );
- jButton36.setName("jButton36" );
- jButton37.setText("7" );
- jButton37.setName("jButton37" );
- jButton38.setText("8" );
- jButton38.setName("jButton38" );
- jButton39.setText("9" );
- jButton39.setName("jButton39" );
- jButton40.setText("10" );
- jButton40.setName("jButton40" );
- jLabel1.setText("Ligne 1" );
- jLabel2.setText("Ligne 2" );
- jLabel3.setText("Ligne 3" );
- jLabel4.setText("Ligne 4" );
- jLabel5.setText("bonnet" );
- jLabel6.setText("bonnet" );
- jLabel7.setText("bonnet" );
- jLabel8.setText("bonnet" );
- GroupLayout layout = new GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(30, 30, 30)
- .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
- .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
- .addComponent(jButton10, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton1, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton2, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton3, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton4, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton5, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton6, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton7, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton8, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton9, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton21, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton22, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton23, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton24, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton25, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton26, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton27, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton28, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton29, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton30, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE))
- .addComponent(jLabel5)
- .addComponent(jLabel7))
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
- .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel1))
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
- .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
- .addComponent(jLabel6)
- .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
- .addComponent(jButton11, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton12, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton13, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton14, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton15, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton16, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton17, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton18, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton19, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton20, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE))))
- .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane3, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel3))
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
- .addComponent(jLabel8)
- .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
- .addComponent(jButton31, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton32, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton33, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton34, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton35, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton36, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton37, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton38, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton39, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton40, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)))))
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
- .addComponent(jLabel4)
- .addComponent(jLabel2)
- .addComponent(jScrollPane2, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE)
- .addComponent(jScrollPane4, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE))
- .addGap(30, 30, 30))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(28, 28, 28)
- .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel1)
- .addComponent(jLabel2)
- .addComponent(jLabel5)
- .addComponent(jLabel6))
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
- .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jButton1, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton2, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton3, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton4, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton5, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton6, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton7, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton8, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton9, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton10, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE))
- .addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)
- .addComponent(jScrollPane2, GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jButton11, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton12, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton13, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton14, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton15, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton16, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton17, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton18, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton19, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton20, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)))
- .addGap(30, 30, 30)
- .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel3)
- .addComponent(jLabel4)
- .addComponent(jLabel7)
- .addComponent(jLabel8))
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jButton31, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton32, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton33, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton34, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton35, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton36, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton37, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton38, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton39, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton40, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jButton21, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton22, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton23, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton24, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton25, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton26, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton27, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton28, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton29, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton30, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE))
- .addComponent(jScrollPane3, GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)
- .addComponent(jScrollPane4, GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
- .addGap(30, 30, 30))
- );
- }
- }
|
Pointage
Code :
- package pointage;
- import java.sql.*;
- public class Pointage {
-
- public FenPointage fen;
-
- String l1 = "SELECT bonnet, prenom, distance FROM Nageur WHERE actif='1' AND ligne='1' ORDER BY bonnet ASC;";
- String l2 = "SELECT bonnet, prenom, distance FROM Nageur WHERE actif='1' AND ligne='2' ORDER BY bonnet ASC;";
- String l3 = "SELECT bonnet, prenom, distance FROM Nageur WHERE actif='1' AND ligne='3' ORDER BY bonnet ASC;";
- String l4 = "SELECT bonnet, prenom, distance FROM Nageur WHERE actif='1' AND ligne='4' ORDER BY bonnet ASC;";
-
- public static Object[] column1;
- public static Object[] column2;
- public static Object[] column3;
- public static Object[] column4;
- public static Object[][] data1;
- public static Object[][] data2;
- public static Object[][] data3;
- public static Object[][] data4;
-
- public static void main(String[] args) {
- Pointage point = new Pointage();
- point.start();
- }
-
- public Pointage(){
- fen = new FenPointage();
- }
-
- public void start(){
- initLigne1(l1);
- initLigne2(l2);
- initLigne3(l3);
- initLigne4(l4);
- fen.initComponents();
- fen.repaint();
- fen.setVisible( true );
- }
- /////
- //tableau ligne 1
- /////
- public void initLigne1(String query){
- try {
- Statement state =Connexion.getInstance().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
- ResultSet res = state.executeQuery(query);
- ResultSetMetaData meta = res.getMetaData();
- Object [] colonne = new Object[meta.getColumnCount()];
- for(int i = 1 ; i <= meta.getColumnCount(); i++)
- colonne[i-1] = meta.getColumnName(i);
- //Petite manipulation pour obtenir le nombre de lignes
- res.last();
- Object[][] donnee = new Object[res.getRow()][meta.getColumnCount()];
- //On revient au départ
- res.beforeFirst();
- int j = 1;
- //On remplit le tableau d'Object[][]
- while(res.next()){
- for(int i = 1 ; i <= meta.getColumnCount(); i++)
- donnee[j-1][i-1] = res.getObject(i);
- j++;
- }
- res.close();
- state.close();
- Pointage.setcolumn1(colonne);
- Pointage.setdata1(donnee);
- } catch (SQLException e) {}
- }
-
- /////
- //tableau ligne 2
- /////
- public void initLigne2(String query){
- try {
- Statement state =Connexion.getInstance().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
- ResultSet res = state.executeQuery(query);
- ResultSetMetaData meta = res.getMetaData();
- Object [] colonne = new Object[meta.getColumnCount()];
- for(int i = 1 ; i <= meta.getColumnCount(); i++)
- colonne[i-1] = meta.getColumnName(i);
- //Petite manipulation pour obtenir le nombre de lignes
- res.last();
- Object[][] donnee = new Object[res.getRow()][meta.getColumnCount()];
- //On revient au départ
- res.beforeFirst();
- int j = 1;
- //On remplit le tableau d'Object[][]
- while(res.next()){
- for(int i = 1 ; i <= meta.getColumnCount(); i++)
- donnee[j-1][i-1] = res.getObject(i);
- j++;
- }
- res.close();
- state.close();
- Pointage.setcolumn2(colonne);
- Pointage.setdata2(donnee);
- } catch (SQLException e) {}
- }
-
- /////
- //tableau ligne 3
- /////
- public void initLigne3(String query){
- try {
- Statement state =Connexion.getInstance().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
- ResultSet res = state.executeQuery(query);
- ResultSetMetaData meta = res.getMetaData();
- Object [] colonne = new Object[meta.getColumnCount()];
- for(int i = 1 ; i <= meta.getColumnCount(); i++)
- colonne[i-1] = meta.getColumnName(i);
- //Petite manipulation pour obtenir le nombre de lignes
- res.last();
- Object[][] donnee = new Object[res.getRow()][meta.getColumnCount()];
- //On revient au départ
- res.beforeFirst();
- int j = 1;
- //On remplit le tableau d'Object[][]
- while(res.next()){
- for(int i = 1 ; i <= meta.getColumnCount(); i++)
- donnee[j-1][i-1] = res.getObject(i);
- j++;
- }
- res.close();
- state.close();
- Pointage.setcolumn3(colonne);
- Pointage.setdata3(donnee);
- } catch (SQLException e) {}
- }
-
- /////
- //tableau ligne 4
- /////
- public void initLigne4(String query){
- try {
- Statement state =Connexion.getInstance().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
- ResultSet res = state.executeQuery(query);
- ResultSetMetaData meta = res.getMetaData();
- Object [] colonne = new Object[meta.getColumnCount()];
- for(int i = 1 ; i <= meta.getColumnCount(); i++)
- colonne[i-1] = meta.getColumnName(i);
- //Petite manipulation pour obtenir le nombre de lignes
- res.last();
- Object[][] donnee = new Object[res.getRow()][meta.getColumnCount()];
- //On revient au départ
- res.beforeFirst();
- int j = 1;
- //On remplit le tableau d'Object[][]
- while(res.next()){
- for(int i = 1 ; i <= meta.getColumnCount(); i++)
- donnee[j-1][i-1] = res.getObject(i);
- j++;
- }
- res.close();
- state.close();
- Pointage.setcolumn4(colonne);
- Pointage.setdata4(donnee);
- } catch (SQLException e) {}
- }
-
- ////////////////////////////////////////////////////////////////////////////
- public static Object[][] getdata1 (){
- return data1;
- };
- public static Object[][] getdata2 (){
- return data2;
- };
- public static Object[][] getdata3 (){
- return data3;
- };
- public static Object[][] getdata4 (){
- return data4;
- };
- ////////////////////////////////////////////////////////////////////////////
- public static Object[] getcolumn1 (){
- return column1;
- };
- public static Object[] getcolumn2 (){
- return column2;
- };
- public static Object[] getcolumn3 (){
- return column3;
- };
- public static Object[] getcolumn4 (){
- return column4;
- };
- ////////////////////////////////////////////////////////////////////////////
- public static void setdata1 (Object dat[][]){
- data1= dat;
- };
- public static void setdata2 (Object dat[][]){
- data2= dat;
- };
- public static void setdata3 (Object dat[][]){
- data3= dat;
- };
- public static void setdata4 (Object dat[][]){
- data4= dat;
- };
- ////////////////////////////////////////////////////////////////////////////
- public static void setcolumn1 (Object col[]){
- column1= col;
- };
- public static void setcolumn2 (Object col[]){
- column2= col;
- };
- public static void setcolumn3 (Object col[]){
- column3= col;
- };
- public static void setcolumn4 (Object col[]){
- column4= col;
- };
-
- public void stop(){
- fen.setVisible( false );
- }
- }
|
ModifBoutons
Code :
- package pointage;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import java.sql.*;
- import javax.swing.JButton;
- public class ModifBoutons implements ActionListener {
-
- public void actionPerformed(ActionEvent événement) {
- Pointage p = new Pointage();
- String ligne="0";
- String bonnet;
- String nomboutonclique;
- String updist;
- String uptemps;
- String upvitesse;
-
- nomboutonclique = ((JButton) événement.getSource()).getName() ;
- System.out.println("nom du bouton : "+nomboutonclique);
- if (nomboutonclique=="jButton1"||nomboutonclique=="jButton2"||nomboutonclique=="jButton3"||nomboutonclique=="jButton4"||
- nomboutonclique=="jButton5"||nomboutonclique=="jButton6"||nomboutonclique=="jButton7"||nomboutonclique=="jButton8"||
- nomboutonclique=="jButton9"||nomboutonclique=="jButton9" ){
- ligne="1";
- }
- if (nomboutonclique=="jButton11"||nomboutonclique=="jButton12"||nomboutonclique=="jButton13"||nomboutonclique=="jButton14"||
- nomboutonclique=="jButton15"||nomboutonclique=="jButton16"||nomboutonclique=="jButton17"||nomboutonclique=="jButton18"||
- nomboutonclique=="jButton19"||nomboutonclique=="jButton19" ){
- ligne="2";
- }
- if (nomboutonclique=="jButton21"||nomboutonclique=="jButton22"||nomboutonclique=="jButton23"||nomboutonclique=="jButton24"||
- nomboutonclique=="jButton25"||nomboutonclique=="jButton26"||nomboutonclique=="jButton27"||nomboutonclique=="jButton28"||
- nomboutonclique=="jButton29"||nomboutonclique=="jButton29" ){
- ligne="3";
- }
- if (nomboutonclique=="jButton31"||nomboutonclique=="jButton32"||nomboutonclique=="jButton33"||nomboutonclique=="jButton34"||
- nomboutonclique=="jButton35"||nomboutonclique=="jButton36"||nomboutonclique=="jButton37"||nomboutonclique=="jButton38"||
- nomboutonclique=="jButton39"||nomboutonclique=="jButton39" ){
- ligne="4";
- }
-
- JButton titreboutonclique = (JButton) événement.getSource();
- bonnet = titreboutonclique.getText();
- System.out.println("numéro du ligne : "+ligne);
- System.out.println("numéro du bonnet : "+bonnet);
-
- updist = "UPDATE Nageur SET distance = distance+50 WHERE actif='1' AND ligne = '"+ligne+"' AND bonnet = '"+bonnet+"';";
- uptemps= "UPDATE Nageur SET temps = CURRENT_TIME()-heure_depart WHERE actif='1' AND ligne = '"+ligne+"' AND bonnet = '"+bonnet+"';";
- upvitesse = "UPDATE Nageur SET vitesse = distance*3.6/TIME_TO_SEC(temps) WHERE actif='1' AND ligne = '"+ligne+"' AND bonnet = '"+bonnet+"';";
-
- try {
- Statement state = Connexion.getInstance().createStatement();
- int updatedist = state.executeUpdate(updist);
- int updatetemps = state.executeUpdate(uptemps);
- int updatevitesse = state.executeUpdate(upvitesse);
- System.out.println("distance : "+updatedist+" temps : "+updatetemps+" vitesse : "+updatevitesse);
- state.close();
-
- } catch (SQLException e) {}
- }
- }
|
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
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 :
- ( (AbstractTableModel) table.getModel()).fireTableDataChanged();
|
Un petit exemple simple :
Code :
- /*
- * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of Oracle or the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
- /*
- * SimpleTableDemo.java requires no other files.
- */
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- import javax.swing.JTable;
- import javax.swing.table.AbstractTableModel;
- import java.awt.Dimension;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.Arrays;
- import java.util.Vector;
- /**
- *
- * @see http://forum.hardware.fr/hfr/Progr [...] 1229_1.htm
- * @see http://docs.oracle.com/javase/tuto [...] table.html
- * @see http://docs.oracle.com/javase/tuto [...] html?code=
- * http://docs.oracle.com/javase/tuto [...] eDemo.java
- *
- */
- public class SimpleTableDemo extends JPanel {
-
- private String[] columnNamesArray = {"First Name",
- "Last Name",
- "Sport",
- "# of Years",
- "Vegetarian"};
-
- private Vector<String> columnNames;
-
- private Object[][] dataArray = {
- {"Kathy", "Smith",
- "Snowboarding", new Integer(5), new Boolean(false)},
- {"John", "Doe",
- "Rowing", new Integer(3), new Boolean(true)},
- {"Sue", "Black",
- "Knitting", new Integer(2), new Boolean(false)},
- {"Jane", "White",
- "Speed reading", new Integer(20), new Boolean(true)},
- {"Joe", "Brown",
- "Pool", new Integer(10), new Boolean(false)}
- };
-
- private Vector<Vector<Object>> data;
-
- private JTable table;
-
- public SimpleTableDemo() {
- super(new GridLayout(1,0));
- columnNames = new Vector<>(Arrays.asList(columnNamesArray));
- data = new Vector<>();
-
- for(Object[] line : dataArray) {
- data.add(new Vector<>(Arrays.asList(line)));
- }
- table = new JTable(data, columnNames);
- table.setPreferredScrollableViewportSize(new Dimension(500, 70));
- table.setFillsViewportHeight(true);
- //Create the scroll pane and add the table to it.
- JScrollPane scrollPane = new JScrollPane(table);
- //Add the scroll pane to this panel.
- add(scrollPane);
- }
-
- private void addLineTable() {
- int nbRows = data.size();
- Object[] row = {"first name " + nbRows, "last name " + nbRows, "sport " + nbRows, new Integer(5), new Boolean(false)};
- data.add(new Vector<>(Arrays.asList(row)));
- ( (AbstractTableModel) table.getModel()).fireTableDataChanged();
- }
- /**
- * Create the GUI and show it. For thread safety,
- * this method should be invoked from the
- * event-dispatching thread.
- */
- private static void createAndShowGUI() {
- //Create and set up the window.
- JFrame frame = new JFrame("SimpleTableDemo" );
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- //Create and set up the content pane.
- final SimpleTableDemo newContentPane = new SimpleTableDemo();
- frame.add("Center", newContentPane);
-
- JButton addButton = new JButton("Add" );
- addButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent arg0) {
- newContentPane.addLineTable();
- }
- });
-
- JPanel southPanel = new JPanel();
- southPanel.add(addButton);
- frame.add("South", southPanel);
- //Display the window.
- frame.setSize(640, 280);
- frame.setLocationRelativeTo(null);
- frame.setVisible(true);
- }
- public static void main(String[] args) {
- //Schedule a job for the event-dispatching thread:
- //creating and showing this application's GUI.
- javax.swing.SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- createAndShowGUI();
- }
- });
- }
- }
|
|