-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextOutputScroll.java
65 lines (48 loc) · 1.06 KB
/
TextOutputScroll.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
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TextOutputScroll extends JFrame{
JTextArea textArea;
JPanel panel;
JScrollPane scrollPane;
TextOutputScroll(String title)
{
setTitle(title);
textArea= new JTextArea(20,40);
textArea.setEditable(false);
textArea.setLineWrap(true);
panel=new JPanel();
scrollPane=new JScrollPane(textArea);
panel.add(scrollPane);
add(panel);
pack();
}
StringBuffer output=new StringBuffer();
void print(String s)
{
output.append(s);
textArea.setText(output.toString());
textArea.setCaretPosition(textArea.getDocument().getLength());
}
void println(String s)
{
print(s+"\n");
}
public static void main(String[] args)
{
try{
TextOutputScroll myPrinter= new TextOutputScroll("TEST");
myPrinter.setVisible(true);
int in;
while( (in=System.in.read()) >= 0 )
{
myPrinter.print(String.valueOf((char) in));
}
System.exit(0);
}
catch(Exception e)
{
System.out.println(e);
}
}
}