java记事本替换功能 像windows自带那样的,以前C#的多好写,将替换的文本赋值给RichTextBox的选中文本,求代码例子 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://hi.baidu.com/freish/blog/item/21a604f7c0271b28730eec61.html public ReplaceDialog(JTextArea text, Frame parent, String title, boolean modal) { super(parent, title, modal); this.txtOwner = text; JPanel pBottom = new JPanel(); btnSearch = new JButton("查找"); btnSearch.addActionListener(this); btnReplace = new JButton("替换"); btnReplace.addActionListener(this); btnCancel = new JButton("取消"); btnCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub dispose(); } }); pBottom.add(btnSearch); pBottom.add(btnReplace); pBottom.add(btnCancel); this.add(pBottom, "South"); JPanel pTop = new JPanel(); pTop.add(new JLabel("查找的内容:")); txtSearch = new JTextField(15); pTop.add(txtSearch); this.add(pTop, "North"); JPanel pCenter = new JPanel(); pCenter.add(new JLabel("替换为:")); txtReplace = new JTextField(15); pCenter.add(txtReplace); this.add(pCenter); this.pack(); this.setLocationRelativeTo(parent); this.setResizable(false); this.setVisible(true); } public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() == btnSearch) { String source = txtOwner.getText(); String content = txtSearch.getText(); int start = txtOwner.getSelectionStart(); index = source.indexOf(content, start); if (index != -1) { txtOwner.select(index, content.length());//找到的话选中文本框的文字 } else {//找不到弹出对话框 InfoDialog info = new InfoDialog(this.txtSearch.getText(), this, "提示!!!", false); } } if(e.getSource()==btnReplace){ String replaced=txtReplace.getText(); String source=txtOwner.getText(); String content = txtSearch.getText(); int start = txtOwner.getSelectionStart(); index = source.indexOf(content, start); if (index != -1) { txtOwner.select(index, content.length());//找到的话选中文本框的文字 } } }这是我写的一部分,谁完成下替换 java必须捕捉的异常都有哪些 求助 如何监测java某个线程内存的占用情况啊? svn的问题 对象之间的关系 我该怎么改这段代码! 如何使用poi进行excel单元格的查找和替换 Oracle 10g的连接串怎么写? 关于Applet的问题,請教各位高手 我只是想写一个简单的java文件。请问forte的类路径该怎么设置的? 为啥加入监听器后,页面找不到,404了? 关于时间格式化问题 求解析HTML正则表达式
boolean modal) {
super(parent, title, modal);
this.txtOwner = text;
JPanel pBottom = new JPanel();
btnSearch = new JButton("查找");
btnSearch.addActionListener(this);
btnReplace = new JButton("替换");
btnReplace.addActionListener(this);
btnCancel = new JButton("取消");
btnCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
dispose();
} });
pBottom.add(btnSearch);
pBottom.add(btnReplace);
pBottom.add(btnCancel);
this.add(pBottom, "South"); JPanel pTop = new JPanel();
pTop.add(new JLabel("查找的内容:"));
txtSearch = new JTextField(15);
pTop.add(txtSearch);
this.add(pTop, "North"); JPanel pCenter = new JPanel();
pCenter.add(new JLabel("替换为:"));
txtReplace = new JTextField(15);
pCenter.add(txtReplace);
this.add(pCenter); this.pack();
this.setLocationRelativeTo(parent);
this.setResizable(false);
this.setVisible(true); } public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getSource() == btnSearch) { String source = txtOwner.getText();
String content = txtSearch.getText();
int start = txtOwner.getSelectionStart();
index = source.indexOf(content, start);
if (index != -1) {
txtOwner.select(index, content.length());//找到的话选中文本框的文字 } else {//找不到弹出对话框
InfoDialog info = new InfoDialog(this.txtSearch.getText(),
this, "提示!!!", false);
}
}
if(e.getSource()==btnReplace){
String replaced=txtReplace.getText();
String source=txtOwner.getText();
String content = txtSearch.getText();
int start = txtOwner.getSelectionStart();
index = source.indexOf(content, start);
if (index != -1) {
txtOwner.select(index, content.length());//找到的话选中文本框的文字 }
}
}
这是我写的一部分,谁完成下替换