-
Notifications
You must be signed in to change notification settings - Fork 1
/
GUI.java
329 lines (303 loc) · 10.9 KB
/
GUI.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JTable;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.text.*;
import javax.swing.JLabel;
import javax.swing.JSlider;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import financialdata.*;
public class GUI extends JFrame implements ActionListener{
static GUI theGUI;
JPanel pnPanel0;
JTable tbFundementals;
JButton btSearch;
JTextArea taInput;
JLabel lbFundementals;
JTextField tfCurrentPrice;
JTextPane tpTicker;
JTextField tfPredictedPrice;
JLabel lbPredictedPrice;
JTextField tfName;
JButton btTrainNetwork;
JSlider sdWidth;
JLabel lbWidth;
JLabel lbDepth;
JSlider sdDepth;
JLabel lbIterations;
JSlider sdIterations;
JButton btLoadStocks;
String [][]dataFundementals = new String[][] { new String[] {"Volume", "21"},
new String[] {"PE Ratio", "22"},
new String[] {"Earnings per share", "23"},
new String[] {"52 Wk low", ""},
new String[] {"52 Wk high", ""},
new String[] {"Today's low", ""},
new String[] {"Today's high", ""},
new String[] {"Market cap", ""},
new String[] {"Short ratio", ""},
new String[] {"Previous close", ""},
new String[] {"Exchange", ""} };
static StyleContext sc = new StyleContext();
static final DefaultStyledDocument tickerBox = new DefaultStyledDocument(sc);
// public static void main(String args[])
// {
// // try
// // {
// // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
// // }
// // catch ( ClassNotFoundException e )
// // {
// // }
// // catch ( InstantiationException e )
// // {
// // }
// // catch ( IllegalAccessException e )
// // {
// // }
// // catch ( UnsupportedLookAndFeelException e )
// // {
// // }
// theGUI = new GUI();
// }
public void actionPerformed(ActionEvent e) {
if ("Search".equals(e.getActionCommand())){
NormalStock st = StockFetcher.getStock("AAPL");
dataFundementals[0][1] = Double.toString(st.getVolume());
dataFundementals[1][1] = Double.toString(st.getPe());
dataFundementals[2][1] = Double.toString(st.getEps());
dataFundementals[3][1] = Double.toString(st.getWeek52low());
dataFundementals[4][1] = Double.toString(st.getWeek52high());
dataFundementals[5][1] = Double.toString(st.getDaylow());
dataFundementals[6][1] = Double.toString(st.getDayhigh());
dataFundementals[7][1] = Double.toString(st.getMarketcap());
dataFundementals[8][1] = Double.toString(st.getShortRatio());
dataFundementals[9][1] = Double.toString(st.getPreviousClose());
dataFundementals[10][1] = st.getExchange();
}
if ("Train Network".equals(e.getActionCommand())){
DriverV2 driver = new DriverV2(80,3,100); //get parameters
}
if ("Load Stocks".equals(e.getActionCommand())){
DriverV2 driver = new DriverV2(80,3,100);
}
}
public GUI()
{
super("Neural network based stock price projection");
pnPanel0 = new JPanel();
GridBagLayout gbPanel0 = new GridBagLayout();
GridBagConstraints gbcPanel0 = new GridBagConstraints();
pnPanel0.setLayout( gbPanel0 );
String []colsFundementals = new String[] { "", "" };
tbFundementals = new JTable( dataFundementals, colsFundementals );
gbcPanel0.gridx = 1;
gbcPanel0.gridy = 6;
gbcPanel0.gridwidth = 10;
gbcPanel0.gridheight = 8;
gbcPanel0.fill = GridBagConstraints.BOTH;
gbcPanel0.weightx = 1;
gbcPanel0.weighty = 1;
gbcPanel0.anchor = GridBagConstraints.NORTH;
gbPanel0.setConstraints( tbFundementals, gbcPanel0 );
pnPanel0.add( tbFundementals );
btSearch = new JButton("Search");
btSearch.addActionListener(this);
btSearch.setActionCommand("Search"); //
gbcPanel0.gridx = 13;
gbcPanel0.gridy = 13;
gbcPanel0.gridwidth = 4;
gbcPanel0.gridheight = 1;
gbcPanel0.fill = GridBagConstraints.BOTH;
gbcPanel0.weightx = 1;
gbcPanel0.weighty = 0;
gbcPanel0.anchor = GridBagConstraints.NORTH;
gbPanel0.setConstraints( btSearch, gbcPanel0 );
pnPanel0.add( btSearch );
taInput = new JTextArea(2,10);
gbcPanel0.gridx = 13;
gbcPanel0.gridy = 10;
gbcPanel0.gridwidth = 5;
gbcPanel0.gridheight = 2;
gbcPanel0.fill = GridBagConstraints.BOTH;
gbcPanel0.weightx = 1;
gbcPanel0.weighty = 0;
gbcPanel0.anchor = GridBagConstraints.NORTH;
gbPanel0.setConstraints( taInput, gbcPanel0 );
pnPanel0.add( taInput );
lbFundementals = new JLabel( "Fundementals" );
gbcPanel0.gridx = 1;
gbcPanel0.gridy = 5;
gbcPanel0.gridwidth = 10;
gbcPanel0.gridheight = 1;
gbcPanel0.fill = GridBagConstraints.BOTH;
gbcPanel0.weightx = 1;
gbcPanel0.weighty = 1;
gbcPanel0.anchor = GridBagConstraints.NORTH;
gbPanel0.setConstraints( lbFundementals, gbcPanel0 );
pnPanel0.add( lbFundementals );
tfCurrentPrice = new JTextField( );
gbcPanel0.gridx = 13;
gbcPanel0.gridy = 4;
gbcPanel0.gridwidth = 5;
gbcPanel0.gridheight = 2;
gbcPanel0.fill = GridBagConstraints.BOTH;
gbcPanel0.weightx = 1;
gbcPanel0.weighty = 0;
gbcPanel0.anchor = GridBagConstraints.NORTH;
gbPanel0.setConstraints( tfCurrentPrice, gbcPanel0 );
pnPanel0.add( tfCurrentPrice );
tpTicker = new JTextPane(tickerBox);
gbcPanel0.gridx = 1;
gbcPanel0.gridy = 1;
gbcPanel0.gridwidth = 9;
gbcPanel0.gridheight = 3;
gbcPanel0.fill = GridBagConstraints.BOTH;
gbcPanel0.weightx = 1;
gbcPanel0.weighty = 0;
gbcPanel0.anchor = GridBagConstraints.NORTH;
gbPanel0.setConstraints( tpTicker, gbcPanel0 );
pnPanel0.add( tpTicker );
tfPredictedPrice = new JTextField( );
gbcPanel0.gridx = 13;
gbcPanel0.gridy = 8;
gbcPanel0.gridwidth = 5;
gbcPanel0.gridheight = 2;
gbcPanel0.fill = GridBagConstraints.BOTH;
gbcPanel0.weightx = 1;
gbcPanel0.weighty = 0;
gbcPanel0.anchor = GridBagConstraints.NORTH;
gbPanel0.setConstraints( tfPredictedPrice , gbcPanel0 );
pnPanel0.add( tfPredictedPrice );
lbPredictedPrice = new JLabel( "Predicted Price" );
gbcPanel0.gridx = 14;
gbcPanel0.gridy = 7;
gbcPanel0.gridwidth = 3;
gbcPanel0.gridheight = 1;
gbcPanel0.fill = GridBagConstraints.BOTH;
gbcPanel0.weightx = 1;
gbcPanel0.weighty = 1;
gbcPanel0.anchor = GridBagConstraints.NORTH;
gbPanel0.setConstraints( lbPredictedPrice, gbcPanel0 );
pnPanel0.add( lbPredictedPrice );
tfName = new JTextField( );
gbcPanel0.gridx = 13;
gbcPanel0.gridy = 1;
gbcPanel0.gridwidth = 5;
gbcPanel0.gridheight = 2;
gbcPanel0.fill = GridBagConstraints.BOTH;
gbcPanel0.weightx = 1;
gbcPanel0.weighty = 0;
gbcPanel0.anchor = GridBagConstraints.NORTH;
gbPanel0.setConstraints( tfName, gbcPanel0 );
pnPanel0.add( tfName );
btTrainNetwork = new JButton( "Train Network" );
btTrainNetwork.addActionListener(this);
btTrainNetwork.setActionCommand("Train Network"); //
gbcPanel0.gridx = 15;
gbcPanel0.gridy = 19;
gbcPanel0.gridwidth = 4;
gbcPanel0.gridheight = 2;
gbcPanel0.fill = GridBagConstraints.BOTH;
gbcPanel0.weightx = 1;
gbcPanel0.weighty = 0;
gbcPanel0.anchor = GridBagConstraints.NORTH;
gbPanel0.setConstraints( btTrainNetwork, gbcPanel0 );
pnPanel0.add( btTrainNetwork );
sdWidth = new JSlider( );
gbcPanel0.gridx = 5;
gbcPanel0.gridy = 16;
gbcPanel0.gridwidth = 9;
gbcPanel0.gridheight = 1;
gbcPanel0.fill = GridBagConstraints.BOTH;
gbcPanel0.weightx = 1;
gbcPanel0.weighty = 0;
gbcPanel0.anchor = GridBagConstraints.NORTH;
gbPanel0.setConstraints( sdWidth, gbcPanel0 );
pnPanel0.add( sdWidth );
lbWidth = new JLabel( "Width" );
gbcPanel0.gridx = 1;
gbcPanel0.gridy = 16;
gbcPanel0.gridwidth = 3;
gbcPanel0.gridheight = 1;
gbcPanel0.fill = GridBagConstraints.BOTH;
gbcPanel0.weightx = 1;
gbcPanel0.weighty = 1;
gbcPanel0.anchor = GridBagConstraints.NORTH;
gbPanel0.setConstraints( lbWidth, gbcPanel0 );
pnPanel0.add( lbWidth );
lbDepth = new JLabel( "Depth" );
gbcPanel0.gridx = 1;
gbcPanel0.gridy = 18;
gbcPanel0.gridwidth = 3;
gbcPanel0.gridheight = 1;
gbcPanel0.fill = GridBagConstraints.BOTH;
gbcPanel0.weightx = 1;
gbcPanel0.weighty = 1;
gbcPanel0.anchor = GridBagConstraints.NORTH;
gbPanel0.setConstraints( lbDepth, gbcPanel0 );
pnPanel0.add( lbDepth );
sdDepth = new JSlider( );
sdDepth.setValue( 6 );
gbcPanel0.gridx = 5;
gbcPanel0.gridy = 18;
gbcPanel0.gridwidth = 9;
gbcPanel0.gridheight = 1;
gbcPanel0.fill = GridBagConstraints.BOTH;
gbcPanel0.weightx = 1;
gbcPanel0.weighty = 0;
gbcPanel0.anchor = GridBagConstraints.NORTH;
gbPanel0.setConstraints( sdDepth, gbcPanel0 );
pnPanel0.add( sdDepth );
lbIterations = new JLabel( "Iterations" );
gbcPanel0.gridx = 1;
gbcPanel0.gridy = 20;
gbcPanel0.gridwidth = 3;
gbcPanel0.gridheight = 1;
gbcPanel0.fill = GridBagConstraints.BOTH;
gbcPanel0.weightx = 1;
gbcPanel0.weighty = 1;
gbcPanel0.anchor = GridBagConstraints.NORTH;
gbPanel0.setConstraints( lbIterations, gbcPanel0 );
pnPanel0.add( lbIterations );
sdIterations = new JSlider( );
sdIterations.setValue( 6 );
gbcPanel0.gridx = 5;
gbcPanel0.gridy = 20;
gbcPanel0.gridwidth = 9;
gbcPanel0.gridheight = 1;
gbcPanel0.fill = GridBagConstraints.BOTH;
gbcPanel0.weightx = 1;
gbcPanel0.weighty = 0;
gbcPanel0.anchor = GridBagConstraints.NORTH;
gbPanel0.setConstraints( sdIterations, gbcPanel0 );
pnPanel0.add( sdIterations );
btLoadStocks = new JButton( "Load Stocks" );
btLoadStocks.addActionListener(this);
btLoadStocks.setActionCommand("Load Stocks"); //
gbcPanel0.gridx = 15;
gbcPanel0.gridy = 16;
gbcPanel0.gridwidth = 4;
gbcPanel0.gridheight = 2;
gbcPanel0.fill = GridBagConstraints.BOTH;
gbcPanel0.weightx = 1;
gbcPanel0.weighty = 0;
gbcPanel0.anchor = GridBagConstraints.NORTH;
gbPanel0.setConstraints( btLoadStocks, gbcPanel0 );
pnPanel0.add( btLoadStocks );
setDefaultCloseOperation( EXIT_ON_CLOSE );
setContentPane( pnPanel0 );
pack();
setVisible( true );
}
}