?? replace.java
字號:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class replace extends searchString implements ActionListener{
GUI gui;
JDialog jdg=new JDialog(GUI.jf,"查找"); //對話框
JTextField jtfsearch=new JTextField(); //被替換文本
JTextField jtfreplace=new JTextField(); //替換文本
JButton jbnext=new JButton("查找下一個");
JButton jbreplace=new JButton("替換");
JButton jbreplaceall=new JButton("全部替換");
JButton jbcancel=new JButton("取消");
JCheckBox div=new JCheckBox("區分大小寫"); //復選框
//
public replace(GUI gui)
{
this.gui=gui;
//構造布局
JPanel p1=new JPanel(new BorderLayout());
p1.add(new JLabel("查找內容 :"),BorderLayout.WEST);
p1.add(jtfsearch,BorderLayout.CENTER);
jtfsearch.setText(searchString.jtf.getText());
//
JPanel p2=new JPanel(new BorderLayout());
p2.add(new JLabel(" 替換為 :"),BorderLayout.WEST);
p2.add(jtfreplace,BorderLayout.CENTER);
//
JPanel p10=new JPanel(new GridLayout(3,1));
p10.add(p1);
p10.add(p2);
//
JPanel p11=new JPanel(new BorderLayout());
p11.add(p10,BorderLayout.CENTER);
p11.add(div,BorderLayout.SOUTH);
//
JPanel p12=new JPanel(new GridLayout(4,1));
jbnext.addActionListener(this);
jbreplace.addActionListener(this);
jbreplaceall.addActionListener(this);
jbcancel.addActionListener(this);
p12.add(jbnext);
p12.add(jbreplace);
p12.add(jbreplaceall);
p12.add(jbcancel);
//對話框設置
jdg.setLayout(new BorderLayout());
jdg.add(p11,BorderLayout.CENTER);
jdg.add(p12,BorderLayout.EAST);
jdg.setSize(250, 130);
jdg.setLocation(GUI.jf.getX()+(GUI.jf.getWidth()-jdg.getWidth())/2,
GUI.jf.getY()+(GUI.jf.getHeight()-jdg.getHeight())/2 );
jdg.setVisible(true);
}
//事件處理
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==jbnext)
{//按鈕 "查找下一個"
//獲取起始查找位置
int i=GUI.jt.getCaret().getDot()+
cal10( GUI.jt.getText().substring(0,GUI.jt.getCaret().getDot()) )+1;
//向后尋找
findnext(GUI.jt.getText(),i,searchString.jtf.getText(),div.isSelected());
}
else if(e.getSource()==jbreplace)
{//按鈕 "替換"
if(GUI.jt.getSelectionStart()-GUI.jt.getSelectionEnd()!=0)
{//有選中的字符串
//替換
GUI.jt.replaceSelection( jtfreplace.getText() );
}
//獲取起始查找位置
int i=GUI.jt.getCaret().getDot()+
cal10( GUI.jt.getText().substring(0,GUI.jt.getCaret().getDot()) )+1;
//向后尋找
findnext(GUI.jt.getText(),i,searchString.jtf.getText(),div.isSelected());
}
else if(e.getSource()==jbreplaceall)
{//按鈕 "替換全部"
GUI.jt.setText(
GUI.jt.getText().replace(
this.jtfsearch.getText(), this.jtfreplace.getText())
);
}
//按鈕 "取消"
else if(e.getSource()==jbcancel)
{
jdg.setVisible(false);
jdg.dispose();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -