-
Notifications
You must be signed in to change notification settings - Fork 3
/
GUI: TwoPlayerName
89 lines (77 loc) · 3.16 KB
/
GUI: TwoPlayerName
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
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Modality;
import javafx.stage.Stage;
public class TwoPlayerName {
public static void Display(String title, String message, String message2) {
GridPane grid;
Stage window;
Label p1Label, p2Label;
TextField player1Name, player2Name;
Button done;
Scene scene;
String p1Name, p2Name, p12Name;
grid = new GridPane();
grid.setPadding(new Insets(10, 10, 10, 10));
grid.setVgap(10);
grid.setHgap(10);
window = new Stage();
window.initModality(Modality.NONE);
window.setTitle("2 player: Names");
window.setMinWidth(400);
p1Label = new Label();
p1Label.setFont(Font.font("Verdana", FontWeight.BOLD, 12));
p1Label.setTextFill(Color.WHITE);
p1Label.setText("Enter player1's name: ");
GridPane.setConstraints(p1Label, 0, 0);
player1Name = new TextField();
player1Name.setPromptText("Name");
p1Name = player1Name.getText();
GridPane.setConstraints(player1Name, 1, 0);
p2Label = new Label();
p2Label.setFont(Font.font("Verdana", FontWeight.BOLD, 12));
p2Label.setTextFill(Color.WHITE);
p2Label.setText("Enter player2's name: ");
GridPane.setConstraints(p2Label, 0, 1);
player2Name = new TextField();
player2Name.setPromptText("Name");
p2Name = player2Name.getText();
GridPane.setConstraints(player2Name, 1, 1);
done = new Button("Done");
final String IDLE_BUTTON_STYLE = "-fx-background-color: black;" +
"-fx-text-fill: white;" +
"-fx-border-style: solid inside;" +
"-fx-border-width: 2;" +
"-fx-border-insets: 0;" +
"-fx-border-radius: 5;" +
"-fx-border-color: #87CEFA;";
final String HOVERED_BUTTON_STYLE = "-fx-background-color: black;" +
"-fx-shadow-highlight-color: black;" +
"-fx-text-fill: white;" +
"-fx-border-style: solid inside;" +
"-fx-border-width: 2;" +
"-fx-border-insets: 0;" +
"-fx-border-radius: 5;" +
"-fx-border-color: #7CFC00";
done.setStyle(IDLE_BUTTON_STYLE);
done.setOnMouseEntered(e -> done.setStyle(HOVERED_BUTTON_STYLE));
done.setOnMouseExited(e -> done.setStyle(IDLE_BUTTON_STYLE));
done.setOnAction(e -> {
window.hide();
TwoPlayer.Display(player1Name.getText(), player2Name.getText());
});
GridPane.setConstraints(done, 1, 2);
grid.getChildren().addAll(p1Label, player1Name, p2Label, player2Name, done);
grid.setStyle("-fx-background-color: linear-gradient(to bottom, black, #191970);");
scene = new Scene(grid);
window.setScene(scene);
window.showAndWait();
}
}