⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 search.java

📁 在java环境下开发的一个笔记记录及管理工具
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package stageexperiment;import javax.swing.*;import java.awt.event.*;import java.io.BufferedReader; import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;import java.util.logging.Level;import java.util.logging.Logger;/** * * @author lina */public class Search extends JFrame {       int x;     String  t;     String  w;     String  f;     String  p;     String k;     String r;    JLabel  topic;    JLabel  writer;    JLabel  filename;    JLabel  path;    JLabel keyword;    JLabel remark;      JTextField jTextFieldtopic;    JTextField jTextFieldwriter;    JTextField jTextFieldfilename;    JTextField jTextFieldpath;    JTextField jTextFieldkeyword;    JTextField jTextFieldremark;    JButton search;    JButton exit;    Notes n=new Notes();  public Search(final AllNotes an,final Main m)  {             this.setLayout(null);//设置布局管理器为null    	//初始化各个控件    	topic=new JLabel("题目");    	writer=new JLabel("作者");    	filename=new JLabel("笔记文件名");        path=new JLabel("路径");        keyword=new JLabel("关键词");        remark=new JLabel("备注");    	jTextFieldtopic=new JTextField();        jTextFieldwriter=new JTextField();        jTextFieldfilename=new JTextField();        jTextFieldpath=new JTextField();        jTextFieldkeyword=new JTextField();        jTextFieldremark=new JTextField();    	search= new JButton("确定");    	exit=new JButton("取消");    	//设置控件位置    	this.topic.setBounds(10,10,80,20);        this.filename.setBounds(10,50,80,20);    	this.keyword.setBounds(10,130,80,20);        this.path.setBounds(10,170,80,20);    	this.remark.setBounds(10,210,80,20);    	this.writer.setBounds(10,90,80,20);        this.jTextFieldtopic.setBounds(100,10,150,20);    	this.jTextFieldfilename.setBounds(100,50,150,20);        this.jTextFieldkeyword.setBounds(100,130,150,20);        this.jTextFieldpath.setBounds(100,170,150,20);        this.jTextFieldremark.setBounds(100,210,150,20);        this.jTextFieldwriter.setBounds(100,90,150,20);        this.search.setBounds(50, 250, 100, 30);        this.exit.setBounds(150, 250, 100, 30);    	//将控件添加到面板上    	this.add(topic);        this.add(filename);      	this.add(keyword);     	this.add(path);     	this.add(remark);    	this.add(writer);    	this.add(jTextFieldtopic);        this.add(jTextFieldfilename);    	this.add(jTextFieldkeyword);    	this.add(jTextFieldpath);    	this.add(jTextFieldremark);    	this.add(jTextFieldwriter);    	this.add(search);        this.add(exit);     	this.setBounds(330,300,300,350);    	this.setTitle("输入查找条件");      	this.setVisible(true);    search.addActionListener(new ActionListener()     {public void actionPerformed(ActionEvent e)       {  int i=0,j=0;          t=jTextFieldtopic.getText();          w=jTextFieldwriter.getText();          f=jTextFieldfilename.getText();          p=jTextFieldpath.getText();          k=jTextFieldkeyword.getText();          r=jTextFieldremark.getText();          if(f.equals("")&&k.equals("")&&p.equals("")&&r.equals("")&&t.equals("")&&w.equals(""))             { JOptionPane.showMessageDialog(null,"查询条件不能为空","错误",JOptionPane.INFORMATION_MESSAGE);i=1;}          else           {              for(i=0;i<an.getLength();i++)              { if((f.equals("")||f.equals(an.all[i].filename))&&(k.equals("")||k.equals(an.all[i].keyword))&&(p.equals("")||p.equals(an.all[i].path))&&(r.equals("")||r.equals(an.all[i].remark))&&(t.equals("")||t.equals(an.all[i].topic))&&(w.equals("")||w.equals(an.all[i].writer)))                {j++;x=i;}               }             if(j==0)               {                 JOptionPane.showMessageDialog(null,"没有你想要的笔记记录","未找到",JOptionPane.INFORMATION_MESSAGE);i=0;                }             if(j==1)               { n=an.all[x];                 JOptionPane.showMessageDialog(null,"确定查看","查询成功",JOptionPane.INFORMATION_MESSAGE);i=0;               }             if(j>1){ JOptionPane.showMessageDialog(null,"查询到多个结果,请输入更详细信息继续查找","注意",JOptionPane.INFORMATION_MESSAGE);i=1;}          }          if(i==0)          {           String str="",s;           BufferedReader output=null;                try {                    m.jTextFieldtopic.setText(n.topic);                     m.jTextFieldwriter.setText(n.writer);                    m.jTextFieldftime.setText(n.ftime);                    File readSource = new File(n.path,n.filename);                    output = new BufferedReader(new FileReader(readSource));                    try {                        while ((s = output.readLine()) != null) {                            str += s+"\r\n";                        }                        m.text.setText(str); output.close();                    } catch (IOException ex) {                        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);                    }                } catch (FileNotFoundException ex) {                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);                }            setVisible(false);}        }    });   exit.addActionListener(new ActionListener()      {public void actionPerformed(ActionEvent e)       {            setVisible(false);          }    });  }  public Notes searched(){return n;} }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -