📄 notepad_openfile.java
字号:
/**
*
*/
package com.edu.sccp.snail.notepad.view;
/**
* @author 小豆包
* @return 文件打开事件
* @time 2008-1-7
*/
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.JFileChooser;
import com.edu.sccp.snail.notepad.interfaces.Notepad_File;
public class Notepad_OpenFile implements Notepad_File{
JFileChooser filechooser = new JFileChooser();
Notepad_newFile nf = null;
Notepad_Main parent = null; //穿过来的父窗体
File file = null;
FileReader fr = null;
/**
* 构造函数传过来的父窗体
* @param parner
*/
public Notepad_OpenFile(Notepad_Main parent){
this.parent = parent;
nf = new Notepad_newFile("");
JFileChooser filechooser = new JFileChooser();
filechooser.setSelectedFile(file);
filechooser.addChoosableFileFilter(new Notepad_FileFilter("jsp"));
filechooser.addChoosableFileFilter(new Notepad_FileFilter("html"));
filechooser.addChoosableFileFilter(new Notepad_FileFilter("txt"));
filechooser.addChoosableFileFilter(new Notepad_FileFilter("java"));
int returnVal = filechooser.showOpenDialog(parent.notepad);
if (returnVal == JFileChooser.APPROVE_OPTION) {
file = filechooser.getSelectedFile();
this.Notepad_FileOpen(nf, file);
}else{
return;
}
}
/**
* 实现接口所作的就是保存打开和另存为
*/
public void Notepad_FileOpen(Notepad_newFile nf, File file) {
/**
* 打开一个文件然后创建一个新的Notepad_newFile();
* 然后更新Notepad_main();
* 并且将这个打开制定文件的Notepad_newFile()对象;
*/
//代码
this.nf = nf;
String file_path = null;
String str = null;
if(file !=null){
try {
file_path = file.getAbsolutePath();
nf.setTitle(file.getName()+"---"+file_path);
fr = new FileReader(new File(file.getPath()));
/**
* 读数据
*/
int rd;
rd = fr.read();
while(rd != -1){
str = str + (char)rd;
rd = fr.read();
}
nf.jta.append(str);
parent.jp1.add(nf);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try{
fr.close();
}catch(IOException e){
e.printStackTrace();
}
}
}
}
public void Notepad_FileSave(Notepad_Main notepad_main, File file) {
}
public void Notepad_File_OrtherSave(Notepad_Main notepad_main, File file) {
}
public void Notepad_File_TreeOpenFile(Notepad_Main notepad_main, Notepad_newFile nnf, File file) throws IOException {
}
public void Notepad_File_TreeNewFile(Notepad_Main notepad_main, Notepad_newFile nnf, File file) throws IOException {
// TODO Auto-generated method stub
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -