77范文网 - 专业文章范例文档资料分享平台

JAVA记事本(6)

来源:网络收集 时间:2018-12-20 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

}

//粘帖功能可用性判断

Transferable contents=clipBoard.getContents(this); if(contents==null) { } else { }

editMenu_Paste.setEnabled(true); popupMenu_Paste.setEnabled(true); editMenu_Paste.setEnabled(false); popupMenu_Paste.setEnabled(false);

}//方法checkMenuItemEnabled()结束

//关闭窗口时调用

public void exitWindowChoose() {

editArea.requestFocus();

String currentValue=editArea.getText(); if(currentValue.equals(oldValue)==true) { } else {

int exitChoose=JOptionPane.showConfirmDialog(this,\您的文件尚未System.exit(0);

保存,是否保存?\退出提示\

if(exitChoose==JOptionPane.YES_OPTION) {

//boolean isSave=false; if(isNewFile) {

String str=null;

JFileChooser fileChooser=new JFileChooser();

fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

22

fileChooser.setApproveButtonText(\确定\fileChooser.setDialogTitle(\另存为\

int result=fileChooser.showSaveDialog(this); if(result==JFileChooser.CANCEL_OPTION) { }

statusLabel.setText(\ 您没有保存文件\return;

File saveFileName=fileChooser.getSelectedFile();

if(saveFileName==null||saveFileName.getName().equals(\{

JOptionPane.showMessageDialog(this,\不合法的文件名

\不合法的文件名\

} else {

try {

FileWriter fw=new FileWriter(saveFileName); BufferedWriter bfw=new BufferedWriter(fw);

bfw.write(editArea.getText(),0,editArea.getText().length());

isNewFile=false;

currentFile=saveFileName; oldValue=editArea.getText();

this.setTitle(saveFileName.getName()+\ - 记事本\statusLabel.setText(\

bfw.flush(); fw.close();

件:\

}

//isSave=true;

23

}

}

}

}

catch(IOException ioException){ }

else { }

System.exit(0);

//if(isSave)System.exit(0); //else return;

try { }

FileWriter fw=new FileWriter(currentFile); BufferedWriter bfw=new BufferedWriter(fw);

bfw.write(editArea.getText(),0,editArea.getText().length()); bfw.flush(); fw.close(); //isSave=true;

catch(IOException ioException){ }

else if(exitChoose==JOptionPane.NO_OPTION) { } else { }

return; System.exit(0);

}//关闭窗口时调用方法结束

24

//查找方法 public void find() {

final JDialog findDialog=new JDialog(this,\查找\时允许其他

窗口同时处于激活状态(即无模式)

Container con=findDialog.getContentPane();//返回此对话框的contentPane

con.setLayout(new FlowLayout(FlowLayout.LEFT)); JLabel findContentLabel=new JLabel(\查找内容(N):\final JTextField findText=new JTextField(15);

JButton findNextButton=new JButton(\查找下一个(F):\

final JCheckBox matchCheckBox=new JCheckBox(\区分大小写(C)\ButtonGroup bGroup=new ButtonGroup();

final JRadioButton upButton=new JRadioButton(\向上(U)\final JRadioButton downButton=new JRadioButton(\向下(U)\downButton.setSelected(true); bGroup.add(upButton); bGroup.add(downButton);

/*ButtonGroup此类用于为一组按钮创建一个多斥(multiple-exclusion)

对象

作用域。

使用相同的 ButtonGroup 对象创建一组按钮意味着“开启”其中一个按

钮时,将关闭组中的其他所有按钮。*/

/*JRadioButton此类实现一个单选按钮,此按钮项可被选择或取消选择,

并可为用户显示其状态。

与 ButtonGroup 对象配合使用可创建一组按钮,一次只能选择其中的一

个按钮。

(创建一个 ButtonGroup 对象并用其 add 方法将 JRadioButton 对象

包含在此组中。)*/

JButton cancel=new JButton(\取消\//取消按钮事件处理

cancel.addActionListener(new ActionListener()

25

{ });

public void actionPerformed(ActionEvent e) { }

findDialog.dispose();

//\查找下一个\按钮监听

findNextButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

//\区分大小写(C)\的JCheckBox是否被选中 int k=0,m=0;

final String str1,str2,str3,str4,strA,strB; str1=editArea.getText(); str2=findText.getText(); str3=str1.toUpperCase(); str4=str2.toUpperCase();

if(matchCheckBox.isSelected())//区分大小写 { }

else//不区分大小写,此时把所选内容全部化成大写(或小写),以便

strA=str1; strB=str2;

于查找

{ }

if(upButton.isSelected()) {

//k=strA.lastIndexOf(strB,editArea.getCaretPosition()-1); if(editArea.getSelectedText()==null)

k=strA.lastIndexOf(strB,editArea.getCaretPosition()-1); strA=str3; strB=str4;

else

k=strA.lastIndexOf(strB,

editArea.getCaretPosition()-findText.getText().length()-1);

26

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库JAVA记事本(6)在线全文阅读。

JAVA记事本(6).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/378684.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: