读书人

程序一:请看看为什么出错

发布时间: 2012-05-14 15:24:34 作者: rapoo

程序一:请各位高手看看,为什么出错
package jim.searcher;

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;
JTextField jtfa;
JButton jba;
JTextField jtfb;
JButton jbb;
JButton jbc;
JTextArea jta;
JTextField jtfc;
JButton jbd;
JButton jbe;
public void creatAndShoeGUI()
{
JFrame.setDefaultLookAndFeelDecorated(true);
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();
jpup.setLayout(new GridLayout(2,2));
jtfa=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());
}
}
});
jtfb=new JTextField(30);
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();///
}
catch(Exception ex){
JOptionPane.showMessageDialog(null,"搜索失败!","提示",JOptionPane.ERROR_MESSAGE);
}
}
});
jpup.add(jtfa);
jpup.add(jba);
jpup.add(jtfb);
jpup.add(jbb);
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();
}
}
);
}
}


[解决办法]
为什么出错 ,你直接把你的运行结果发出来,即 你编译或者运行的后台信息发出来,更直接

读书人网 >J2SE开发

热点推荐