-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputEditRow.java
More file actions
78 lines (65 loc) · 2.5 KB
/
InputEditRow.java
File metadata and controls
78 lines (65 loc) · 2.5 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
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.geometry.*;
import java.lang.*;
import javafx.scene.control.Button;
import javafx.event.*;
import java.util.*;
class InputEditRow {
public static void display(Table table) {
Stage window = new Stage();
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle("Edit Rows");
window.setMinWidth(250);
VBox layout = new VBox(10);
Label instruction = new Label("Type in the record's row and column to Edit:");
TextField input = new TextField();
input.setPrefWidth(100);
Label instruction1 = new Label("Type in the new value:");
TextField value = new TextField();
value.setPrefWidth(100);
HBox bottomLayout = new HBox(20);
Button confirm = new Button("Confirm");
Button cancel = new Button("Cancel");
confirm.setOnAction(e -> {
String rowinfo1 = input.getText();
String[] toEdit = rowinfo1.split(",");
String toupdate = value.getText();
int[] position = new int[2];
// System.out.println(table.getRecords().getRecordsNumber());
for (int i = 0; i < 2; i++) {
if (isInteger(toEdit[i])){
position[i] = Integer.parseInt(toEdit[i]);
}
else {
AlertBox.display("Error", "Please type in corrent number.");
window.close();
}
}
if (!table.updateRow(position[0], position[1], toupdate)) {
AlertBox.display("Error", "Please type in valid value.");
window.close();
}
window.close();
});
// System.out.println(table.getRecords().getRecordsNumber());
cancel.setOnAction(e -> window.close());
bottomLayout.getChildren().addAll(confirm, cancel);
bottomLayout.setPadding(new Insets(20,0,0,0));
layout.getChildren().addAll(instruction, input, instruction1, value, bottomLayout);
layout.setPadding(new Insets(30,20,30,20));
Scene scene = new Scene(layout, 300, 300);
window.setScene(scene);
window.showAndWait();
}
static boolean isInteger(String s) {
if(s.isEmpty()) return false;
for (int i = 0; i < s.length(); i++) {
if(Character.digit(s.charAt(i),10) < 0)
return false;
}
return true;
}
}