-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConsole.java
68 lines (52 loc) · 1.41 KB
/
Console.java
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
64
65
66
67
68
package boardgame.gui;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import javax.swing.JFrame;
import javax.swing.JTextArea;
/*
* Class to create a custom output stream as a text area
*/
public class Console extends JTextArea{
private PrintStream out;
public Console () {
this.setEditable(false);
out = new PrintStream( new CustomOutputStream(this));
}
public Console (String text) {
super(text);
this.setEditable(false);
out = new PrintStream( new CustomOutputStream(this));
}
public PrintStream getPrintStream() {
return out;
}
// @Override
// public Dimension getMinimumSize() {
// return new Dimension(500, 100);
// }
//
// public Dimension getMaximumSize() {
// return new Dimension(500, 100);
// }
//
// @Override
// public Dimension getPreferredSize() {
// return new Dimension(500, 100);
// }
public class CustomOutputStream extends OutputStream {
private JTextArea textArea;
public CustomOutputStream(JTextArea textArea) {
this.textArea = textArea;
}
@Override
public void write(int b) throws IOException {
// redirects data to the text area
textArea.append(String.valueOf((char)b));
// scrolls the text area to the end of data
textArea.setCaretPosition(textArea.getDocument().getLength());
}
}
}