I had a class called GUI which contained all of the code. I decided I wanted to separate it in 3 classes: GUI, teacher, student. The problem is that in the new separated version, I can't manage to connect the databases because I get this error: [SQLITE_CANTOPEN] Unable to open the database file (out of memory).
This is how my classes look:
GUI
public class GUI extends Application
{
//Grid Panels
GridPane chooseUserButtonPane;
//Titles
Image chooseUser;
//Choose User
Button teacherButton;
Button studentButton;
Button backButton;
//Instances of other classes
Teacher teacher = new Teacher();
Student student = new Student();
//Scenes
Scene sceneChooseUser;
Stage primaryStage = new Stage();
public static void main(String[] args)
{
//when you open GUI is going to call the method launch then
//is going to go to the application and its going to set the program as a javafx application
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception
{
//Primary stage = main window
primaryStage.setTitle("Carmen Zarco Lens");
//Creating the layout of the Choose User page.
StackPane layoutChooseUser = new StackPane();
layoutChooseUser.setStyle("-fx-background-color: #FECB6E;");
//Scene of the LogIn window
sceneChooseUser = new Scene(layoutChooseUser, 1100, 650);
//This says use our scene for the primary stage
primaryStage.setScene(sceneChooseUser);
//CHOOSE USER SCENE
//Choose user title
AnchorPane chooseUserPane = new AnchorPane();
chooseUser = new Image(getClass().getResourceAsStream("chooseUser.png"));
ImageView chooseUsertitleview = new ImageView();
chooseUsertitleview.setImage(chooseUser);
chooseUserPane.getChildren().add(chooseUsertitleview);
ImageView chooseUsertitleapp = (ImageView) chooseUserPane.getChildren().get(0);
chooseUsertitleapp.setX(150);
chooseUsertitleapp.setY(10);
//top/right/bottom/left
//Choose User buttons panel
chooseUserButtonPane = new GridPane();
chooseUserButtonPane.setHgap(100);
chooseUserButtonPane.setVgap(25);
chooseUserButtonPane.setPadding(new Insets(200, 20, 0, 80));
teacherButton = new Button("TEACHER ACCOUNT");
teacherButton.setOnAction(e -> primaryStage.setScene(teacher.sceneTLogIn));
teacherButton.setPrefWidth(320.0);
teacherButton.setPrefHeight(320.0);
teacherButton.setStyle("-fx-font: 50 timesnewroman; -fx-base: #AE3522");
teacherButton.setWrapText(true);
chooseUserButtonPane.add(teacherButton,1,1);
studentButton = new Button("STUDENT ACCOUNT");
studentButton.setOnAction(e -> primaryStage.setScene(student.sceneSLogIn));
studentButton.setPrefWidth(320.0);
studentButton.setPrefHeight(320.0);
studentButton.setStyle("-fx-font: 50 timesnewroman; -fx-base: #AE3522");
studentButton.setWrapText(true);
chooseUserButtonPane.add(studentButton,2,1);
//ADD EVERYTHING TO THE LAYOUTS
//Add things to the choose User layout
layoutChooseUser.getChildren().add(chooseUserPane);
layoutChooseUser.getChildren().add(chooseUserButtonPane);
// Displays it to the user
primaryStage.setResizable(false);
primaryStage.show();
}
}
TEACHER
public class Teacher
{
//Title
Image Tlogin;
Image title;
Image addQuestions;
Image Tsignup;
//Grid Panels
GridPane TloginButtonPane;
GridPane TsignupButtonPane;
GridPane addQButtonPane;
GridPane backButtonPane;
//Teacher Login
TextField userTextFieldT;
PasswordField passwordTextFieldT;
Button TloginButton;
Button TsignupButton;
Label TloginProblemLabel;
Button backButton;
//Teacher SignUp
Label nameSignupTLabel;
TextField nameSignupTTextField;
Label lastnameSignupTLabel;
TextField lastnameSignupTTextField;
Label usernameSignupTLabel;
TextField usernameSignupTTextField;
Label passwordSignupTLabel;
TextField passwordSignupTTextField;
Button saveTButton;
//Add Question
Label typeQLabel;
Label subjectLabel;
RadioButton mathRB;
RadioButton historyRB;
RadioButton geographyRB;
RadioButton sciencesRB;
RadioButton spanishRB;
RadioButton physicsRB;
String textSubjectQ;
RadioButton typeQ1;
RadioButton typeQ2;
RadioButton typeQ3;
String textTypeQ;
Label levelLabel;
ToggleButton easyLevelButton;
ToggleButton mediumLevelButton;
ToggleButton highLevelButton;
String textLevelQ;
Label speedLabel;
String textSpeedQ;
TextField speedTextField;
Label contentQLabel;
TextField contentQTextField;
Label answerQLabel;
static TextField answerQTextField;
Button doneButton;
Button addQButton;
Label problemLabel;
Label questionTextLabel;
//Connecting to the databases
Connection connectionQuestions = null;
Connection connectionUsers = null;
//Instance GUI
GUI gui;
//Scenes
Scene sceneTLogIn;
public Teacher()
{
connectionQuestions = questionssqliteConnection.dbConnector();
connectionUsers = userssqliteConnection.UdbConnector();
gui = new GUI();
}
public void main(String[] args)
{
//Creating the layout of the Teacher LogIn page.
StackPane layoutTLogIn = new StackPane();
layoutTLogIn.setStyle("-fx-background-color: #FECB6E;");
//Creating the layout of the teachers SignUp.
StackPane layoutTSignUp = new StackPane();
layoutTSignUp.setStyle("-fx-background-color: #FECB6E;");
//Creating the layout of the Teacher LogIn page.
StackPane layoutAddQ = new StackPane();
layoutAddQ.setStyle("-fx-background-color: #FECB6E;");
//Scene of the Teacher LogIn window
sceneTLogIn = new Scene(layoutTLogIn, 1100, 650);
//Scene of the Teacher SignUP window
Scene sceneTSignUp = new Scene(layoutTSignUp, 1100, 650);
//Scene of the Teacher to add questions to the database
Scene sceneAddQ = new Scene(layoutAddQ, 1100, 650);
//TEACHER SIGN UP SCENE
//Login title
AnchorPane TsignupPane = new AnchorPane();
Tsignup = new Image(getClass().getResourceAsStream("singup.png"));
ImageView Tsignuptitleview = new ImageView();
Tsignuptitleview.setImage(Tsignup);
TsignupPane.getChildren().add(Tsignuptitleview);
ImageView Tsignuptitleapp = (ImageView) TsignupPane.getChildren().get(0);
Tsignuptitleapp.setX(300);
Tsignuptitleapp.setY(10);
//top/right/bottom/left
//Teacher signup buttons panel
TsignupButtonPane = new GridPane();
TsignupButtonPane.setHgap(50);
TsignupButtonPane.setVgap(30);
TsignupButtonPane.setPadding(new Insets(150, 10, 0, 140));
nameSignupTLabel = new Label("First Name:");
nameSignupTLabel.setPrefWidth(250.0);
nameSignupTLabel.setPrefHeight(50.0);
nameSignupTLabel.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522; -fx-text-fill: black;");
TsignupButtonPane.add(nameSignupTLabel,1,1);
nameSignupTTextField = new TextField();
nameSignupTTextField.setPrefWidth(400.0);
nameSignupTTextField.setPrefHeight(60.0);
nameSignupTTextField.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522; -fx-text-fill: black;");
TsignupButtonPane.add(nameSignupTTextField,2,1);
lastnameSignupTLabel = new Label("Last Name:");
lastnameSignupTLabel.setPrefWidth(250.0);
lastnameSignupTLabel.setPrefHeight(50.0);
lastnameSignupTLabel.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522; -fx-text-fill: black;");
TsignupButtonPane.add(lastnameSignupTLabel,1,2);
lastnameSignupTTextField = new TextField();
lastnameSignupTTextField.setPrefWidth(400.0);
lastnameSignupTTextField.setPrefHeight(60.0);
lastnameSignupTTextField.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522; -fx-text-fill: black;");
TsignupButtonPane.add(lastnameSignupTTextField,2,2);
usernameSignupTLabel = new Label("UserName:");
usernameSignupTLabel.setPrefWidth(250.0);
usernameSignupTLabel.setPrefHeight(50.0);
usernameSignupTLabel.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522; -fx-text-fill: black;");
TsignupButtonPane.add(usernameSignupTLabel,1,3);
usernameSignupTTextField = new TextField();
usernameSignupTTextField.setPrefWidth(400.0);
usernameSignupTTextField.setPrefHeight(60.0);
usernameSignupTTextField.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522; -fx-text-fill: black;");
TsignupButtonPane.add(usernameSignupTTextField,2,3);
passwordSignupTLabel = new Label("Password:");
passwordSignupTLabel.setPrefWidth(250.0);
passwordSignupTLabel.setPrefHeight(50.0);
passwordSignupTLabel.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522; -fx-text-fill: black;");
TsignupButtonPane.add(passwordSignupTLabel,1,4);
passwordSignupTTextField = new TextField();
passwordSignupTTextField.setPrefWidth(400.0);
passwordSignupTTextField.setPrefHeight(60.0);
passwordSignupTTextField.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522; -fx-text-fill: black;");
TsignupButtonPane.add(passwordSignupTTextField,2,4);
saveTButton = new Button("SAVE INFORMATION");
saveTButton.addEventHandler(ActionEvent.ACTION, (e)-> {
try
{
String query = "insert into TeachersInfo (\"First Name\",\"Last Name\",UserName,Password) values (?,?,?,?)";
//String query = "insert into TeachersInfo (First Name,Last Name,UserName,Password) values (?,?,?,?)";
PreparedStatement pst = connectionUsers.prepareStatement(query);
//First question mark = 1, second = 2, etc.
pst.setString(1,nameSignupTTextField.getText());
pst.setString(2,lastnameSignupTTextField.getText());
pst.setString(3,usernameSignupTTextField.getText());
pst.setString(4,passwordSignupTTextField.getText());
pst.execute();
System.out.println("Data saved");
//after executing the query this lines will close the connection with the database
pst.close();
}
catch(Exception a)
{
System.out.println(a);
}
gui.primaryStage.setScene(gui.sceneChooseUser);
});
saveTButton.setPrefWidth(700.0);
saveTButton.setPrefHeight(60.0);
saveTButton.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522;;");
TsignupButtonPane.add(saveTButton,1,5,2,1);
//TEACHER LOGIN SCENE
//Login title
AnchorPane TloginPane = new AnchorPane();
Tlogin = new Image(getClass().getResourceAsStream("Tlogin.png"));
ImageView Tlogintitleview = new ImageView();
Tlogintitleview.setImage(Tlogin);
TloginPane.getChildren().add(Tlogintitleview);
ImageView Tlogintitleapp = (ImageView) TloginPane.getChildren().get(0);
Tlogintitleapp.setX(130);
Tlogintitleapp.setY(10);
//top/right/bottom/left
//Login buttons panel
TloginButtonPane = new GridPane();
TloginButtonPane.setHgap(100);
TloginButtonPane.setVgap(25);
TloginButtonPane.setPadding(new Insets(200, 10, 0, 10));
userTextFieldT = new TextField("User Name");
userTextFieldT.setPrefWidth(400.0);
userTextFieldT.setPrefHeight(60.0);
userTextFieldT.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522");
TloginButtonPane.add(userTextFieldT,2,1);
passwordTextFieldT = new PasswordField();
passwordTextFieldT.setText("Password");
passwordTextFieldT.setPrefWidth(400.0);
passwordTextFieldT.setPrefHeight(60.0);
passwordTextFieldT.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522");
TloginButtonPane.add(passwordTextFieldT,2,2);
TloginButton = new Button("LOGIN");
TloginButton.addEventHandler(ActionEvent.ACTION, (e)-> {
try
{
String query = "select * from TeachersInfo where username=? and password=? ";
PreparedStatement pst = connectionUsers.prepareStatement(query);
//First question mark = 1, second = 2, etc.
pst.setString(1,userTextFieldT.getText());
pst.setString(2,passwordTextFieldT.getText());
//Exescute the query
ResultSet rs = pst.executeQuery();
int count = 0;
while(rs.next())
{
count = count+1;
}
if(count == 1)
{
gui.primaryStage.setScene(sceneAddQ);
}
else if(count >1)
{
}
else
{
TloginProblemLabel.setText("!!User name or password incorrect!!");
gui.primaryStage.setScene(sceneTLogIn);
}
//after executing the query this lines will close the connection with the database
rs.close();
pst.close();
}
catch(Exception a)
{
System.out.println(a);
}
});
TloginButton.setPrefWidth(400.0);
TloginButton.setPrefHeight(60.0);
TloginButton.setStyle("-fx-font: 40 timesnewroman; -fx-base: #AE3522");
TloginButtonPane.add(TloginButton,2,3);
TloginProblemLabel = new Label();
TloginProblemLabel.setPrefWidth(600.0);
TloginProblemLabel.setPrefHeight(50.0);
TloginProblemLabel.setStyle("-fx-font: 21 timesnewroman; -fx-base: #AE3522; -fx-text-fill: red;");
TloginButtonPane.add(TloginProblemLabel,1,4,2,1);
backButton = new Button("BACK");
backButton.setOnAction(e -> gui.primaryStage.setScene(gui.sceneChooseUser));
backButton.setPrefWidth(140.0);
backButton.setPrefHeight(50.0);
backButton.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522;");
TloginButtonPane.add(backButton,1,5);
TsignupButton = new Button("SIGN UP");
TsignupButton.setOnAction(e -> gui.primaryStage.setScene(sceneTSignUp));
TsignupButton.setPrefWidth(180.0);
TsignupButton.setPrefHeight(50.0);
TsignupButton.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522");
TloginButtonPane.add(TsignupButton,3,5);
//ADD QUESTIONS TO THE DATABASE
//Own questions title
AnchorPane addQpane = new AnchorPane();
addQuestions = new Image(getClass().getResourceAsStream("addQuestions.png"));
ImageView addQtitleview = new ImageView();
addQtitleview.setImage(addQuestions);
addQpane.getChildren().add(addQtitleview);
ImageView addQtitleapp = (ImageView) addQpane.getChildren().get(0);
addQtitleapp.setX(90);
addQtitleapp.setY(10);
//Own questions buttons
addQButtonPane = new GridPane();
addQButtonPane.setHgap(10);
addQButtonPane.setVgap(20);
addQButtonPane.setPadding(new Insets(10, 100, 0, 100));
addQButtonPane.setStyle("-fx-background-color: #FECB6E;");
subjectLabel = new Label("Subject:");
subjectLabel.setPrefWidth(300.0);
subjectLabel.setPrefHeight(70.0);
subjectLabel.setStyle("-fx-font: 30 timesnewroman; -fx-base: #190707;-fx-text-fill: black;");
addQButtonPane.add(subjectLabel,1,1);
//Putting the radio buttons in a toggleGroup so that they are mutually exclusive.
ToggleGroup groupSubject = new ToggleGroup();
mathRB = new RadioButton("Math");
mathRB.setPrefWidth(200.0);
mathRB.setPrefHeight(40.0);
mathRB.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;-fx-text-fill: black;");
mathRB.setToggleGroup(groupSubject);
addQButtonPane.add(mathRB,1,2);
historyRB = new RadioButton("History");
historyRB.setPrefWidth(200.0);
historyRB.setPrefHeight(40.0);
historyRB.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;-fx-text-fill: black;");
historyRB.setToggleGroup(groupSubject);
addQButtonPane.add(historyRB,2,2);
spanishRB = new RadioButton("Spanish");
spanishRB.setPrefWidth(200.0);
spanishRB.setPrefHeight(40.0);
spanishRB.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;-fx-text-fill: black;");
spanishRB.setToggleGroup(groupSubject);
addQButtonPane.add(spanishRB,3,2);
physicsRB = new RadioButton("Physics");
physicsRB.setPrefWidth(200.0);
physicsRB.setPrefHeight(40.0);
physicsRB.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;-fx-text-fill: black;");
physicsRB.setToggleGroup(groupSubject);
addQButtonPane.add(physicsRB,1,3);
sciencesRB = new RadioButton("Sciences");
sciencesRB.setPrefWidth(200.0);
sciencesRB.setPrefHeight(40.0);
sciencesRB.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;-fx-text-fill: black;");
sciencesRB.setToggleGroup(groupSubject);
addQButtonPane.add(sciencesRB,2,3);
geographyRB = new RadioButton("Geography");
geographyRB.setPrefWidth(200.0);
geographyRB.setPrefHeight(40.0);
geographyRB.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;-fx-text-fill: black;");
geographyRB.setToggleGroup(groupSubject);
addQButtonPane.add(geographyRB,3,3);
mathRB.setUserData("Math");
historyRB.setUserData("History");
spanishRB.setUserData("Spanish");
physicsRB.setUserData("Physics");
sciencesRB.setUserData("Sciences");
geographyRB.setUserData("Geography");
groupSubject.selectedToggleProperty().addListener(new ChangeListener<Toggle>(){
public void changed(ObservableValue<? extends Toggle> ov,
Toggle toggle, Toggle new_toggle)
{
if (new_toggle != null)
{
textSubjectQ = (String) groupSubject.getSelectedToggle().getUserData();
}
}
});
typeQLabel = new Label("Type of Question:");
typeQLabel.setPrefWidth(350.0);
typeQLabel.setPrefHeight(70.0);
typeQLabel.setStyle("-fx-font: 30 timesnewroman; -fx-base: #190707;-fx-text-fill: black;");
addQButtonPane.add(typeQLabel,1,5);
//Putting the radio buttons in a toggleGroup so that they are mutually exclusive.
ToggleGroup groupTypeQ = new ToggleGroup();
typeQ1 = new RadioButton("Connect with Arrows");
typeQ1.setPrefWidth(350.0);
typeQ1.setPrefHeight(40.0);
typeQ1.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;-fx-text-fill: black;");
typeQ1.setToggleGroup(groupTypeQ);
addQButtonPane.add(typeQ1,1,6);
typeQ2 = new RadioButton("Choose Answer");
typeQ2.setPrefWidth(350.0);
typeQ2.setPrefHeight(40.0);
typeQ2.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;-fx-text-fill: black;");
typeQ2.setToggleGroup(groupTypeQ);
addQButtonPane.add(typeQ2,2,6);
typeQ3 = new RadioButton("Introduce Answer");
typeQ3.setPrefWidth(250.0);
typeQ3.setPrefHeight(40.0);
typeQ3.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;-fx-text-fill: black;");
typeQ3.setToggleGroup(groupTypeQ);
addQButtonPane.add(typeQ3,3,6);
typeQ1.setUserData("Connect with Arrows");
typeQ2.setUserData("Choose Answer");
typeQ3.setUserData("Introduce Answer");
groupTypeQ.selectedToggleProperty().addListener(new ChangeListener<Toggle>(){
public void changed(ObservableValue<? extends Toggle> ov,
Toggle toggle, Toggle new_toggle)
{
if (new_toggle != null)
{
textTypeQ = (String) groupTypeQ.getSelectedToggle().getUserData();
}
}
});
levelLabel = new Label("Level:");
levelLabel.setPrefWidth(220.0);
levelLabel.setPrefHeight(70.0);
levelLabel.setStyle("-fx-font: 30 timesnewroman; -fx-base: #190707;-fx-text-fill: black;");
addQButtonPane.add(levelLabel,1,8);
ToggleGroup groupLevelQ = new ToggleGroup();
easyLevelButton = new ToggleButton("EASY");
//easyLevelButton.setOnAction(e -> primaryStage.setScene(sceneOwnQ));
easyLevelButton.setPrefWidth(150.0);
easyLevelButton.setPrefHeight(50.0);
easyLevelButton.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;");
easyLevelButton.setToggleGroup(groupLevelQ);
addQButtonPane.add(easyLevelButton,1,9);
mediumLevelButton = new ToggleButton("MEDIUM");
//mediumLevelButton.setOnAction(e -> primaryStage.setScene(sceneOwnQ));
mediumLevelButton.setPrefWidth(150.0);
mediumLevelButton.setPrefHeight(50.0);
mediumLevelButton.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;");
mediumLevelButton.setToggleGroup(groupLevelQ);
addQButtonPane.add(mediumLevelButton,2,9);
highLevelButton = new ToggleButton("HIGH");
//highLevelButton.setOnAction(e -> primaryStage.setScene(sceneOwnQ));
highLevelButton.setPrefWidth(150.0);
highLevelButton.setPrefHeight(50.0);
highLevelButton.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;");
highLevelButton.setToggleGroup(groupLevelQ);
addQButtonPane.add(highLevelButton,3,9);
easyLevelButton.setUserData("Easy");
mediumLevelButton.setUserData("Medium");
highLevelButton.setUserData("High");
groupLevelQ.selectedToggleProperty().addListener(new ChangeListener<Toggle>(){
public void changed(ObservableValue<? extends Toggle> ov,
Toggle toggle, Toggle new_toggle)
{
if (new_toggle != null)
{
textLevelQ = (String) groupLevelQ.getSelectedToggle().getUserData();
}
}
});
speedLabel = new Label("Speed:");
speedLabel.setPrefWidth(220.0);
speedLabel.setPrefHeight(70.0);
speedLabel.setStyle("-fx-font: 30 timesnewroman; -fx-base: #190707;-fx-text-fill: black;");
addQButtonPane.add(speedLabel,1,11);
speedTextField = new TextField("minutes");
speedTextField.setPrefWidth(50.0);
speedTextField.setPrefHeight(50.0);
speedTextField.setStyle("-fx-font: 20 timesnewroman; -fx-base: #190707;-fx-text-fill: black;");
// page.add(Node, colIndex, rowIndex, colSpan, rowSpan):
addQButtonPane.add(speedTextField, 2, 11);
contentQLabel = new Label("Content of the Question:");
contentQLabel.setPrefWidth(600.0);
contentQLabel.setPrefHeight(50.0);
contentQLabel.setStyle("-fx-font: 30 timesnewroman; -fx-base: #190707;-fx-text-fill: black;");
//This makes the label to be occupying more than one column so the other smaller buttons don't move.
addQButtonPane.add(contentQLabel, 1, 13, 2, 1);
contentQTextField = new TextField();
contentQTextField.setPrefWidth(800.0);
contentQTextField.setPrefHeight(50.0);
contentQTextField.setStyle("-fx-font: 20 timesnewroman; -fx-base: #190707;-fx-text-fill: black;");
// page.add(Node, colIndex, rowIndex, colSpan, rowSpan):
addQButtonPane.add(contentQTextField, 1, 14, 3, 1);
answerQLabel = new Label("Answer of the Question:");
answerQLabel.setPrefWidth(600.0);
answerQLabel.setPrefHeight(50.0);
answerQLabel.setStyle("-fx-font: 30 timesnewroman; -fx-base: #190707;-fx-text-fill: black;");
//This makes the label to be occupying more than one column so the other smaller buttons don't move.
addQButtonPane.add(answerQLabel, 1, 16, 2, 1);
answerQTextField = new TextField();
answerQTextField.setPrefWidth(800.0);
answerQTextField.setPrefHeight(50.0);
answerQTextField.setStyle("-fx-font: 20 timesnewroman; -fx-base: #190707;-fx-text-fill: black;");
// page.add(Node, colIndex, rowIndex, colSpan, rowSpan):
addQButtonPane.add(answerQTextField, 1, 17, 3, 1);
doneButton = new Button("DONE");
doneButton.addEventHandler(ActionEvent.ACTION, (e)-> {
gui.primaryStage.setScene(gui.sceneChooseUser);
problemLabel.setText(null);
});
doneButton.setPrefWidth(140.0);
doneButton.setPrefHeight(50.0);
doneButton.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522");
addQButtonPane.add(doneButton,1,21);
addQButton = new Button("ADD QUESTION");
//Adding more that one action to a button;
addQButton.addEventHandler(ActionEvent.ACTION, (e)-> {
try
{
String query = "insert into Questions (Subject,Type,Level,Speed,Question,Answer) values (?,?,?,?,?,?)";
PreparedStatement pst = connectionQuestions.prepareStatement(query);
//First question mark = 1, second = 2, etc.
pst.setString(1,textSubjectQ);
pst.setString(2,textTypeQ);
pst.setString(3,textLevelQ);
//pst.setString(4,textSpeedQ);
pst.setString(4,speedTextField.getText());
pst.setString(5,contentQTextField.getText());
pst.setString(6,answerQTextField.getText());
pst.execute();
System.out.println("Data saved");
//after executing the query this lines will close the connection with the database
pst.close();
}
catch(Exception a)
{
System.out.println(a);
}
gui.primaryStage.setScene(sceneAddQ);
});
addQButton.setPrefWidth(350.0);
addQButton.setPrefHeight(50.0);
addQButton.setStyle("-fx-font: 25 timesnewroman; -fx-base: #2EFE64; -fx-text-fill: black;");
addQButtonPane.add(addQButton,3,21);
problemLabel = new Label();
problemLabel.setPrefWidth(600.0);
problemLabel.setPrefHeight(50.0);
problemLabel.setStyle("-fx-font: 21 timesnewroman; -fx-base: #AE3522; -fx-text-fill: red;");
addQButtonPane.add(problemLabel,1,22,4,1);
//Pane to be able to have a scrollbar
ScrollPane sp = new ScrollPane();
sp.setFitToWidth(true);
ScrollBar s1 = new ScrollBar();
s1.setOrientation(Orientation.VERTICAL);
sp.setContent(s1);
sp.setContent(addQButtonPane);
sp.setStyle("-fx-background-color: #FECB6E;");
//Makes possible to have two panes in the same scene/layout
HBox hBoxAddQ = new HBox();
hBoxAddQ.setSpacing(10.0);
hBoxAddQ.setPadding(new Insets(140,10,50,10));
hBoxAddQ.getChildren().addAll(addQButtonPane, sp);
//Add things to the teacher login layout
layoutTLogIn.getChildren().add(TloginPane);
layoutTLogIn.getChildren().add(TloginButtonPane);
//Add things to the teacher signup layout
layoutTSignUp.getChildren().add(TsignupPane);
layoutTSignUp.getChildren().add(TsignupButtonPane);
//Add things to the add questions to database by the teacher
layoutAddQ.getChildren().add(addQpane);
layoutAddQ.getChildren().add(hBoxAddQ);
}
}
The student class looks basically the same and then I have the classes to connect the databases.One of them with the questions database and the other one with the users database. They both look the same. For example, one of the two looks like this:
DATABASE CONNECTION
public class questionssqliteConnection
{
Connection conn = null;
public static Connection dbConnector()
{
try
{
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("jdbc:sqlite:/Users/cachuti/Documents/Questions.sqlite");
System.out.println("Connection");
return conn;
}
catch(Exception e)
{
System.out.println(e);
return null;
}
}
}
So, as I said, before I had one big class with all the infromation that now is in GUI, Teacher, and Student and it worked. I really dont know what is the problem so i would really appreciate the help. Thank you so much in advance.
Aucun commentaire:
Enregistrer un commentaire