void replace() {// 替换对话框，添加监听器并重写actionPerformed方法
		JFrame jr = new JFrame("替代");
		JLabel jl1 = new JLabel("查找：");
		JLabel jl2 = new JLabel("替换为：");
		final JTextField jtf1 = new JTextField(10);
		final JTextField jtf2 = new JTextField(10);
		JButton jb1 = new JButton("替换/替换下一个");
		JButton jb2 = new JButton("全部替换");
		JPanel jp1 = new JPanel();
		JPanel jp2 = new JPanel();
		JPanel jp3 = new JPanel();
		jp1.add(jl1);
		jp1.add(jtf1);
		jp2.add(jl2);
		jp2.add(jtf2);
		jp3.add(jb1);
		jp3.add(jb2);
		jr.setLayout(new GridLayout(3, 1));
		jr.add(jp1);
		jr.add(jp2);
		jr.add(jp3);
		jr.setSize(400, 200);
		jr.setLocationRelativeTo(null);
		jr.setVisible(true);

		jb1.addActionListener(new ActionListener() {// 逐个替换
			public void actionPerformed(ActionEvent e) {
				String sfind = jtf1.getText();
				String sreplace = jtf2.getText();
				StyledDocument doc = textPane.getStyledDocument();
				String cur = "";
				try {
					cur = doc.getText(0, doc.getLength());
				} catch (BadLocationException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				if (cur.indexOf(sfind) == -1) {
					unfind();
					System.out.println("进入这里");
				} else {
					if (textPane.getCaretPosition() == cur.length()) {
						textPane.setCaretPosition(0);
					}
					textPane.setSelectionStart(cur.indexOf(sfind,
							textPane.getCaretPosition()));
					textPane.setSelectionEnd(cur.indexOf(sfind,
							textPane.getCaretPosition())
							+ sfind.length());
					textPane.replaceSelection(sreplace);
				}
			}
		});
		jb2.addActionListener(new ActionListener() {// 全部替换
			public void actionPerformed(ActionEvent e) {
				while (true) {
					String sfind = jtf1.getText();
					String sreplace = jtf2.getText();
					StyledDocument doc = textPane.getStyledDocument();
					String cur = "";
					try {
						cur = doc.getText(0, doc.getLength());
					} catch (BadLocationException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					if (cur.indexOf(sfind) == -1) {
						break;
					}
					textPane.setSelectionStart(cur.indexOf(sfind,
							textPane.getCaretPosition()));
					textPane.setSelectionEnd(cur.indexOf(sfind,
							textPane.getCaretPosition())
							+ sfind.length());
					textPane.replaceSelection(sreplace);
				}
			}
		});
	}