📄 viewlogaction.java
字号:
package view.control.viewaction;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import view.dialog.log.ViewLog;
public class ViewLogAction implements ActionListener, ItemListener {
private ViewLog log = null;
public static String logfilename;
public ViewLogAction(ViewLog log) {
this.log = log;
}
public void OpenLog() {
try {
FileInputStream reader = new FileInputStream(new File("日志文件//"
+ logfilename));
StringBuffer strbuff = new StringBuffer();
BufferedInputStream in = new BufferedInputStream(reader);
byte[] b = new byte[1024];
int len;
while ((len = in.read(b)) != -1) {
strbuff.append(new String(b, 0, len));
}
log.setText(strbuff.toString());
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();
}
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("退出")) {
log.dispose();
} else if (e.getActionCommand().equals("打开日志文件")) {
OpenLog();
}
}
public void itemStateChanged(ItemEvent e) {
logfilename = log.getSelectItem();
OpenLog();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -