java做的简单记事本范文

{

text.setFont(new Font(Str1,Font.PLAIN,15)); text.setForeground(Color.black); text.setText(\ } try {

if(strCmd.equals(\打开\ {

openFile(); }

if(strCmd.equals(\保存\ {

saveFile(); }

}catch(IOException e1){} if(strCmd.equals(\退出\ {

System.exit(0); }

if(strCmd.equals(\全选\ {

16

}

text.selectAll();

if(strCmd.equals(\清空\{ }

text.setText(\

if(strCmd.equals(\复制\ {

str=text.getSelectedText(); }

if(strCmd.equals(\粘贴\ {

text.insert(str,text.getCaretPosition()); }

if(strCmd.equals(\剪切\ {

str=text.getSelectedText();

text.replaceRange(\

}

if(strCmd.equals(\字体\

17

{

d.setVisible(true); }

if(strCmd.equals(\颜色选择\ {

\

Color c=JColorChooser.showDialog(this,\颜色选择 text.setForeground(c); Red=c.getRed(); Green=c.getGreen(); Blue=c.getBlue(); }

if(e.getSource()==tFind||e.getSource()==bFind) { find(); return; } if(e.getSource()==tReplace||e.getSource()==bReplace) {

text.requestFocus();

18

String s1=tReplace.getText();

if (text.getSelectedText().equals(tFind.getText())) {

int start=text.getSelectionStart(); text.replaceRange(s1, text.getSelectionStart(), text.getSelectionEnd());

text.select(start,start+s1.length()); } else

find(); return; }

if(e.getSource()==bReplaceAll) {

text.requestFocus();

String s1=tReplace.getText(); str = text.getText();

String strFind = tFind.getText(); int start = 0; int end = str.length();

19

int len = strFind.length(); int count=0; if (start<=end-len) {

for (;start <= end - len; start++) { if len).equals(strFind)) {

count++;

text.replaceRange(s1, start,start + len);

text.select(start,start+s1.length()); } } }

if(count==0)

JOptionPane.showConfirmDialog(findD,\没有找到!\替换提示\ else

JOptionPane.showConfirmDialog(findD,\共替换字

\

.\

(str.substring(start,

start

+

\

20

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4