thread ,jtable ,jscrollpane
salut
j'ai un problème avec les threads j'ai crée deux threads t et t1 ,chaque thread sert à récupérer les donnée d'une table sur jTable
les deux threads s'executent en parallele
j'ai crée une classe qui contient les threads mais je ne sais pas faire parallelisme
,faire executerles deux threads en parallele puis afficher résultta dans une autre classe créer
voila la classe qui contient les threads
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
package stock;
import javax.swing.*;
import java.sql.*;
import javax.swing.table.*;
class partition extends Thread {
DefaultTableModel mode15,mode16;
int j,i;
public Thread t=new Thread(){
public void run(){
Connection conn = null;
String url = "jdbc:mysql://localhost/facture";
String userName = "root";
String password = "ulysse";
String[] column2 = { "id","nom de famille" };
mode15 = new DefaultTableModel(column2, 0);
JTable jTable2 = new JTable(mode15);
i=0;
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = DriverManager.getConnection(url, userName, password);
Statement instruction = conn.createStatement();
System.out.println("Connected");
String sql = " SELECT id3,fa from facture.famille ";
ResultSet resultat = instruction.executeQuery(sql);
while (resultat.next()) {
mode15.addRow(new String[] {"", "" });
jTable2.setValueAt(resultat.getString("famille.id3") ,i, 0);
jTable2.setValueAt(resultat.getString("famille.fa") ,i, 1);
i++;
}
}
catch (Exception g) {
System.out.println("ERREUR " + g);
}
}
};
public Thread t1=new Thread(){
public void run(){
Connection conn = null;
String url = "jdbc:mysql://localhost/facture";
String userName = "root";
String password = "ulysse";
String[] column3 = { "id","nom" };
mode16 = new DefaultTableModel(column3, 0);
JTable jTable3 = new JTable(mode16);
j=0;
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = DriverManager.getConnection(url, userName, password);
Statement instruction = conn.createStatement();
System.out.println("Connected2");
String sql = " SELECT d,nom from facture.stock ";
ResultSet resultat = instruction.executeQuery(sql);
while (resultat.next()) {
mode16.addRow(new String[] {"", "" });
jTable3.setValueAt(resultat.getString("stock.d") ,j, 0);
jTable3.setValueAt(resultat.getString("stock.nom") ,j, 1);
j++;
}
}
catch (Exception g) {
System.out.println("ERREUR3 " + g);
}
}
};
} |
et le code qui contient la partie d'affichage
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
package stock;
import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;
public class stockfamille extends JFrame {
stockfamille(){
setTitle("Fiche produit");
this.setResizable(false);
this.setSize(600, 500);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
partition a = new partition();
a.t.start();
a.t1.start();
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
public static void main (String [] args){
stockfamille d = new stockfamille() ;
d.setVisible(true);
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
jPanel1.setBorder(null);
jPanel1.setBounds(new Rectangle(43, 8, 487, 308));
jPanel1.setLayout(null);
jScrollPane2.setBounds(new Rectangle(9, 32, 325, 90));
jScrollPane3.setBounds(new Rectangle(21, 194, 325, 94));
this.getContentPane().add(jPanel1, null);
jPanel1.add(jScrollPane2, null);
jPanel1.add(jScrollPane3, null);
}
JPanel jPanel1 = new JPanel();
JScrollPane jScrollPane2 = new JScrollPane();
JScrollPane jScrollPane3 = new JScrollPane();
} |
j'espere avoir une réponse merci d'avance