一个包含简单查询的JAVA记事本 内容简单 初学者适用

源代码在线查看: tools.java

软件大小: 84 K
上传用户: aspen
关键词: JAVA 查询 初学者 记事本
下载地址: 免注册下载 普通下载 VIP

相关代码

				/*				 * Tools.java				 *				 * Created on 2008年4月17日, 上午10:03				 *				 * To change this template, choose Tools | Template Manager				 * and open the template in the editor.				 */								package note;								import javax.swing.JEditorPane;								/**				 *				 * @author soft01				 */				public abstract class Tools {				    //传入参数的解释				    //jEditorPane对象 string要查找的字符串 upOrLow大小写开启 danCi按单词模式				    //upOrDown向上或向下查询				    public static void find(JEditorPane jEditorPane, String string, 				            boolean upOrLow, boolean danCi, boolean upOrDown,				            int start, int end) {				        String text = jEditorPane.getText ();				        int index = 0;				        //忽略大小写				        if (upOrLow == true) {				            text = text.toLowerCase ();				            string = string.toLowerCase ();				        }				        //向上				        if (upOrDown == true) {				            index = text.lastIndexOf (string, start - 1);				        } else {				            //向下				            index = text.indexOf (string, end);				        }				        //如果没找到				        if (index == -1)				            return;				        //匹配单词				        if (danCi == true) {				            //单词的前一个字符				            String CharStartOfDanCi;				            if (index != 0)				                CharStartOfDanCi = text.substring (index - 1, index);				            else CharStartOfDanCi = " ";				            //单词的后一个字符				            String CharEndOfDanCi;				            if ((index + string.length () != text.length ())) 				                CharEndOfDanCi = text.substring (index + string.length (), index + string.length () + 1);				            else  CharEndOfDanCi = " ";				            //开始匹配				            if (CharStartOfDanCi.matches ("\\w") || CharEndOfDanCi.matches ("\\w")) {				                if (upOrDown == true)				                    Tools.find (jEditorPane, string, upOrLow, danCi, upOrDown,				                        index - 1, index - 1);				                else Tools.find (jEditorPane, string, upOrLow, danCi, upOrDown,				                        index + 1, index + 1);				                return;				            }				        }				        //显示找到的单词				        jEditorPane.select (index, index + string.length ());				    }				}			

相关资源