-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeaderboard.java
More file actions
215 lines (170 loc) · 5.57 KB
/
Leaderboard.java
File metadata and controls
215 lines (170 loc) · 5.57 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
/**
* Java Leaderboard Class
* @author Kanishk
* @version 1.00, 1 Dec 2018
*/
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;
public class Leaderboard extends Application
{
static Stage firststage;
TextField nameInput;
/**
*
* Simple class definition of Leaderboard.
* This class is used for handling Leaderboard HiScore
* @since version 1.00
*/
private void CommonClose()
{
int answer=Confirm.show("Are you Sure?");
if(answer==1)
{
firststage.close();
}
}
private final TableView<Person> table = new TableView<>();
private final ObservableList<Person> data =
FXCollections.observableArrayList(new Person("A", 1.0));
final HBox hb = new HBox();
public static void main(String[] args)
{
launch(args);
}
/**
*
* Start method.
* The methods starts up the Leaderboard
* @since version 1.00
*/
@Override
public void start(Stage stage)
{
firststage=stage;
// stage.setAlwaysOnTop(true);
Scene scene = new Scene(new Group());
firststage.setWidth(450);
firststage.setHeight(550);
TableColumn firstNameCol = new TableColumn("First Name");
firstNameCol.setMinWidth(100);
firstNameCol.setCellValueFactory(
new PropertyValueFactory<>("firstName"));
TableColumn lastNameCol = new TableColumn("HighScore");
lastNameCol.setMinWidth(100);
lastNameCol.setCellValueFactory(
new PropertyValueFactory<>("hiScore"));
table.setItems(data);
table.getColumns().addAll(firstNameCol, lastNameCol);
final Button addButton = new Button("Add");
addButton.setOnAction((ActionEvent e) -> {
addButtonClicked();
});
hb.getChildren().add(addButton);
//hb.getChildren().add(button2);
hb.setSpacing(3);
nameInput = new TextField();
nameInput.setPromptText("Name");
nameInput.setMinWidth(100);
hb.getChildren().add(nameInput);
final Button exitMain = new Button("Exit to Main Menu");
exitMain.setOnAction((ActionEvent e) ->
{
HomeScreen hm1=new HomeScreen();
hm1.start(stage);
});
hb.getChildren().add(exitMain);
//hb.getChildren().add(button2);
hb.setSpacing(3);
final Button exitGame = new Button("Exit Game ");
exitGame.setOnAction((ActionEvent e)->
{
CommonClose();
});
hb.getChildren().add(exitGame);
//hb.getChildren().add(button2);
hb.setSpacing(3);
final VBox vbox = new VBox();
vbox.setSpacing(5);
vbox.setPadding(new Insets(10, 10, 10, 10));
vbox.setSpacing(10);
vbox.getChildren().addAll(table, hb);
((Group) scene.getRoot()).getChildren().addAll(vbox);
//((Group) scene.getRoot()).getChildren().add(button2);
firststage.setScene(scene);
firststage.show();
}
public void addButtonClicked()
{
Person person = new Person(nameInput.getText(),0.0d);
person.setFirstName(nameInput.getText());
table.getItems().add(person);
nameInput.clear();
}
public void addscore(String name, double score) {
Person person = new Person(name,score);
table.getItems().add(person);
}
public static class Person
{
/**
*
* Simple class definition of Person.
* This class is used for handling Persons on Leaderboard
* @since version 1.00
*/
private final SimpleStringProperty firstName;
private final SimpleDoubleProperty hiScore;
private Person(String fName, Double hiScore)
{
this.firstName = new SimpleStringProperty(fName);
this.hiScore = new SimpleDoubleProperty(hiScore);
}
/**
*
* GetFirstName method.
* The methods returns the name of the Person
*
* @return firstName
* @since version 1.00
*/
public String getFirstName()
{
return firstName.get();
}
public void setFirstName(String fName)
{
firstName.set(fName);
}
/**
*
* GetHiScore method.
* The methods returns the hiScore
*
* @return hiScore
* @since version 1.00
*/
public Double getHiScore() {
return hiScore.get();
}
// public void setHiScore(Number hiScore)
// {
// hiScore.setValue(hiScore);
// }
}
}