-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHistory.java
More file actions
executable file
·63 lines (56 loc) · 1.58 KB
/
History.java
File metadata and controls
executable file
·63 lines (56 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import java.awt.*;
import java.awt.event.*;
import java.io.*;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author yao
*/
public class History extends Frame{
private TextArea textarea;
public History(String receiver){
setLayout(null);
setResizable(false);
textarea = new TextArea("", 7, 45,TextArea.SCROLLBARS_BOTH);
textarea.setBounds(20, 50, 330, 340);
add(textarea);
setSize(400, 400);
setTitle("Chat Log");
setVisible(true);
textarea.setEditable(false);
setBackground(Color.gray);
this.addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(
WindowEvent e){
setVisible(false);
}
}
);
readHistory(receiver);
}
public void readHistory(String receiver){
File file = new File(receiver);
if (!file.exists()) {
System.out.println("Log.txt does not exist.");
return;
}
if (!(file.isFile() && file.canRead())) {
System.out.println(file.getName() + " cannot be read from.");
return;
}
try {
FileInputStream fis = new FileInputStream(file);
char current;
while (fis.available() > 0) {
current = (char) fis.read();
this.textarea.append(Character.toString(current));
}
} catch (IOException e) {
e.printStackTrace();
}
}
}