lucene界面索引的建立

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

import org.apache.lucene.search.Sort;

 class jiemian { 
    JSearcher JS=new JSearcher();
    XMLSearcher XMLS=new XMLSearcher();
    AddNewWord AD=new AddNewWord();
    int m;
    int q;
    JTextField jtfa;
    JTextField jtfd;
    JTextField jtfe;
    JButton jba; 
    JButton jbf;
    JButton jbg;
    JButton jbh;
    JButton jbi;
    JTextField jtfb; 
    JButton jbb; 
    JButton jbc; 
    JTextArea jta; 
    JTextField jtfc; 
    JButton jbd; 
    JButton jbe; 
     public  void creatAndShoeGUI() 
     { 
         JFrame.setDefaultLookAndFeelDecorated(false); 
         JFrame frame=new JFrame("搜索器"); 
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
          
         final JFileChooser fc = new JFileChooser(); 
         fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 
        
         Container con = frame.getContentPane(); 
         con.setLayout(new BorderLayout()); 
          
         JPanel jpup = new JPanel();
         JPanel jpup1 = new JPanel();
         GridLayout grid;
         grid=new GridLayout(3,3);
         jpup.setLayout(grid);
         jpup1.setLayout(new GridLayout(1,2));
        
         jtfa=new JTextField(30);
         jtfe=new JTextField(30);
         jtfd=new JTextField(30);
         jba=new JButton("选择索引的存放路径");
         jba.addActionListener(new ActionListener() 
                               { 
                                 public void actionPerformed(ActionEvent e) 
                                 { 
                                     int r=fc.showOpenDialog(null); 
                                     if(r==JFileChooser.APPROVE_OPTION) 
                                     { 
                                         jtfa.setText(fc.getSelectedFile().getPath()); 
                                     } 
                                 } 
                              }); 
         jbc=new JButton("选择文件的存放路径");
         jbh=new JButton("添加到词库");
         jbh.addActionListener( 
                 new ActionListener() 
                 { 
                     public void actionPerformed(ActionEvent e) 
                     { 
                         try{ 
                          AD.w=jtfe.getText();
                          AD.kks();
                        } 
                        catch(Exception ex){ 
                             JOptionPane.showMessageDialog(null,"添加失败","提示",JOptionPane.ERROR_MESSAGE); 
                        } 
                     } 
                 }); 
         jpup1.add(jtfe);
         jpup1.add(jbh);
         jbi=new JButton("搜索xml文件");
         jbi.addActionListener( 
                 new ActionListener() 
                 { 
                     public void actionPerformed(ActionEvent e) 
                     { 
                         try{ 
                          XMLS.word  = jtfb.getText();
                          //q=XMLS.p;
                          XMLS.kss();
                          jta.setText("共搜到"+XMLS.p+"条结果 : "+"\n"+XMLS.SB1+"\n");
                        } 
                        catch(Exception ex){ 
                             JOptionPane.showMessageDialog(null,"搜索失败","提示",JOptionPane.ERROR_MESSAGE); 
                        } 
                     } 
                 }); 
         jbc.addActionListener(new ActionListener() 
                               { 
                                 public void actionPerformed(ActionEvent e) 
                                 { 
                                     int r=fc.showOpenDialog(null); 
                                     if(r==JFileChooser.APPROVE_OPTION) 
                                     { 
                                         jtfd.setText(fc.getSelectedFile().getPath()); 
                                     } 
                                 } 
                              }); 
         jtfb=new JTextField(30); 
         jbf=new JButton("创建索引");
         jbf.addActionListener( 
                 new ActionListener() 
                 { 
                     public void actionPerformed(ActionEvent e) 
                     { 
                         try{ 
                             String indexPath=jtfa.getText();  
                             String testfile=jtfd.getText();
                             JS.CreatIndex( indexPath,testfile,"jim");
                             jta.setText("创建成功");
                        } 
                        catch(Exception ex){ 
                             JOptionPane.showMessageDialog(null,"创建失败!","提示",JOptionPane.ERROR_MESSAGE); 
                        } 
                     } 
                 }); 
         jbb=new JButton("搜索"); 
         jbb.addActionListener( 
                 new ActionListener() 
                 { 
                     public void actionPerformed(ActionEvent e) 
                     { 
                         try{ 
                             //String indexPath=jtfa.getText(); 
                             JS.word  = jtfb.getText(); 
                             //JS.CreatIndex( indexPath,"testFiles","jim");
                             JS.ks();
                             m=JS.n;
                             jta.setText("共搜到"+m+"条结果 : "+"\n"+JS.SB+"\n");
                         } 
                        catch(Exception ex){ 
                             JOptionPane.showMessageDialog(null,"搜索失败!","提示",JOptionPane.ERROR_MESSAGE); 
                         } 
                     } 
                 }); 
         jpup.add(jtfa); 
         jpup.add(jba);
         jpup.add(jbf);
         jpup.add(jtfd);
         jpup.add(jbc);
         jpup.add(jpup1);
         jpup.add(jtfb); 
         jpup.add(jbb);
         jpup.add(jbi);
        
         //jpup.add(jbg);
         jta=new JTextArea(10,30); 
         JScrollPane jsp=new JScrollPane(jta); 
         JPanel jpdown = new JPanel(); 
         jpdown.setLayout(new FlowLayout()); 
         jtfc=new JTextField(35); 
         jbd=new JButton("设定导出路径"); 
         fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); 
         jbd.addActionListener( 
                 new ActionListener() 
                 { 
                     public void actionPerformed(ActionEvent e) 
                     { 
                         int r = fc.showOpenDialog(null); 
                        if(r==JFileChooser.APPROVE_OPTION) 
                         { 
                             jtfc.setText(fc.getSelectedFile().getPath()); 
                         } 
                     } 
                 } 
                 ); 
         jbe=new JButton("导出搜索结果"); 
        jbe.addActionListener( 
                new ActionListener() 
                { 
                     public void actionPerformed(ActionEvent e) 
                     { 
                         try 
                        { 
                             File f =new File(jtfc.getText()); 
                             FileWriter fw = new FileWriter(f); 
                             PrintWriter pw = new PrintWriter(fw); 
                             pw.write(jta.getText()); 
                             pw.flush(); 
                             pw.close(); 
                             JOptionPane.showMessageDialog(null, "写入文件成功","提示",JOptionPane.INFORMATION_MESSAGE); 
                         } 
                        catch(IOException ioe){ 
                             JOptionPane.showMessageDialog(null, "写入文件失败","提示",JOptionPane.INFORMATION_MESSAGE); 
                         } 
                     } 
                 } 
                 ); 
                 jpdown.add(jtfc); 
                 jpdown.add(jbd); 
                 jpdown.add(jbe); 
                 
                 con.add(jpup,BorderLayout.NORTH); 
                 con.add(jsp,BorderLayout.CENTER); 
                 con.add(jpdown,BorderLayout.SOUTH); 
                  
                 frame.setSize(200, 100); 
                 frame.pack(); 
                 frame.setVisible(true); 
     } 
     public static void main(String args[]){
   SwingUtilities.invokeLater(new Runnable()
   {
    public void run()
    {
     new jiemian().creatAndShoeGUI();
    }
   }
   );
  }
}

你可能感兴趣的:(jsp,exception,String,File,null,Lucene)