2016-05-26 4 views
-1

У меня есть работа, и я хочу отображать результаты этой программы в моем графическом интерфейсе, но я просто не могу этого сделать, тогда я хочу, чтобы метод позволял мне видеть результаты этой программы в моем График inetreface, поэтому я создал интерфейс, и я зарезервировал отображение кнопок и область для отображения (JTextArea), это означает, что когда я нажимаю на кнопку, она показывает результаты (содержимое моего Rdf-файла). Я хочу, чтобы ваша помощь, если это возможно, и спасибо заранееRdf и java gui

Model model = ModelFactory.createDefaultModel(); 
    // use the FileManager to find the input file 
    InputStream in = (InputStream) FileManager.get().open("C:/Users/SAMSUNG/Desktop/WICM2/projet/opus_august2007.rdf"); 
    if (in == null) { 
    throw new IllegalArgumentException(
    "File: " + "C:/Users/SAMSUNG/Desktop/WICM2/projet/opus_august2007.rdf"+ " not found"); 
    } 
    // read the RDF/XML file 
    model.read(in, ""); 

    // write it to standard out 
    //model.write(System.out); 
    model.write(System.out); 

и вот мой интерфейс программы

import java.io.InputStream; 
import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.List; 
import java.util.Map; 

import javax.swing.JFileChooser; 
import javax.swing.filechooser.FileNameExtensionFilter; 

import com.hp.hpl.jena.rdf.model.Model; 
import com.hp.hpl.jena.rdf.model.ModelFactory; 
import com.hp.hpl.jena.rdf.model.NodeIterator; 
import com.hp.hpl.jena.rdf.model.Statement; 
import com.hp.hpl.jena.rdf.model.StmtIterator; 
import com.hp.hpl.jena.util.FileManager; 

/** 
* 
* @author SAMSUNG 
*/ 
public class frameFinal extends javax.swing.JFrame { 

    /** 
    * Creates new form FrameFinal 
    */ 
    public frameFinal() { 
     initComponents(); 
    } 

    /** 
    * This method is called from within the constructor to initialize the form. 
    * WARNING: Do NOT modify this code. The content of this method is always 
    * regenerated by the Form Editor. 
    */ 
    @SuppressWarnings("unchecked") 
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents 
    private void initComponents() { 

     jTabbedPane1 = new javax.swing.JTabbedPane(); 
     jPanel1 = new javax.swing.JPanel(); 
     jButton1 = new javax.swing.JButton(); 
     jTextField3 = new javax.swing.JTextField(); 
     jPanel3 = new javax.swing.JPanel(); 
     jTextArea2 = new javax.swing.JTextArea(); 
     jButton3 = new javax.swing.JButton(); 
     jPanel4 = new javax.swing.JPanel(); 
     jButton4 = new javax.swing.JButton(); 
     jScrollPane1 = new javax.swing.JScrollPane(); 
     jScrollPane2 = new javax.swing.JScrollPane(); 
     jTextArea1 = new javax.swing.JTextArea(); 
     jMenuBar1 = new javax.swing.JMenuBar(); 
     jMenu1 = new javax.swing.JMenu(); 
     jMenu2 = new javax.swing.JMenu(); 

     setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 
      setTitle("Rdf & taxonomie"); 
     jPanel1.setBackground(new java.awt.Color(204, 204, 255)); 

     jButton1.setText("PARCOURIR"); 
     jButton1.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       jButton1ActionPerformed(evt); 
      } 
     }); 

     jTextField3.setBackground(new java.awt.Color(204, 204, 204)); 
     jTextField3.setEnabled(false); 

     javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); 
     jPanel1.setLayout(jPanel1Layout); 
     jPanel1Layout.setHorizontalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(jPanel1Layout.createSequentialGroup() 
       .addContainerGap(53, Short.MAX_VALUE) 
       .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 327, javax.swing.GroupLayout.PREFERRED_SIZE) 
       .addGap(18, 18, 18) 
       .addComponent(jButton1) 
       .addGap(79, 79, 79)) 
     ); 
     jPanel1Layout.setVerticalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(jPanel1Layout.createSequentialGroup() 
       .addGap(120, 120, 120) 
       .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
        .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE) 
        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)) 
       .addContainerGap(157, Short.MAX_VALUE)) 
     ); 

     jTabbedPane1.addTab("Chargement File", jPanel1); 



     jButton3.setText("Visualise"); 
     jButton3.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       jButton3ActionPerformed(evt); 
      } 
     }); 



     jTabbedPane1.addTab("Visualiser", jPanel3); 

     jButton4.setText("Generer"); 
     jButton4.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       jButton4ActionPerformed(evt); 
      } 
     }); 

     jTextArea1.setColumns(20); 
     jTextArea1.setRows(5); 
     jScrollPane1.setViewportView(jTextArea1); 
     jTextArea2.setColumns(20); 

     jTextArea2.setRows(5); 
     jScrollPane2.setViewportView(jTextArea2); 
     javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); 
     jPanel3.setLayout(jPanel3Layout); 
     jPanel3Layout.setHorizontalGroup(
      jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() 
       .addContainerGap(477, Short.MAX_VALUE) 
       .addComponent(jButton3) 
       .addGap(20, 20, 20)) 
      .addComponent(jScrollPane2) 
     ); 
     jPanel3Layout.setVerticalGroup(
      jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(jPanel3Layout.createSequentialGroup() 
       .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE) 
       .addGap(18, 18, 18) 
       .addComponent(jButton3)) 
     ); 
     javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); 
     jPanel4.setLayout(jPanel4Layout); 
     jPanel4Layout.setHorizontalGroup(
      jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(jPanel4Layout.createSequentialGroup() 
       .addGap(0, 489, Short.MAX_VALUE) 
       .addComponent(jButton4) 
       .addContainerGap()) 
      .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 570, Short.MAX_VALUE) 
     ); 
     jPanel4Layout.setVerticalGroup(
      jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(jPanel4Layout.createSequentialGroup() 
       .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 246, javax.swing.GroupLayout.PREFERRED_SIZE) 
       .addGap(18, 18, 18) 
       .addComponent(jButton4) 
       .addGap(0, 25, Short.MAX_VALUE)) 
     ); 

     jTabbedPane1.addTab("Taxonomie", jPanel4); 

     jMenu1.setText("File"); 
     jMenuBar1.add(jMenu1); 

     jMenu2.setText("Edit"); 
     jMenuBar1.add(jMenu2); 

     setJMenuBar(jMenuBar1); 

     javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 
     getContentPane().setLayout(layout); 
     layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING) 
     ); 
     layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addComponent(jTabbedPane1) 
     ); 

     pack(); 
    }// </editor-fold>//GEN-END:initComponents 

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed 
     JFileChooser fileChooser = new JFileChooser(); 
     fileChooser.setCurrentDirectory(new java.io.File("C:\\Users\\SAMSUNG\\Desktop\\WICM2\\projet")); 
     fileChooser.setFileFilter(new FileNameExtensionFilter("RDF Definitions", "rdf", "RDF")); 
     int returnVal = fileChooser.showOpenDialog(null); 
     if (returnVal == JFileChooser.APPROVE_OPTION) { 
      this.jTextField3.setText(fileChooser.getSelectedFile().getPath()); 
    }//GEN-LAST:event_jButton1ActionPerformed 
    } 

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed 
     // TODO add your handling code here: 
    }//GEN-LAST:event_jTextField1ActionPerformed 

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed 
     jTextArea1.setText(""); 
     Model model = ModelFactory.createDefaultModel(); 
      InputStream in = FileManager.get().open("C:/Users/SAMSUNG/Desktop/WICM2/projet/opus_august2007.rdf"); 
      Model m = model.read(in,null); 
      NodeIterator nit = m.listObjects(); 
      List<String> lclass = new ArrayList<>(); 
      Map<String,List<String>> map = new HashMap<>(); 
      StmtIterator si = m.listStatements(); 
      while(si.hasNext()){ 
       Statement statement = si.next(); 
      if(statement.getPredicate().getLocalName().equalsIgnoreCase("subClassOf")){ 
       String mere = statement.getObject().toString(); 
       String fils = statement.getSubject().getLocalName(); 
       if(map.containsKey(mere)){ 
        List<String> l = map.get(mere); 
        l.add(fils); 
        map.replace(mere, l); 
       }else{ 
        List<String> l = new ArrayList<>(); 
        l.add(fils); 
        map.put(mere, l); 
       } 
      } 
       if(statement.getObject().isResource() && statement.getPredicate().getLocalName().equalsIgnoreCase("type")){ 
        if(!lclass.contains(statement.getSubject().getLocalName())){ 
        lclass.add(statement.getSubject().getLocalName()) ; 
        } 
       } 
      } 
      jTextArea1.append("Les classes:\n"); 
      for(String classe:lclass){ 
       jTextArea1.append(classe+"\n"); 
      } 
      jTextArea1.append("Les classe et les sous classes:\n"); 
      for(String l : map.keySet()){ 
       jTextArea1.append("Classe mere : "+l+"\n"); 
       for(String s:map.get(l)){ 
        jTextArea1.append(" Classe fils:"+s+"\n"); 


       } 
      } 
    }//GEN-LAST:event_jButton4ActionPerformed 
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { 
     /*jTextArea2.setText(""); 
     Model model = ModelFactory.createDefaultModel(); 
     // use the FileManager to find the input file 
     InputStream in = FileManager.get().open("C:/Users/SAMSUNG/Desktop/WICM2/projet/opus_august2007.rdf"); 
     // DataInputStrean st = new DataInputStream() ; 
     if (in == null) { 
     throw new IllegalArgumentException(
     "File: " + "C:/Users/SAMSUNG/Desktop/WICM2/projet/opus_august2007.rdf"+ " not found"); 
     } 
     // read the RDF/XML file 
     model.read(in, ""); 
     // write it to standard out 
     //model.write(System.out); 
     model.write(System.out);*/ 

    } 
    /** 
    * @param args the command line arguments 
    */ 
    public static void main(String args[]) { 
     /* Set the Nimbus look and feel */ 
     //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> 
     /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. 
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */ 
     try { 
      for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { 
       if ("Nimbus".equals(info.getName())) { 
        javax.swing.UIManager.setLookAndFeel(info.getClassName()); 
        break; 
       } 
      } 
     } catch (ClassNotFoundException ex) { 
      java.util.logging.Logger.getLogger(frameFinal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
     } catch (InstantiationException ex) { 
      java.util.logging.Logger.getLogger(frameFinal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
     } catch (IllegalAccessException ex) { 
      java.util.logging.Logger.getLogger(frameFinal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
     } catch (javax.swing.UnsupportedLookAndFeelException ex) { 
      java.util.logging.Logger.getLogger(frameFinal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
     } 
     //</editor-fold> 

     /* Create and display the form */ 
     java.awt.EventQueue.invokeLater(new Runnable() { 
      public void run() { 
       new frameFinal().setVisible(true); 
      } 
     }); 
    } 

    // Variables declaration - do not modify//GEN-BEGIN:variables 
    private javax.swing.JButton jButton1; 
    private javax.swing.JButton jButton3; 
    private javax.swing.JButton jButton4; 
    private javax.swing.JMenu jMenu1; 
    private javax.swing.JMenu jMenu2; 
    private javax.swing.JMenuBar jMenuBar1; 
    private javax.swing.JPanel jPanel1; 
    private javax.swing.JPanel jPanel3; 
    private javax.swing.JPanel jPanel4; 
    private javax.swing.JScrollPane jScrollPane1; 
    private javax.swing.JScrollPane jScrollPane2; 
    private javax.swing.JTabbedPane jTabbedPane1; 
    private javax.swing.JTextArea jTextArea1; 
    private javax.swing.JTextArea jTextArea2; 
    private javax.swing.JTextField jTextField3; 
    // End of variables declaration//GEN-END:variables 
} 
+0

Ахмед: Я полностью понимаю, что английский язык не может быть вашим первым языком, так как это не мое. Но могли бы вы хотя бы исправить свои опечатки и знаки препинания? Трудно проанализировать ваш вопрос. –

+0

да большое спасибо за ваш комментарий, я постараюсь улучшить свой английский – ahmed

+0

Ahmed: Спасибо за улучшения в пунктуации; вы могли бы также попытаться изменить свой код на минимальный, полный и проверенный пример (как указано в http://stackoverflow.com/help/mcve) –

ответ

0

Если я понимаю, что вы хотите отобразить весь файл RDF в текстовой области. Так что, если это то, что вы хотите, вы просто должны прочитать его в использовании читателя что-то вроде ...

try{ 
    FileReader f = new FileReader("c:\\opus_august2007.rdf"); 
    BufferedReader b = new BufferedReader(f); 
    boolean eof = false; 
    while(! eof) 
     { 
     String lineIn = b.readLine(); 
     if(lineIn == null) 
     { 
     eof = true; 
     } 
     else 
     { 
     mytxtarea.append(lineIn + System.getProperty("line.separator")); 
     } 
     } 
    }catch(Exception e){ 
     e.printStackTrace(); 
    } 
+0

Большое спасибо – ahmed

+0

Здравствуйте, я хочу показать свой результат этой программы как дерево, я хочу, чтобы рука закончила мою работу и заранее заблаговременно Вот мой код – ahmed