Salut . j'ai ecrit un code qui recupere le contenu d'une table html
et doit l'afficher dans une JTable qui aura comme header num , nomPrenom , adr , id .
j'arrive pas a afficher les listes recuperer dans une JTable .aidezz moi svp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.ArrayList; import javax.swing.JTable; public class Lecteur { private static ArrayList<String> listeEtudiant = new ArrayList<String>(); public static void ajouterLigne(String line ){ listeEtudiant.add(line); //System.out.println("Ligne Size : " + listeEtudiant.size() + " " + line); String[] monTab = line.split(" "); String num = monTab[0]; String nomprenom = monTab[1]; String adr = monTab[2]; String id = monTab[3]; System.out.println(num + nomprenom + adr + id); } public static ArrayList getListeEtudiants(){ return listeEtudiant; } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 import java.net.*; import java.io.*; import java.util.regex.Matcher; import java.util.regex.Pattern; public class URLConnectionReader { public static void main(String[] args) throws Exception { URL yahoo = new URL("http://deptinfo.unice.fr/~grin/mescours/linfo/poo/projets/listeetudiants.html"); URLConnection yc = yahoo.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { StringBuilder codeHTML = new StringBuilder(); String expReguliere = ".*?<tr[^>]*>(.*?)</tr>.*?"; Pattern p = Pattern.compile(expReguliere); while ((inputLine = in.readLine()) != null) { codeHTML.append(inputLine); } Matcher m = p.matcher(codeHTML.toString()); while(m.find()) // System.out.println(m.group(1).replaceAll("(<[^>]*>)|(</[a-z]*>)", " ")); Lecteur.ajouterLigne(m.group(1).replaceAll("(<[^>]*>)|(</[a-z]*>)", " ")); // } // System.out.println(inputLine); // // Lecteur.getListeEtudiants().remove(0); //for(int i=0; i<Lecteur.getListeEtudiants().size() ; i++){ // System.out.println(Lecteur.getListeEtudiants().get(i)); } in.close(); } }
Partager