數(shù)據(jù)加載中……
          高手幫我看看這程序是哪里出了問題?

          package SimpleSearcher;
          import java.awt.*;
          import java.awt.event.*;
          import java.io.IOException;

          import javax.swing.*;
          public class SimpleSearcherFrame {
          JFrame jf=new JFrame("SimpleSearcher");
          JTextArea jta;
          JLabel l1,l2;
          JPanel p;
          JTextField tf1,tf2;
          JScrollPane  jp;
          JButton b1,b2,b3;
          FileDialog fd;
          String keyword,parent,child,path=new String();
          public void go() throws IOException{
          l1=new JLabel("請(qǐng)輸入文件所在位置");
          tf1=new JTextField(20);
          tf1.setEditable(true);
          l2=new JLabel("請(qǐng)輸入查詢的關(guān)鍵字");
          tf2=new JTextField(20);
          tf2.setEditable(true);
          keyword=tf2.getText();
          {fd=new FileDialog(jf,"打開文件位置");

          jta=new JTextArea(300,100);
          jp=new  JScrollPane(jta,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
          b1=new JButton("打開文件位置");
          b1.addActionListener(new ActionListener()
          {
          public void actionPerformed(ActionEvent e){
          fd.setVisible(true);
          parent=fd.getDirectory();
          child=fd.getFile();
          path=parent+child;
          tf1.setText(path);
          }
          }
          );
          b2=new JButton("查詢");
          b3=new JButton("清空");
          b3.addActionListener(new ActionListener()
          {
           public  void actionPerformed(ActionEvent e){
          jta.setText(null); 
           }
          });
          p=new JPanel();
          p.add(l1);
          p.add(tf1);
          p.add(b1);
          p.add(tf2);
          p.add(b2);
          Container cp=jf.getContentPane();
          cp.add(p,BorderLayout.NORTH);
          cp.add(jta,BorderLayout.CENTER);
          cp.add(b3,BorderLayout.SOUTH);
          jf.pack();
          jf.setVisible(true);
          SimpleSearcherCode ssc=new SimpleSearcherCode();
          String s=ssc.search(keyword,path);
          jta.append(s);
          }
          }

          }
          package SimpleSearcher;
          import java.io.*;
          class SimpleSearcherCode
          {
           public String  search(String keyword,String path) throws IOException
          {
             FileReader fr = new FileReader(path);
             BufferedReader reader=new BufferedReader(fr);
             int line=0;int mark=0;String s1[]=new String[300];int i=0;
               while(reader.readLine()!=null)
               {
                line++;
                int start=0;
                while(reader.readLine().indexOf(keyword, start)!=-1){
                start=reader.readLine().indexOf(keyword,start);
                mark++;
                s1[i]= keyword+"在第"+line+"第"+start+"位置";
                i++;
                }
               }
            String s2="文件中一共搜到"+mark+"個(gè)關(guān)鍵字";
               if(mark==0)
               {
                return "文件中沒有相關(guān)內(nèi)容";
               }
               else {for(int j=0;j<i;j++)
                s2+=s1[i];
               return s2;
               }
          }
          }


          package SimpleSearcher;

          import java.io.IOException;

          public class Searching {
          public static void main(String args[]) throws IOException
          {
          SimpleSearcherFrame ssf =new SimpleSearcherFrame();
          ssf.go();
          }
          }
          界面沒什么問題,主要是在文件流的轉(zhuǎn)換上不知道哪里不匹配,老是說沒實(shí)例化。

          posted on 2011-04-19 00:57 失眠患者 閱讀(138) 評(píng)論(1)  編輯  收藏

          評(píng)論

          # re: 高手幫我看看這程序是哪里出了問題? 2011-04-19 01:05 失眠患者

          我發(fā)現(xiàn)了,小錯(cuò)誤,還看了半天。。。。

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 南阳市| 曲松县| 井冈山市| 拜城县| 新兴县| 荣昌县| 农安县| 南川市| 通渭县| 喀喇| 武强县| 抚顺市| 九江市| 涡阳县| 罗源县| 东台市| 孟州市| 嘉善县| 桃园市| 平凉市| 若尔盖县| 东平县| 内丘县| 渝中区| 四会市| 射阳县| 那曲县| 天长市| 都江堰市| 进贤县| 壤塘县| 呼和浩特市| 伊金霍洛旗| 阿克陶县| 黎川县| 武宁县| 双牌县| 迭部县| 永德县| 和静县| 奇台县|