IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Format d'échange (XML, JSON...) Java Discussion :

JPanel + Xml


Sujet :

Format d'échange (XML, JSON...) Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    94
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 94
    Par défaut JPanel + Xml
    Avec la classe JDOM2, j'ai réussi à récupérer les données contenu dans un fichier xml.
    Je souhaite maintenant les afficher dans une IHM.
    je n'arrive pas à afficher ce résultat dans un JPanel.

    Si quelqu'un à une idée de la manière à faire
    Merci

    Voici le code de mon IHM
    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
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.Dimension;
     
    import javax.swing.*;
     
    public class Onglet extends JTabbedPane {
     
    	public static void main(String[] args)
    	{
    	     JFrame ihm = new JFrame("IHM XML");
    	     ihm.setSize(new Dimension(800,400));
    	     Container c = ihm.getContentPane();
     
    	     c.setLayout(new BorderLayout());
     
    	     JTabbedPane onglets; 
    	     JPanel panneau;
    	     LectureXml statXml;
     
    	     c.add("Center", onglets = new JTabbedPane(SwingConstants.TOP));
     
    	     onglets.addTab("Utilisation",panneau = new JPanel());
    	     panneau.add(new JLabel());
     
    	     onglets.addTab("Erreurs",panneau = new JPanel());
    	     panneau.add(new JLabel());
     
    	     onglets.addTab("Collisions",panneau = new JPanel());
    	     panneau.add(new JLabel());
     
    	     onglets.addTab("Broadcasts",panneau = new JPanel());
    	     panneau.add(new JLabel());
     
    	     onglets.addTab("Protocoles",panneau = new JPanel());
    	     panneau.add(new JLabel());
     
    	     onglets.setSelectedIndex(0);
     
    	     ihm.setVisible(true);
    	}
    }

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    94
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 94
    Par défaut
    Après quelques essais j'arrive à ça mais sans succès :
    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
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    import java.io.*;
    import org.jdom.*;
    import org.jdom.input.*;
    import org.jdom.filter.*;
    import java.util.List;
    import java.util.Iterator;
    import javax.swing.*;
    import java.awt.*;
     
    public class LectureXml extends JTextPane {
     
    	static org.jdom.Document document;
    	static Element racine;
     
    	public static void main(String[] args)
    	 {
    	    //On crée une instance de SAXBuilder
    	    SAXBuilder sxb = new SAXBuilder();
     
    	    try
    	    {
    	    	//On crée un nouveau document JDOM avec en argument le fichier XML
    	    	//Le parsing est terminé
    	    	document = sxb.build(new File("Horodatage.xml"));
    	    }
     
    	    catch(Exception e){
    	    	System.out.println( e );
    	    }
     
    	    //On initialise un nouvel élément racine avec l'élément racine du document.
    	    racine = document.getRootElement();
     
    	    afficheALL(racine,"");
    	 }
     
    	 static void afficheALL(Element elt, String tab)
    	 {
    	    //On crée une List contenant tous les noeuds "statistiques" de l'Element racine
    	    List listHorodatage = elt.getChildren();
     
    	    //On crée un Iterator sur notre liste
    	    Iterator i = listHorodatage.iterator();
     
    	    while(i.hasNext())
    	    {
    	    	Element courant = (Element)i.next();
    	    	if(courant.getName().equals("statistiques"))
    	    	{
    	    		JTextField Lab = new JTextField(tab+courant.getAttribute("erreurs"));
    	    		afficheALL(courant,tab+"\t");
    	    	}
     
    	    	if (!courant.getName().toLowerCase().equals("utilisation"))
    	    	{
    	    		JTextField Labi = new JTextField (tab+courant.getText());
    	    	}
    	    }
    	 }
    }
    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
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.Dimension;
    import javax.swing.*;
     
    public class Onglet extends JFrame {
     
    	public static void main(String[] args)
    	{
    	     JFrame ihm = new JFrame("IHM XML");
    	     ihm.setSize(new Dimension(800,400));
    	     Container c = ihm.getContentPane();
     
    	     c.setLayout(new BorderLayout());
     
    	     JTabbedPane onglets; 
     
    	     LectureXml panneau = new LectureXml();
     
     
    	     c.add("Center", onglets = new JTabbedPane(SwingConstants.TOP));
     
    	     onglets.addTab("Utilisation", panneau);
    	     panneau.add(new JLabel());
     
    	     onglets.addTab("Erreurs",panneau = new LectureXml());
    	     panneau.add(new JLabel());
     
    	     onglets.addTab("Collisions",panneau = new LectureXml());
    	     panneau.add(new JLabel());
     
    	     onglets.addTab("Broadcasts",panneau = new LectureXml());
    	     panneau.add(new JLabel());
     
    	     onglets.addTab("Protocoles",panneau = new LectureXml());
    	     panneau.add(new JLabel());
     
    	     onglets.setSelectedIndex(0);
     
    	     ihm.setVisible(true);
    	}
    }

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    94
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 94
    Par défaut
    J'ai essayé cette manière mais elle ne focntionne pas
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    while(i.hasNext())
    	    {
    	    	Element courant = (Element)i.next();
    	    	if(courant.getName().equals("statistiques"))
    	    	{
    	    		JLabel champ = new JLabel(tab+courant.getText());
    	    	}
     
    	    	if (!courant.getName().toLowerCase().equals("utilisation"))
    	    	{
    	    		JLabel champ = new JLabel (tab+courant.getText());
    	    	}
    	    }
    Est-ce que je suis sur la bonne voie quand même ?

Discussions similaires

  1. xml -> xsl -> xml
    Par virgile04 dans le forum XSL/XSLT/XPATH
    Réponses: 2
    Dernier message: 10/10/2002, 16h53
  2. Balises HTML dans un fichier XML
    Par Bastet79 dans le forum XML/XSL et SOAP
    Réponses: 12
    Dernier message: 04/09/2002, 15h29
  3. delphi XML / HTML caractéres speciaux !
    Par adem dans le forum EDI
    Réponses: 2
    Dernier message: 29/08/2002, 17h48
  4. Débutant XML
    Par viny dans le forum XML/XSL et SOAP
    Réponses: 8
    Dernier message: 25/07/2002, 12h07
  5. Pas de casse dans les XML
    Par :GREG: dans le forum Composants VCL
    Réponses: 4
    Dernier message: 17/07/2002, 13h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo