}
//粘帖功能可用性判断
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)在线全文阅读。
相关推荐: