Results 1 to 6 of 6
  1. #1
    doha786 is offline Member
    Join Date
    Mar 2009
    Posts
    48
    Rep Power
    0

    Question How to solve this JTable problem??

    hi,

    I am trying to build a small program that can search java ‘class’ files and ‘method’s from a repository where millions of java files are stored. In addition it has an algorithm(LONGEST COMMON SUBSEQUENCE) to compare the results to find the similarity percentage and user can make precision by putting threshold value before start searching.

    I already done for java ‘class’ files and it can show results correctly in TextArea of GUI. But actually I want to show these results in JTable instead of textArea where result will create rows automatically in Table.

    I am trying like this, has no error but no output..

    Would anybody please check and help me......

    Java Code:
    public void actionPerformed(ActionEvent e) {
    if(e.getSource()==searchButton){
    
    FileReader reader;         String result="";             
    String word= new String(); 
    String target = "class";
     Map<String, File> names = new HashMap<String, File>();
     
    try{ 
    
    File directory = new File("C:/Java/Repository");// setting the repository path
    
    File filelist[]= directory.listFiles();
    
          for (File f: filelist) {
       
    reader = new FileReader (f);     
    Scanner scan = new Scanner(reader); 
    
    while(scan.hasNext()){ scan.next();
     result = scan.findWithinHorizon(target,0); 
    
    if(result!=null) {
    word = (scan.next() + scan.findWithinHorizon("", 0));
    names.put(word,f); }
    
    for (String found: names.keySet()){ } 
    
       }
      }
      
    
     }
             String SearchClass=txtField.getText();
                  
             for (String found: names.keySet()) {
             DecimalFormat myformat=new DecimalFormat("###.##");
             double compare = MyGui.LCS(found, SearchClass);
             double getThreshold = Double.parseDouble(threshold.getText());
          
          
             if (compare >= getThreshold) {
                   File file = names.get(found);
    
          //previously show resutls in textArea correctly
                   //txtArea.append(found+"\t\t\t\t"+myformat.format(compare) +" \t\t\t "+ file.getName()+"\n");  
              
    
    //now i want to make column and row to show that same results     
                try {  
                   DefaultTableModel model= new DefaultTableModel();
    Vector<String> vCol = new Vector<String>();
     vCol.addElement("NAMES");    vCol.addElement("SIMILAIRY");    vCol.addElement("FILE PATH"); 
    
              Vector<String> row;
            Vector<Vector> vRow=new Vector<Vector>();        
             
             row= new Vector<String>();
                            
     row.addElement(found); row.addElement(myformat.format(compare)); row.addElement(file.getName());
    //  row.addElement(""+found); row.addElement(""+myformat.format(compare)); row.addElement(""+file.getName());
          
             vRow.addElement(row);
            model.addRow(vRow);
            model = new DefaultTableModel(vRow, vCol); 
       
    JTable table = new JTable(model);
          
    JScrollPane scrollpane = new JScrollPane(table);
    resultSet.add(scrollpane);
            }
           catch(Exception exc)
                      {
                         System.out.println("Error!" + exc);
                      }
    
                }
       }           
     }
     // show error message when threshold is empty
    catch(Exception ex)  {JOptionPane.showMessageDialog(null,"Threshold is Empty",  "Error", JOptionPane.ERROR_MESSAGE); }     
             }
    }
    Last edited by doha786; 02-05-2010 at 02:23 AM.

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    806
    Rep Power
    6

    Default

    Please include code tag and repost the complete code.
    Ramya:cool:

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  4. #4
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    5

    Default

    Quote Originally Posted by RamyaSivakanth View Post
    Please include code tag and repost the complete code.
    Many seems to have that trouble of including code tags.

    Hey Fudarable why dont you include a Sticky topic of how to use code tags.

  5. #5
    doha786 is offline Member
    Join Date
    Mar 2009
    Posts
    48
    Rep Power
    0

    Default

    Repost the code:

    Java Code:
    public void actionPerformed(ActionEvent e) {
    if(e.getSource()==searchButton){
    
    FileReader reader;         String result="";             
    String word= new String(); 
    String target = "class";
     Map<String, File> names = new HashMap<String, File>();
     
    try{ 
    
    File directory = new File("C:/Java/Repository");// setting the repository path
    
    File filelist[]= directory.listFiles();
    
          for (File f: filelist) {
       
    reader = new FileReader (f);     
    Scanner scan = new Scanner(reader); 
    
    while(scan.hasNext()){ scan.next();
     result = scan.findWithinHorizon(target,0); 
    
    if(result!=null) {
    word = (scan.next() + scan.findWithinHorizon("", 0));
    names.put(word,f); }
    
    for (String found: names.keySet()){ } 
    
       }
      }
      
    
     }
             String SearchClass=txtField.getText();
                  
             for (String found: names.keySet()) {
             DecimalFormat myformat=new DecimalFormat("###.##");
             double compare = MyGui.LCS(found, SearchClass);
             double getThreshold = Double.parseDouble(threshold.getText());
          
          
             if (compare >= getThreshold) {
                   File file = names.get(found);
    
          //previously show resutls in textArea correctly
                   //txtArea.append(found+"\t\t\t\t"+myformat.format(compare) +" \t\t\t "+ file.getName()+"\n");  
              
    
    //now i want to make column and row to show that same results     
                try {  
                   DefaultTableModel model= new DefaultTableModel();
    Vector<String> vCol = new Vector<String>();
     vCol.addElement("NAMES");    vCol.addElement("SIMILAIRY");    vCol.addElement("FILE PATH"); 
    
              Vector<String> row;
            Vector<Vector> vRow=new Vector<Vector>();        
             
             row= new Vector<String>();
                            
     row.addElement(found); row.addElement(myformat.format(compare)); row.addElement(file.getName());
    //  row.addElement(""+found); row.addElement(""+myformat.format(compare)); row.addElement(""+file.getName());
          
             vRow.addElement(row);
            model.addRow(vRow);
            model = new DefaultTableModel(vRow, vCol); 
       
    JTable table = new JTable(model);
          
    JScrollPane scrollpane = new JScrollPane(table);
    resultSet.add(scrollpane);
            }
           catch(Exception exc)
                      {
                         System.out.println("Error!" + exc);
                      }
    
                }
       }           
     }
     // show error message when threshold is empty
    catch(Exception ex)  {JOptionPane.showMessageDialog(null,"Threshold is Empty",  "Error", JOptionPane.ERROR_MESSAGE); }     
             }
    }

  6. #6
    doha786 is offline Member
    Join Date
    Mar 2009
    Posts
    48
    Rep Power
    0

    Default

    its not my 1st post, i've followed how to use code tags correctly but dont know why showing like this way...

    anyway, i m going to make another new post.

    thanks.

Similar Threads

  1. Need help to solve my problem
    By Copro in forum New To Java
    Replies: 4
    Last Post: 08-21-2009, 04:26 AM
  2. Could someone help me to solve this problem...
    By Vinny in forum Java Software
    Replies: 1
    Last Post: 07-08-2009, 06:59 PM
  3. Help me to solve problem
    By mansoorhacker in forum Forum Guides
    Replies: 8
    Last Post: 01-24-2009, 06:29 PM
  4. Solve my Problem
    By kyo in forum New To Java
    Replies: 1
    Last Post: 12-16-2008, 02:22 PM
  5. Replies: 2
    Last Post: 05-15-2008, 10:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •