-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplay1.java
73 lines (55 loc) · 1.87 KB
/
Display1.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
69
70
71
72
73
import java.awt.*;
import javax.swing.Timer; //for timer
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.IOException;
import java.util.*;
public class Display1
extends JPanel implements ActionListener {
JTextArea textArea;
Information server;
public Display1(Information server) {
super(new GridBagLayout());
textArea = new JTextArea(5, 20);
textArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textArea);
//Add Components to this panel.
GridBagConstraints c = new GridBagConstraints();
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.HORIZONTAL;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1.0;
c.weighty = 1.0;
add(scrollPane, c);
Timer timer = new Timer(500, this);
timer.start();
this.server = server;
}
public void actionPerformed(ActionEvent e) {
String newline = server.getMSG();
if(newline != null) {
textArea.append(newline + "\n");
//Make sure the new text is visible, even if there
//was a selection in the text area.
textArea.setCaretPosition(textArea.getDocument().getLength());
}
}
public static void main(String [] args) throws IOException {
//Create and set up the window.
JFrame frame = new JFrame("TextDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
StockDataBase allowedUsers = new StockDataBase("stocks.csv","Symbol","Security Name", "Price");
TestServer server = new TestServer(MainServer.BASE_PORT,
allowedUsers);
//Add contents to the window.
frame.add(new Display1(server));
//Display the window.
frame.pack();
frame.setVisible(true);
server.server_loop();
}
}