· 8 years ago · Jan 11, 2018, 03:56 PM
1package fr.themode.pump;
2
3import javafx.application.Application;
4import javafx.collections.FXCollections;
5import javafx.collections.ObservableList;
6import javafx.event.ActionEvent;
7import javafx.event.EventHandler;
8import javafx.scene.Scene;
9import javafx.scene.control.Button;
10import javafx.scene.control.ComboBox;
11import javafx.scene.control.TextField;
12import javafx.scene.layout.StackPane;
13import javafx.scene.paint.Color;
14import javafx.scene.text.Text;
15import javafx.stage.Stage;
16
17public class Main extends Application {
18
19 public static void main(String[] args) {
20 launch(args);
21 }
22
23 @Override
24 public void start(Stage primaryStage) throws Exception {
25 primaryStage.setTitle("Binance Pump");
26 primaryStage.setResizable(false);
27
28 // Error text
29 Text textStatus = new Text();
30 textStatus.setTranslateY(-75);
31
32 // API key
33 TextField apiKey = new TextField();
34 apiKey.setPromptText("API key");
35 apiKey.setTranslateY(-50);
36 removeTextFieldSpace(apiKey, true, false);
37
38 // Secret key
39 TextField secretKey = new TextField();
40 secretKey.setPromptText("Secret key");
41 secretKey.setTranslateY(-25);
42 removeTextFieldSpace(secretKey, true, false);
43
44 // Currency name
45 TextField currencyName = new TextField();
46 currencyName.setPromptText("Currency name");
47 removeTextFieldSpace(currencyName, false, true);
48
49 // ComboBox
50 ObservableList<String> buyPercentages = FXCollections.observableArrayList(
51 "25%", "50%", "75%", "100%");
52 ComboBox buyPercentageBox = new ComboBox(buyPercentages);
53 buyPercentageBox.setPromptText("Buy Percentage");
54 buyPercentageBox.setTranslateX(-65);
55 buyPercentageBox.setTranslateY(85);
56
57 ObservableList<String> sellPercentages = FXCollections.observableArrayList(
58 "5%", "10%", "15%", "20%", "25%",
59 "30%", "35%", "40%", "45%", "50%",
60 "55%", "60%", "65%", "70%", "75%"
61 , "80%", "85%", "90%", "95%", "100%");
62 ComboBox sellPercentageBox = new ComboBox(sellPercentages);
63 sellPercentageBox.setPromptText("Sell Percentage");
64 sellPercentageBox.setTranslateX(65);
65 sellPercentageBox.setTranslateY(85);
66
67 // Buy button
68 Button buyButton = new Button();
69 buyButton.setText("Buy !");
70 buyButton.setDefaultButton(true);
71 buyButton.setOnAction(new EventHandler<ActionEvent>() {
72
73 @Override
74 public void handle(ActionEvent event) {
75 if (apiKey.getText().isEmpty()) {
76 textStatus.setText("Empty api key");
77 textStatus.setFill(Color.RED);
78 } else if (secretKey.getText().isEmpty()) {
79 textStatus.setText("Empty secret key");
80 textStatus.setFill(Color.RED);
81 } else if (currencyName.getText().isEmpty()) {
82 textStatus.setText("Empty currency name");
83 textStatus.setFill(Color.RED);
84 } else if (buyPercentageBox.getSelectionModel().isEmpty()) {
85 textStatus.setText("No buy percentage set !");
86 textStatus.setFill(Color.RED);
87 } else if (sellPercentageBox.getSelectionModel().isEmpty()) {
88 textStatus.setText("No sell percentage set !");
89 textStatus.setFill(Color.RED);
90 } else {
91 // TODO send api request
92 textStatus.setText("Success!");
93 textStatus.setFill(Color.GREEN);
94 System.out.println("Buy!");
95 }
96 }
97 });
98
99 buyButton.setTranslateY(50);
100
101 StackPane root = new StackPane();
102 root.getChildren().add(textStatus);
103 root.getChildren().add(apiKey);
104 root.getChildren().add(secretKey);
105 root.getChildren().add(currencyName);
106 root.getChildren().add(buyButton);
107 root.getChildren().add(buyPercentageBox);
108 root.getChildren().add(sellPercentageBox);
109
110 primaryStage.setScene(new Scene(root, 300, 250));
111 primaryStage.show();
112 }
113
114 private void removeTextFieldSpace(TextField textField, boolean allowNumbers, boolean onlyCaps) {
115 textField.textProperty().addListener((observable, oldValue, newValue) -> {
116 String result = newValue.replace(" ", "");
117 if (!allowNumbers) {
118 result = result.replaceAll("\\d", "");
119 }
120 if (onlyCaps) {
121 result = result.toUpperCase();
122 }
123 textField.setText(result);
124 });
125 }
126}