-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
3241 lines (2774 loc) · 115 KB
/
Main.java
File metadata and controls
3241 lines (2774 loc) · 115 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
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//stock Trading App Code
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.chart.BarChart;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.control.Button;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.layout.HBox;
import javafx.util.Duration;
import javafx.animation.TranslateTransition;
import javafx.scene.layout.StackPane;
import javafx.scene.control.*;
import javafx.geometry.Insets;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.scene.text.TextAlignment;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.animation.PauseTransition;
import javafx.geometry.Pos;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.nio.file.StandardOpenOption;
import javafx.stage.Modality;
import java.util.concurrent.CompletableFuture;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.TilePane;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.paint.Color;
import javafx.scene.paint.RadialGradient;
import javafx.scene.paint.Stop;
import javafx.animation.*;
import static Jithu.A.*;
import Jithu.Mix;
import java.io.FileReader;
import javafx.collections.ObservableList;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
class Apistocks{
private static final String ALPHA_VANTAGE_API_KEY = "YOUR_API_HERE";
private String SYMBOL = "AAPL"; // Replace with the stock symbol you want to track
StringBuilder res=new StringBuilder();
Apistocks(String symbo){
this.SYMBOL=symbo;
}
private void updateStockPrice() {
try {
URL url = new URL("https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=" + SYMBOL + "&apikey=" + ALPHA_VANTAGE_API_KEY);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
reader.close();
res=response;
// Parse JSON response
} catch (Exception e) {
e.printStackTrace();
}
}
public String parseStockPrice(String jsonResponse) {
try {
// Look for the key "05. price" in the JSON response
int keyIndex = jsonResponse.indexOf("05. price");
// Check if the key is present in the response
if (keyIndex != -1) {
// Find the value associated with the key
int startIndex = jsonResponse.indexOf(":", keyIndex) + 1;
int endIndex = jsonResponse.indexOf("\"", startIndex+2);
// Extract and return the stock price
return jsonResponse.substring(startIndex+2, endIndex).trim();
} else {
// Handle the case where the key is not present in the response
return "193";
}
} catch (Exception e) {
e.printStackTrace();
return "Error parsing stock price";
}
}
public String parseStocklowprice(String jsonResponse) {
try {
// Look for the key "05. price" in the JSON response
int keyIndex = jsonResponse.indexOf("04. low");
// Check if the key is present in the response
if (keyIndex != -1) {
// Find the value associated with the key
int startIndex = jsonResponse.indexOf(":", keyIndex) + 1;
int endIndex = jsonResponse.indexOf("\"", startIndex+2);
// Extract and return the stock price
return jsonResponse.substring(startIndex+2, endIndex).trim();
} else {
// Handle the case where the key is not present in the response
return "19";
}
} catch (Exception e) {
e.printStackTrace();
return "Error parsing stock price";
}
}
public String parseStockhighprice(String jsonResponse) {
try {
// Look for the key "05. price" in the JSON response
int keyIndex = jsonResponse.indexOf("03. high");
// Check if the key is present in the response
if (keyIndex != -1) {
// Find the value associated with the key
int startIndex = jsonResponse.indexOf(":", keyIndex) + 1;
int endIndex = jsonResponse.indexOf("\"", startIndex+2);
// Extract and return the stock price
return jsonResponse.substring(startIndex+2, endIndex).trim();
} else {
// Handle the case where the key is not present in the response
return "930";
}
} catch (Exception e) {
e.printStackTrace();
return "Error parsing stock price";
}
}
public String parseStockvolume(String jsonResponse) {
try {
// Look for the key "05. price" in the JSON response
int keyIndex = jsonResponse.indexOf("06. volume");
// Check if the key is present in the response
if (keyIndex != -1) {
// Find the value associated with the key
int startIndex = jsonResponse.indexOf(":", keyIndex) + 1;
int endIndex = jsonResponse.indexOf("\"", startIndex+2);
// Extract and return the stock price
return jsonResponse.substring(startIndex+2, endIndex).trim();
} else {
// Handle the case where the key is not present in the response
return "33";
}
} catch (Exception e) {
e.printStackTrace();
return "Error parsing stock price";
}
}
public String parseStockpercent(String jsonResponse) {
try {
// Look for the key "05. price" in the JSON response
int keyIndex = jsonResponse.indexOf("10. change percent");
// Check if the key is present in the response
if (keyIndex != -1) {
// Find the value associated with the key
int startIndex = jsonResponse.indexOf(":", keyIndex) + 1;
int endIndex = jsonResponse.indexOf("%", startIndex+2);
// Extract and return the stock price
return jsonResponse.substring(startIndex+2, endIndex).trim();
} else {
// Handle the case where the key is not present in the response
return "0.0";
}
} catch (Exception e) {
e.printStackTrace();
return "Error parsing stock price";
}
}
public int intege(){
updateStockPrice();
String stk=parseStockPrice(res.toString());
double ppl=Double.parseDouble(stk);
return (int)ppl;
}
public int integ(){
String stk=parseStocklowprice(res.toString());
double ppl=Double.parseDouble(stk);
return (int)ppl;
}
public int integr(){
String stk=parseStockhighprice(res.toString());
double ppl=Double.parseDouble(stk);
return (int)ppl;
}
public int volume(){
String stk=parseStockvolume(res.toString());
double ppl=Double.parseDouble(stk);
return (int)ppl;
}
public double percent(){
String stk=parseStockpercent(res.toString());
double ppl=Double.parseDouble(stk);
return ppl;
}
}
class Storestockdetails{
public static Map<String, Integer> volume = new HashMap<>();
public static Map<String, Double> percent = new HashMap<>();
}
class StockPrice{
public static Map<String, Integer> stockPrices;
public static Map<String, Integer> stocklowPrices;
public static Map<String, Integer> stockhighPrices;
private static Random random = new Random();
int k=0;
public StockPrice(){
stockPrices = new HashMap<>();
stocklowPrices = new HashMap<>();
stockhighPrices = new HashMap<>();
initializeStockPrices(); // Initial update
// Schedule a task to update the stock prices every 5 seconds (adjust as needed)
Timer timer = new Timer(true);
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
updateStockPrices();
}
}, 0, 5000);
}
private static void initializeStockPrices() {
Apistocks h = new Apistocks("AAPL");
// Initialize stock prices with random values between 100 and 1000
stockPrices.put("AAPL",h.intege());
stocklowPrices.put("AAPL",h.integ());
stockhighPrices.put("AAPL",h.integr());
Storestockdetails.volume.put("AAPL", h.volume());
Storestockdetails.percent.put("AAPL",h.percent());
Apistocks k = new Apistocks("GOOG");
stockPrices.put("GOOG", k.intege());
stocklowPrices.put("GOOG",k.integ());
stockhighPrices.put("GOOG",k.integr());
Storestockdetails.volume.put("GOOG", k.volume());
Storestockdetails.percent.put("GOOG",k.percent());
Apistocks a = new Apistocks("MSFT");
stockPrices.put("MSFT", a.intege());
stocklowPrices.put("MSFT",a.integ());
stockhighPrices.put("MSFT",a.integr());
Storestockdetails.volume.put("MSFT", a.volume());
Storestockdetails.percent.put("MSFT",a.percent());
Apistocks h1 = new Apistocks("AMZN");
stockPrices.put("AMZN", h1.intege());
stocklowPrices.put("AMZN",h1.integ());
stockhighPrices.put("AMZN",h1.integr());
Storestockdetails.volume.put("AMZN", h1.volume());
Storestockdetails.percent.put("AMZN",h1.percent());
Apistocks h2 = new Apistocks("TSLA");
stockPrices.put("TSLA", h2.intege());
stocklowPrices.put("TSLA",h2.integ());
stockhighPrices.put("TSLA",h2.integr());
Storestockdetails.volume.put("TSLA", h2.volume());
Storestockdetails.percent.put("TSLA",h2.percent());
Apistocks h3 = new Apistocks("Meta Platforms");
stockPrices.put("Meta Platforms", h3.intege());
stocklowPrices.put("Meta Platforms",h3.integ());
stockhighPrices.put("Meta Platforms",h3.integr());
Storestockdetails.volume.put("Meta Platforms", h3.volume());
Storestockdetails.percent.put("Meta Platforms",h3.percent());
Apistocks h4 = new Apistocks("IBM");
stockPrices.put("IBM", h4.intege());
stocklowPrices.put("IBM",h4.integ());
stockhighPrices.put("IBM",h4.integr());
Storestockdetails.volume.put("IBM", h4.volume());
Storestockdetails.percent.put("IBM",h4.percent());
Apistocks h5 = new Apistocks("WMT");
stockPrices.put("WMT", h5.intege());
stocklowPrices.put("WMT",h5.integ());
stockhighPrices.put("WMT",h5.integr());
Storestockdetails.volume.put("WMT", h5.volume());
Storestockdetails.percent.put("WMT",h5.percent());
Apistocks h6 = new Apistocks("MCD");
stockPrices.put("MCD", h6.intege());
stocklowPrices.put("MCD",h6.integ());
stockhighPrices.put("MCD",h6.integr());
Storestockdetails.volume.put("MCD", h6.volume());
Storestockdetails.percent.put("MCD",h6.percent());
Apistocks h7 = new Apistocks("V");
stockPrices.put("V", h7.intege());
stocklowPrices.put("V",h7.integ());
stockhighPrices.put("V",h7.integr());
Storestockdetails.volume.put("V", h7.volume());
Storestockdetails.percent.put("V",h7.percent());
Apistocks h8 = new Apistocks("NOK");
stockPrices.put("NOK", h8.intege());
stocklowPrices.put("NOK",h8.integ());
stockhighPrices.put("NOK",h8.integr());
Storestockdetails.volume.put("NOK", h8.volume());
Storestockdetails.percent.put("NOK",h8.percent());
Apistocks h9 = new Apistocks("NYT");
stockPrices.put("NYT", h9.intege());
stocklowPrices.put("NYT",h9.integ());
stockhighPrices.put("NYT",h9.integr());
Storestockdetails.volume.put("NYT", h9.volume());
Storestockdetails.percent.put("NYT",h9.percent());
Apistocks h10 = new Apistocks("RACE");
stockPrices.put("RACE", h10.intege());
stocklowPrices.put("RACE",h10.integ());
stockhighPrices.put("RACE",h10.integr());
Storestockdetails.volume.put("RACE", h10.volume());
Storestockdetails.percent.put("RACE",h10.percent());
Apistocks h11 = new Apistocks("PFE");
stockPrices.put("PFE", h11.intege());
stocklowPrices.put("PFE",h11.integ());
stockhighPrices.put("PFE",h11.integr());
Storestockdetails.volume.put("PFE", h11.volume());
Storestockdetails.percent.put("PFE",h11.percent());
Apistocks h12 = new Apistocks("OPY");
stockPrices.put("OPY", h12.intege());
stocklowPrices.put("OPY",h12.integ());
stockhighPrices.put("OPY",h12.integr());
Storestockdetails.volume.put("OPY", h12.volume());
Storestockdetails.percent.put("OPY",h12.percent());
/*Apistocks h13 = new Apistocks("NOK");
stockPrices.put("NOK", h13.intege());
stocklowPrices.put("NOK",h13.integ());
stockhighPrices.put("NOK",h13.integr());
Storestockdetails.volume.put("NOK", h13.volume());
Storestockdetails.percent.put("NOK",h13.percent());
Apistocks h14 = new Apistocks("NYT");
stockPrices.put("NYT", h14.intege());
stocklowPrices.put("NYT",h14.integ());
stockhighPrices.put("NYT",h14.integr());
Storestockdetails.volume.put("NYT", h14.volume());
Storestockdetails.percent.put("NYT",h14.percent());
Apistocks h15 = new Apistocks("NKE");
stockPrices.put("NKE", h15.intege());
stocklowPrices.put("NKE",h15.integ());
stockhighPrices.put("NKE",h15.integr());
Storestockdetails.volume.put("NKE", h15.volume());
Storestockdetails.percent.put("NKE",h15.percent());
Apistocks h16 = new Apistocks("MGM");
stockPrices.put("MGM", h16.intege());
stocklowPrices.put("MGM",h16.integ());
stockhighPrices.put("MGM",h16.integr());
Storestockdetails.volume.put("MGM", h16.volume());
Storestockdetails.percent.put("MGM",h16.percent());*/
printStockPrices();
}
private static void updateStockPrices() {
// Update stock prices with a small random change between -50 and 50
for (Map.Entry<String, Integer> entry : stockPrices.entrySet()) {
int y=stocklowPrices.get(entry.getKey());
int c=stockhighPrices.get(entry.getKey());
int priceChange;
if(c-y>0){
priceChange = y+random.nextInt(c-y); // Random value between -50 and 50
}
else if(y-c>0){
priceChange = y-random.nextInt(y-c); // Random value between -50 and 50
}
else{
priceChange=1;
}
int currentPrice = priceChange;
stockPrices.put(entry.getKey(), currentPrice);
}
printStockPrices();
}
private static void printStockPrices() {
// Print stock prices to the console
System.out.println("Stock Prices:");
for (Map.Entry<String, Integer> entry : stockPrices.entrySet()) {
System.out.println(entry.getKey() + ": $" + entry.getValue());
}
Print("");
}
}
interface Pages{
public BorderPane getRoot();
}
class File{
public static void Write(String filePath,String textToAppend){
try (FileWriter fileWriter = new FileWriter(filePath, true);
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter)) {
bufferedWriter.write(textToAppend);
Print("Text appended successfully.");
} catch (IOException e) {
Print("An error occurred while appending to the file.");
e.printStackTrace();
}
}
public static void Overwrite(String filePath,String newText){
try (FileWriter fileWriter = new FileWriter(filePath, false)) {
// The second parameter 'false' indicates that you want to overwrite the file
fileWriter.write(newText);
Print("Text overwritten successfully.");
} catch (IOException e) {
Print("An error occurred while overwriting the file.");
e.printStackTrace();
}
}
public static void Create(String filePath,String content){
try {
// Create the file and write the content
Path path = Path.of(filePath);
Files.write(path, content.getBytes(), StandardOpenOption.CREATE);
Print("File created successfully.");
} catch (IOException e) {
Print("An error occurred while creating the file.");
e.printStackTrace();
}
}
}
class Conv{
public static double StoD(String s){
try {
double result = Double.parseDouble(s);
return result;
} catch (NumberFormatException e) {
Print("Invalid numeric format");
e.printStackTrace();
return 0;
}
}
}
class Infopage implements Pages{
private BorderPane root;
Button[] buttons;
Stocks mystock=new Stocks();
String stockname;
double stockprice;
String from="dash";
double currency;
Text[] texts;
Text[] textr;
private VBox companyInfoContainer = new VBox(10);
public Infopage(Portfolio pf,String ghi){
currency=pf.user.getBalance();
from=ghi;
Stocks stok = new Stocks();
stok.addstock("TSLA",0);
stok.addstock("AMZN",0);
stok.addstock("AAPL",0);
stok.addstock("GOOG",0);
stok.addstock("MSFT",0);
stok.addstock("Meta Platforms",0);
stok.addstock("IBM",0);
stok.addstock("MCD",0);
stok.addstock("NOK",0);
stok.addstock("NYT",0);
stok.addstock("OPY",0);
stok.addstock("PFE",0);
stok.addstock("RACE",0);
stok.addstock("V",0);
stok.addstock("WMT",0);
texts = new Text[stok.stocks.size()];
textr = new Text[stok.stocks.size()];
root=new BorderPane();
ScrollPane leAnchorPane = new ScrollPane();
leAnchorPane.setPrefHeight(600.0);
leAnchorPane.setPrefWidth(354.0);
leAnchorPane.setStyle("-fx-background-color: #0598ff;");
LinearGradient linearGradient = new LinearGradient(
0, 0, 1, 1, true, CycleMethod.NO_CYCLE,
new Stop(0, Color.RED),
new Stop(1, Color.BLUE)
);
ScrollPane scrollPane = new ScrollPane(companyInfoContainer);
scrollPane.setFitToWidth(true);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS); // Set vertical scroll policy
// Set preferred height for companyInfoContainer
companyInfoContainer.setPrefHeight(200);
scrollPane.setPrefHeight(500.0);
scrollPane.setPrefWidth(345.0);
scrollPane.setStyle("-fx-background-color: #ffffff;");
Text currencytext = new Text(""+currency);
currencytext.setLayoutX(344.0);
Button myButton = new Button("Return!");
myButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
// Open a new scene with NewPage
Pages newPag;
if(from.equals("port")){
newPag = new Portfoliopg(pf);
}
else{
newPag = new NewPage(pf);
}
Stage newstag = new Stage();
newstag.setScene(new Scene(newPag.getRoot(), 750, 600));
newstag.setTitle("Welcome ");
newstag.show();
Stage stageu = (Stage) root.getScene().getWindow();
stageu.close();
}
});
HBox menubo = new HBox();
menubo.setPrefWidth(1000);
menubo.setStyle("-fx-background-color: #0598ff;");
menubo.getChildren().addAll(myButton,currencytext);
Button appleButton = new Button("Apple");
Button nokiaButton = new Button("Nokia");
Button facebookButton = new Button("Facebook");
Button amazonButton = new Button("Amazon");
Button nytbutton = new Button("New York Times");
Button ibmButton = new Button("IBM");
Button googleButton = new Button("Google");
Button oppyButton = new Button("Oppenheimer Holdings");
Button walmartButton = new Button("Walmart");
Button microButton = new Button("Microsoft");
Button visaButton = new Button("Visa");
Button ferrariButton = new Button("Ferrari");
Button pfizerButton = new Button("Pfizer");
Button mcdButton = new Button("McDonald's");
Button teslaButton = new Button("Tesla");
appleButton.setStyle("-fx-background-color: transparent; ");
nokiaButton.setStyle("-fx-background-color: transparent; ");
facebookButton.setStyle("-fx-background-color: transparent; ");
amazonButton.setStyle("-fx-background-color: transparent; ");
nytbutton.setStyle("-fx-background-color: transparent; ");
ibmButton.setStyle("-fx-background-color: transparent; ");
googleButton.setStyle("-fx-background-color: transparent; ");
oppyButton.setStyle("-fx-background-color: transparent; ");
walmartButton.setStyle("-fx-background-color: transparent; ");
microButton.setStyle("-fx-background-color: transparent; ");
visaButton.setStyle("-fx-background-color: transparent; ");
ferrariButton.setStyle("-fx-background-color: transparent; ");
pfizerButton.setStyle("-fx-background-color: transparent; ");
mcdButton.setStyle("-fx-background-color: transparent; ");
teslaButton.setStyle("-fx-background-color: transparent; ");
nytbutton.setOnAction(e -> handleButtonClick("New York Times"));
ibmButton.setOnAction(e -> handleButtonClick("IBM"));
oppyButton.setOnAction(e -> handleButtonClick("Oppenheimer Holdings"));
walmartButton.setOnAction(e -> handleButtonClick("Walmart"));
microButton.setOnAction(e -> handleButtonClick("Microsoft"));
visaButton.setOnAction(e -> handleButtonClick("Visa"));
ferrariButton.setOnAction(e -> handleButtonClick("Ferrari"));
pfizerButton.setOnAction(e -> handleButtonClick("Pfizer"));
mcdButton.setOnAction(e -> handleButtonClick("McDonald's"));
appleButton.setOnAction(e -> handleButtonClick("Apple"));
nokiaButton.setOnAction(e -> handleButtonClick("Nokia"));
googleButton.setOnAction(e -> handleButtonClick("Google"));
amazonButton.setOnAction(e -> handleButtonClick("Amazon"));
facebookButton.setOnAction(e -> handleButtonClick("Facebook"));
teslaButton.setOnAction(e -> handleButtonClick("Tesla"));
VBox buttonList = new VBox(10);
buttonList.getChildren().addAll(appleButton, googleButton, amazonButton,
nokiaButton, nytbutton, ibmButton,oppyButton, walmartButton, microButton, visaButton,ferrariButton, pfizerButton, mcdButton);
// Set background color for the button list
buttonList.setStyle("-fx-background-color: skyblue;");
buttonList.setPrefHeight(600.0);
buttonList.setPrefWidth(345.0);
leAnchorPane.setContent(buttonList);
Timer timero = new Timer(true);
timero.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
for(Stock x:stok.stocks){
int post=0;
Integer inter=pf.stockprice.stockPrices.get(x.name);
x.price=inter.doubleValue();
texts[post].setText(x.price+"");
textr[post].setText(x.price+"");
post++;
}
}
}, 0, 5000);
root.setTop(menubo);
root.setLeft(leAnchorPane);
root.setCenter(scrollPane);
}
public BorderPane getRoot(){
return root;
}
private void handleButtonClick(String stockName) {
String fileName = "stockinfo.txt";
String companyInfo = "";
try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {
String line;
while ((line = br.readLine()) != null) {
if (line.startsWith(stockName)) {
companyInfo = "Information:\n"; // Heading
companyInfo += line + "\n"; // Start with the company name
while ((line = br.readLine()) != null && !line.isEmpty()) {
companyInfo += line + "\n"; // Append company information with line breaks
}
break;
}
}
} catch (IOException e) {
companyInfo = "Error reading company information.";
e.printStackTrace();
}
// Clear previous labels before adding the new one
companyInfoContainer.getChildren().clear();
// Create a new label for the company and set wrapping and max width
Label companyLabel = new Label(companyInfo);
companyLabel.setWrapText(true); // Enable text wrapping
companyLabel.setMaxWidth(companyInfoContainer.getWidth()); // Set maximum width
// Add the label to the container
companyInfoContainer.getChildren().add(companyLabel);
}
}
class Transactionhist implements Pages{
private BorderPane root;
Button[] buttons;
Stocks mystock=new Stocks();
String stockname;
double stockprice;
String from="dash";
double currency;
public Transactionhist(Portfolio pf,String ghi){
currency=pf.user.getBalance();
from=ghi;
String filePath = pf.user.getUsername()+"file.txt";
Path path = Paths.get(filePath);
try {
List<String> lines = Files.readAllLines(path);
for (String line : lines) {
String[] stoyk=line.split(",");
mystock.addstock(stoyk[0],Conv.StoD(stoyk[1]));
}
} catch (IOException e) {
System.out.println("An error occurred while reading the file.");
e.printStackTrace();
}
root=new BorderPane();
AnchorPane leAnchorPane = new AnchorPane();
leAnchorPane.setPrefHeight(500.0);
leAnchorPane.setPrefWidth(354.0);
leAnchorPane.setStyle("-fx-background-color: #0598ff;");
Timer timero = new Timer(true);
timero.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
for(Stock x:pf.mystocks.stocks){
Integer inter=pf.stockprice.stockPrices.get(x.name);
x.price=inter.doubleValue();
}
}
}, 0, 5000);
Text fust = new Text("");
fust.setFill(Color.web("#0598ff"));
fust.setLayoutX(134.0);
fust.setLayoutY(250);
fust.setFont(new Font(30.0));
Text fustr = new Text("");
fustr.setFill(Color.web("#0598ff"));
fustr.setLayoutX(134.0);
fustr.setLayoutY(170);
fustr.setFont(new Font(30.0));
LinearGradient linearGradient = new LinearGradient(
0, 0, 1, 1, true, CycleMethod.NO_CYCLE,
new Stop(0, Color.RED),
new Stop(1, Color.BLUE)
);
ScrollPane scrollPane = new ScrollPane(leAnchorPane);
AnchorPane cenAnchorPane = new AnchorPane();
cenAnchorPane.setPrefHeight(500.0);
cenAnchorPane.setPrefWidth(345.0);
cenAnchorPane.setStyle("-fx-background-color: linear-gradient(from 0% 0% to 100% 100%, #FF0000, #0000FF);");
cenAnchorPane.getChildren().add(fust);
Text currencytext = new Text(""+currency);
currencytext.setLayoutX(344.0);
Button myButton = new Button("Return!");
myButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
// Open a new scene with NewPage
Pages newPag;
if(from.equals("port")){
newPag = new Portfoliopg(pf);
}
else{
newPag = new NewPage(pf);
}
Stage newstag = new Stage();
newstag.setScene(new Scene(newPag.getRoot(), 750, 600));
newstag.setTitle("Welcome ");
newstag.show();
Stage stageu = (Stage) root.getScene().getWindow();
stageu.close();
}
});
HBox menubo = new HBox();
menubo.setPrefWidth(750);
menubo.setStyle("-fx-background-color: #0598ff;");
menubo.getChildren().addAll(myButton,currencytext);
int mn=0;
int i=0;
buttons = new Button[mystock.stocks.size()];
for (Stock x:mystock.stocks){
Button mybu=new Button(x.name);
mybu.setLayoutY(mn);
buttons[i]=mybu;
final int g=i;
buttons[i].setOnAction(e -> {
//us.setText("Stock name: "+mystock.stocks.get(g).name);
stockname=mystock.stocks.get(g).name;
//det.setText("Stock price: "+mystock.stocks.get(g).price);
stockprice=mystock.stocks.get(g).price;
String filePathet = pf.user.getUsername()+"file.txt"; // Replace with the actual path to your file
// Use try-with-resources to ensure the file is closed properly
try {
// Read all lines from the file into a List<String>
Path pathet = Paths.get(filePathet);
List<String> lines = Files.readAllLines(pathet);
// Process each line
for (String line : lines) {
String[] fly = new String[3];
fly=line.split(",");
if(fly[0].equals(stockname)){
fust.setText(fly[2]);
fustr.setText(stockname);
}
}
} catch (IOException exp) {
exp.printStackTrace();
// Handle the exception (e.g., file not found, permission issues, etc.)
}
});
i++;
mn+=30;
mybu.setStyle("-fx-background-color: #0598ff;");
leAnchorPane.getChildren().addAll(mybu);
}
root.setTop(menubo);
root.setLeft(scrollPane);
root.setCenter(cenAnchorPane);
}
public BorderPane getRoot(){
return root;
}
}
class Portfoliopg implements Pages{
private BorderPane root;
Button[] buttons;
Stocks mystock;
String stockname;
double stockprice;
double currency;
//private String fullText;
//private int textWidth;
//private int currentIndex = 0;
public Portfoliopg(Portfolio pf){
currency=pf.user.getBalance();
mystock=pf.mystocks;
root=new BorderPane();
LinearGradient linearGradient = new LinearGradient(
0, 0, 1, 1, true, CycleMethod.NO_CYCLE,
new Stop(0, Color.RED),
new Stop(1, Color.BLUE)
);
AnchorPane leAnchorPane = new AnchorPane();
leAnchorPane.setPrefHeight(500.0);
leAnchorPane.setPrefWidth(354.0);
leAnchorPane.setStyle("-fx-background-color: linear-gradient(from 0% 0% to 100% 100%, #FF0000, #0000FF);");
ImageView userImage = new ImageView(new Image(getClass().getResourceAsStream("user.png")));
userImage.setFitHeight(70);
userImage.setFitWidth(70);
userImage.setLayoutX(135);
userImage.setLayoutY(60);
leAnchorPane.getChildren().add(userImage);
ScrollPane cenAnchorPane = new ScrollPane();
cenAnchorPane.setPrefHeight(500.0);
cenAnchorPane.setPrefWidth(345.0);
VBox vb = new VBox();
vb.setPadding(new Insets(110));
Text currencytext = new Text(""+currency);
currencytext.setLayoutX(344.0);
Text usid = new Text("user Id: 21224");
usid.setFill(Color.web("#FFFFFF"));
usid.setLayoutX(94.0);
usid.setLayoutY(161.0);
usid.setFont(new Font(21.0));
leAnchorPane.getChildren().add(usid);
Text us = new Text("username: "+pf.user.getUsername());
us.setFill(Color.web("#0598ff"));
//us.setLayoutX(134.0);
//us.setLayoutY(141.0);
us.setFont(new Font(21.0));
vb.getChildren().add(us);
String mytystock="";
for(Stock x:mystock.stocks){
mytystock+=(x.name+",\n");
}
//fullText="stocks: "+mytystock;
vb.setSpacing(50);
vb.setAlignment(Pos.CENTER);
Text bus = new Text("stocks: "+mytystock);
bus.setFill(Color.web("#0598ff"));
//bus.setLayoutX(134.0);
//bus.setLayoutY(310.0);
bus.setTextAlignment(TextAlignment.CENTER);
bus.setFont(Font.font("Arial",20.0));
vb.getChildren().add(bus);
cenAnchorPane.setContent(vb);
/*Timeline timeline = new Timeline(new KeyFrame(
Duration.millis(50), // Duration between characters
event -> {
if (currentIndex <= fullText.length()) {
bus.setText(fullText.substring(0, currentIndex));
currentIndex++;
}
}
));
timeline.setCycleCount(fullText.length() + 1);
timeline.play();
PauseTransition pauseTransition = new PauseTransition(Duration.seconds(1.5));
// Set the initial text
bus.setText(fullText);
// Measure the width of the text
textWidth = (int) bus.getBoundsInLocal().getWidth();
// Create a TranslateTransition for the animation
//bus.setTranslateX(textWidth);
TranslateTransition translateTransition = new TranslateTransition();
translateTransition.setNode(bus);
translateTransition.setByX(-textWidth);
translateTransition.setCycleCount(TranslateTransition.INDEFINITE);
translateTransition.setInterpolator(javafx.animation.Interpolator.LINEAR);
translateTransition.setDuration(Duration.seconds(4)); // Adjust duration as needed
// Start the animation
pauseTransition.setOnFinished(event -> translateTransition.play());
pauseTransition.play();*/
Button myButton = new Button("Return!");
myButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
// Open a new scene with NewPage
NewPage newPag = new NewPage(pf);
Stage newstag = new Stage();
newstag.setScene(new Scene(newPag.getRoot(), 750, 600));
newstag.setTitle("Welcome ");
newstag.show();
Stage stageu = (Stage) root.getScene().getWindow();
stageu.close();
}
});
Button transist = new Button("Transaction history");
transist.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
// Open a new scene with NewPage
Transactionhist Tras = new Transactionhist(pf,"port");
Stage newstag = new Stage();
newstag.setScene(new Scene(Tras.getRoot(), 750, 600));
newstag.setTitle("Welcome ");
newstag.show();
Stage stageu = (Stage) root.getScene().getWindow();
stageu.close();
}
});
vb.getChildren().add(transist);
HBox menubo = new HBox();
menubo.setPrefWidth(750);
menubo.setStyle("-fx-background-color: linear-gradient(from 0% 0% to 100% 100%, #FF0000, #0000FF);");
menubo.getChildren().addAll(myButton,currencytext);
root.setTop(menubo);
root.setLeft(leAnchorPane);
root.setCenter(cenAnchorPane);
}
public BorderPane getRoot(){
return root;
}
}
class Stockpage implements Pages{
private BorderPane root;
Button[] buttons;
Stocks mystock;
String stockname;
double stockprice;
double stockbuyprice;
String from="dash";
double currency;
Portfolio pg;
String userhandle="";
Text[] texts;
Text[] textr;
public Stockpage(Portfolio pf,String ghi){
currency=pf.user.getBalance();
from=ghi;
pg=pf;
mystock=pf.mystocks;
texts = new Text[mystock.stocks.size()];
textr = new Text[mystock.stocks.size()];