-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddBooksScene.java
146 lines (113 loc) · 4.28 KB
/
addBooksScene.java
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
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Group;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Parent;
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.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import java.lang.*;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
class addBooksScene extends Scene{
private TextField bookIDField;
private TextField titleField;
private TextField authorField;
private TextField publisherField;
private TextField priceField;
private MySQLManager manager;
private Stage primaryStage;
private Scene prevScene, showScene;
private Alert a = new Alert(AlertType.NONE);
showBookScene scene2;
public addBooksScene(Parent root, double width, double height){
super(root,width,height);
// vbox = new VBox();
}
public void createUI(Stage stage, Scene prevScene, Scene showScene, MySQLManager manager){
this.primaryStage = stage;
this.primaryStage.setScene(this);
this.prevScene = prevScene;
this.showScene = showScene;
this.manager = manager;
Scene here = this;
TextField tf1, tf2, tf3, tf4, tf5;
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25,25,25,25));
Label bookIDL = new Label("Enter book ID:");
grid.add(bookIDL,0,1);
tf1 = new TextField();
grid.add(tf1,1,1);
Label titleL = new Label("Enter title:");
grid.add(titleL,0,2);
tf2 = new TextField();
grid.add(tf2,1,2);
Label authorL = new Label("Enter author name:");
grid.add(authorL,0,3);
tf3 = new TextField();
grid.add(tf3,1,3);
Label publisherL = new Label("Enter publisher:");
grid.add(publisherL,0,4);
tf4 = new TextField();
grid.add(tf4,1,4);
Label priceL = new Label("Enter price:");
grid.add(priceL,0,5);
tf5 = new TextField();
grid.add(tf5,1,5);
Button addBtn = new Button("Add book");
HBox hbBtn1 = new HBox(10);
hbBtn1.setAlignment(Pos.BOTTOM_RIGHT);
hbBtn1.getChildren().add(addBtn);
grid.add(addBtn,1,7);
Button viewBtn = new Button("View booklist");
HBox hbBtn2 = new HBox(10);
hbBtn2.setAlignment(Pos.BOTTOM_RIGHT);
hbBtn2.getChildren().add(viewBtn);
grid.add(viewBtn,0,7);
viewBtn.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent e){
scene2 = new showBookScene(new Group(),600,500);
scene2.createUI(primaryStage,prevScene,here,manager);
}
});
addBtn.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent e){
if(!manager.addBooks(tf2.getText(),tf3.getText(),tf4.getText(),Double.valueOf(tf5.getText()))){
a.setAlertType(AlertType.INFORMATION);
a.setTitle("Update confirmation");
a.setHeaderText("Update not successful");
a.setContentText("That Book ID is already in use");
a.show();
}else{
tf1.setText("");
tf2.setText("");
tf3.setText("");
tf4.setText("");
tf5.setText("");
a.setAlertType(AlertType.INFORMATION);
a.setTitle("Update confirmation");
a.setHeaderText("Update successful");
a.setContentText("The book has been added.");
a.show();
}
}
});
((Group) this.getRoot()).getChildren().addAll(grid);
}
}