From 3953be62d2958fb0ba35c0039bff4ef5ea1d9f79 Mon Sep 17 00:00:00 2001 From: RobinSrk Date: Tue, 13 Sep 2022 19:45:52 +0600 Subject: [PATCH 01/86] renamed files --- src/main/java/com/example/quizmanagement/MainApplication.java | 2 +- .../example/quizmanagement/{hello-view.fxml => main-view.fxml} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/main/resources/com/example/quizmanagement/{hello-view.fxml => main-view.fxml} (100%) diff --git a/src/main/java/com/example/quizmanagement/MainApplication.java b/src/main/java/com/example/quizmanagement/MainApplication.java index 6dd79c9..db14fe4 100644 --- a/src/main/java/com/example/quizmanagement/MainApplication.java +++ b/src/main/java/com/example/quizmanagement/MainApplication.java @@ -10,7 +10,7 @@ public class MainApplication extends Application { @Override public void start(Stage stage) throws IOException { - FXMLLoader fxmlLoader = new FXMLLoader(MainApplication.class.getResource("hello-view.fxml")); + FXMLLoader fxmlLoader = new FXMLLoader(MainApplication.class.getResource("main-view.fxml")); Scene scene = new Scene(fxmlLoader.load(), 520, 340); stage.setTitle("Online java quiz management system"); stage.setScene(scene); diff --git a/src/main/resources/com/example/quizmanagement/hello-view.fxml b/src/main/resources/com/example/quizmanagement/main-view.fxml similarity index 100% rename from src/main/resources/com/example/quizmanagement/hello-view.fxml rename to src/main/resources/com/example/quizmanagement/main-view.fxml From c04709ae2f5f5e9052ac5bcfb11df382c92ae1fa Mon Sep 17 00:00:00 2001 From: RobinSrk Date: Tue, 13 Sep 2022 23:16:55 +0600 Subject: [PATCH 02/86] updated design and file names --- .../example/quizmanagement/MainApplication.java | 2 +- .../com/example/quizmanagement/hello-view.fxml | 16 ---------------- .../com/example/quizmanagement/main-view.fxml | 15 +++++++++++++++ 3 files changed, 16 insertions(+), 17 deletions(-) delete mode 100644 src/main/resources/com/example/quizmanagement/hello-view.fxml create mode 100644 src/main/resources/com/example/quizmanagement/main-view.fxml diff --git a/src/main/java/com/example/quizmanagement/MainApplication.java b/src/main/java/com/example/quizmanagement/MainApplication.java index 4d22226..ab83cd7 100644 --- a/src/main/java/com/example/quizmanagement/MainApplication.java +++ b/src/main/java/com/example/quizmanagement/MainApplication.java @@ -10,7 +10,7 @@ public class MainApplication extends Application { @Override public void start(Stage stage) throws IOException { - FXMLLoader fxmlLoader = new FXMLLoader(MainApplication.class.getResource("hello-view.fxml")); + FXMLLoader fxmlLoader = new FXMLLoader(MainApplication.class.getResource("main-view.fxml")); Scene scene = new Scene(fxmlLoader.load(), 820, 640); stage.setTitle("Online java quiz management system"); stage.setScene(scene); diff --git a/src/main/resources/com/example/quizmanagement/hello-view.fxml b/src/main/resources/com/example/quizmanagement/hello-view.fxml deleted file mode 100644 index aa58f1b..0000000 --- a/src/main/resources/com/example/quizmanagement/hello-view.fxml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - + + + From 32a273d04155ba8e76248aebef03d756b3448050 Mon Sep 17 00:00:00 2001 From: RobinSrk Date: Thu, 22 Sep 2022 13:24:21 +0600 Subject: [PATCH 25/86] renamed some files --- .../com/example/quizmanagement/add-view.fxml | 102 ++++++++++++++++++ .../com/example/quizmanagement/quiz.css | 16 --- .../quizmanagement/{main.css => styles.css} | 6 +- 3 files changed, 105 insertions(+), 19 deletions(-) create mode 100644 src/main/resources/com/example/quizmanagement/add-view.fxml delete mode 100644 src/main/resources/com/example/quizmanagement/quiz.css rename src/main/resources/com/example/quizmanagement/{main.css => styles.css} (89%) diff --git a/src/main/resources/com/example/quizmanagement/add-view.fxml b/src/main/resources/com/example/quizmanagement/add-view.fxml new file mode 100644 index 0000000..bb10ffc --- /dev/null +++ b/src/main/resources/com/example/quizmanagement/add-view.fxml @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/com/example/quizmanagement/quiz.css b/src/main/resources/com/example/quizmanagement/quiz.css deleted file mode 100644 index 9a5d897..0000000 --- a/src/main/resources/com/example/quizmanagement/quiz.css +++ /dev/null @@ -1,16 +0,0 @@ -#next-button{ - -fx-background-color: #6c63ff; - -fx-padding: 13px; - -fx-border-insets: 5px; - -fx-background-insets: 5px; - -fx-text-fill: white; - -fx-background-radius: 10px; -} -#back-button{ - -fx-background-color: #fa6f66; - -fx-background-radius: 10px; - -fx-padding: 13px; - -fx-border-insets: 5px; - -fx-background-insets: 5px; - -fx-text-fill: white; -} diff --git a/src/main/resources/com/example/quizmanagement/main.css b/src/main/resources/com/example/quizmanagement/styles.css similarity index 89% rename from src/main/resources/com/example/quizmanagement/main.css rename to src/main/resources/com/example/quizmanagement/styles.css index 766ccd5..e89197f 100644 --- a/src/main/resources/com/example/quizmanagement/main.css +++ b/src/main/resources/com/example/quizmanagement/styles.css @@ -1,4 +1,4 @@ -#test-button{ +#blue-button{ -fx-border-width: 5px; -fx-fill: #ff0000; -fx-background-color: #6c63ff; @@ -6,10 +6,10 @@ -fx-padding: 8px; -fx-text-fill: white; } -#add-button{ +#purple-button{ -fx-border-width: 0px; -fx-background-color: #fa6f66; -fx-background-radius: 10px; -fx-padding: 8px; -fx-text-fill: white; -} \ No newline at end of file +} From 9015864ae013a6ca769599419c5352116a4444df Mon Sep 17 00:00:00 2001 From: RobinSrk Date: Thu, 22 Sep 2022 13:25:13 +0600 Subject: [PATCH 26/86] updated css class names --- .../resources/com/example/quizmanagement/main-view.fxml | 6 +++--- .../resources/com/example/quizmanagement/quiz-view.fxml | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/resources/com/example/quizmanagement/main-view.fxml b/src/main/resources/com/example/quizmanagement/main-view.fxml index 3a23f83..7a2b0fc 100644 --- a/src/main/resources/com/example/quizmanagement/main-view.fxml +++ b/src/main/resources/com/example/quizmanagement/main-view.fxml @@ -15,8 +15,8 @@ - - - + + + + diff --git a/src/main/resources/com/example/quizmanagement/question-view.fxml b/src/main/resources/com/example/quizmanagement/question-view.fxml deleted file mode 100644 index bb10ffc..0000000 --- a/src/main/resources/com/example/quizmanagement/question-view.fxml +++ /dev/null @@ -1,102 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 8e5fd7f7d1240d23f80329f25d337ac28e261e82 Mon Sep 17 00:00:00 2001 From: RobinSrk Date: Thu, 22 Sep 2022 21:02:00 +0600 Subject: [PATCH 31/86] updated window navigation functionality --- .../example/quizmanagement/AddQuestionController.java | 9 +-------- .../java/com/example/quizmanagement/LoginController.java | 9 ++------- .../java/com/example/quizmanagement/MainController.java | 8 ++------ .../java/com/example/quizmanagement/QuizController.java | 4 +--- 4 files changed, 6 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/example/quizmanagement/AddQuestionController.java b/src/main/java/com/example/quizmanagement/AddQuestionController.java index 3f32fa5..144a273 100644 --- a/src/main/java/com/example/quizmanagement/AddQuestionController.java +++ b/src/main/java/com/example/quizmanagement/AddQuestionController.java @@ -19,25 +19,18 @@ public class AddQuestionController { @FXML private Button goBack; - - @FXML private Label error; @FXML private TextArea question; - @FXML private VBox container; @FXML private TextField op1, op2, op3, op4, cro; - @FXML - private Button submit; @FXML private void onClickGoBack() throws Exception { - Stage stage = (Stage) goBack.getScene().getWindow(); - stage.close(); - Stage primaryStage = new Stage(); + Stage primaryStage = (Stage) goBack.getScene().getWindow(); Parent root = FXMLLoader.load(getClass().getResource("main-view.fxml")); root.getStylesheets().add(getClass().getResource("/com/example/quizmanagement/styles.css").toExternalForm()); primaryStage.setTitle("Online Java Quiz Management System"); diff --git a/src/main/java/com/example/quizmanagement/LoginController.java b/src/main/java/com/example/quizmanagement/LoginController.java index 690acaa..2687724 100644 --- a/src/main/java/com/example/quizmanagement/LoginController.java +++ b/src/main/java/com/example/quizmanagement/LoginController.java @@ -30,7 +30,6 @@ private void onLogin() throws Exception { if (username.getText().equals("") || pass.getText().equals("")) { error.setText("Please fill all fields"); } else { - // convert pass.getText() to md5 MessageDigest md = MessageDigest.getInstance("MD5"); byte[] bytes = md.digest(pass.getText().getBytes()); BigInteger no = new BigInteger(1, bytes); @@ -46,9 +45,7 @@ private void onLogin() throws Exception { "`password` = " + "'" + hashedPass + "'"); if (rs != null && rs.next()) { Credentials.setLoggedIn(true); - Stage stage = (Stage) cancel.getScene().getWindow(); - stage.close(); - Stage primaryStage = new Stage(); + Stage primaryStage = (Stage) cancel.getScene().getWindow(); Parent root = FXMLLoader.load(getClass().getResource("add-view.fxml")); root.getStylesheets().add(getClass().getResource("/com/example/quizmanagement/styles.css").toExternalForm()); primaryStage.setTitle("Online Java Quiz Management System"); @@ -62,9 +59,7 @@ private void onLogin() throws Exception { @FXML private void onCancel() throws Exception { - Stage stage = (Stage) cancel.getScene().getWindow(); - stage.close(); - Stage primaryStage = new Stage(); + Stage primaryStage = (Stage) cancel.getScene().getWindow(); Parent root = FXMLLoader.load(getClass().getResource("main-view.fxml")); root.getStylesheets().add(getClass().getResource("/com/example/quizmanagement/styles.css").toExternalForm()); primaryStage.setTitle("Online Java Quiz Management System"); diff --git a/src/main/java/com/example/quizmanagement/MainController.java b/src/main/java/com/example/quizmanagement/MainController.java index 274f774..6749161 100644 --- a/src/main/java/com/example/quizmanagement/MainController.java +++ b/src/main/java/com/example/quizmanagement/MainController.java @@ -16,9 +16,7 @@ public class MainController { @FXML private void onClickAddButton() throws Exception { - Stage stage = (Stage) addButton.getScene().getWindow(); - stage.close(); - Stage primaryStage = new Stage(); + Stage primaryStage = (Stage) addButton.getScene().getWindow(); System.out.println(Credentials.isLoggedIn()); if (Credentials.isLoggedIn()) { Parent root = FXMLLoader.load(getClass().getResource("add-view.fxml")); @@ -37,9 +35,7 @@ private void onClickAddButton() throws Exception { @FXML private void onClickTestButton() throws Exception { - Stage stage = (Stage) testButton.getScene().getWindow(); - stage.close(); - Stage primaryStage = new Stage(); + Stage primaryStage = (Stage) testButton.getScene().getWindow(); Parent root = FXMLLoader.load(getClass().getResource("quiz-view.fxml")); root.getStylesheets().add(getClass().getResource("/com/example/quizmanagement/styles.css").toExternalForm()); primaryStage.setTitle("Test"); diff --git a/src/main/java/com/example/quizmanagement/QuizController.java b/src/main/java/com/example/quizmanagement/QuizController.java index 20b7481..27259c5 100644 --- a/src/main/java/com/example/quizmanagement/QuizController.java +++ b/src/main/java/com/example/quizmanagement/QuizController.java @@ -87,9 +87,7 @@ public void changed(ObservableValue observableValue, Toggle to @FXML private void onClickGoBack() throws Exception { - Stage stage = (Stage) goBack.getScene().getWindow(); - stage.close(); - Stage primaryStage = new Stage(); + Stage primaryStage = (Stage) goBack.getScene().getWindow(); Parent root = FXMLLoader.load(getClass().getResource("main-view.fxml")); root.getStylesheets().add(getClass().getResource("/com/example/quizmanagement/styles.css").toExternalForm()); primaryStage.setTitle("Online Java Quiz Management System"); From bb8db6632e018c0fdfba417849e159314cffa2bb Mon Sep 17 00:00:00 2001 From: RobinSrk Date: Thu, 22 Sep 2022 21:15:41 +0600 Subject: [PATCH 32/86] removed unused codes --- src/main/java/com/example/quizmanagement/LoginController.java | 1 - src/main/java/com/example/quizmanagement/MainController.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/main/java/com/example/quizmanagement/LoginController.java b/src/main/java/com/example/quizmanagement/LoginController.java index 2687724..9cbe49c 100644 --- a/src/main/java/com/example/quizmanagement/LoginController.java +++ b/src/main/java/com/example/quizmanagement/LoginController.java @@ -37,7 +37,6 @@ private void onLogin() throws Exception { while (hashedPass.length() < 32) { hashedPass = "0" + hashedPass; } - System.out.println(hashedPass); Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/quiz", "root", ""); Statement st = con.createStatement(); diff --git a/src/main/java/com/example/quizmanagement/MainController.java b/src/main/java/com/example/quizmanagement/MainController.java index 6749161..92fcf63 100644 --- a/src/main/java/com/example/quizmanagement/MainController.java +++ b/src/main/java/com/example/quizmanagement/MainController.java @@ -17,7 +17,6 @@ public class MainController { @FXML private void onClickAddButton() throws Exception { Stage primaryStage = (Stage) addButton.getScene().getWindow(); - System.out.println(Credentials.isLoggedIn()); if (Credentials.isLoggedIn()) { Parent root = FXMLLoader.load(getClass().getResource("add-view.fxml")); root.getStylesheets().add(getClass().getResource("/com/example/quizmanagement/styles.css").toExternalForm()); From c676aede5a50c78c0ecdb383fed38298d4e50462 Mon Sep 17 00:00:00 2001 From: RobinSrk Date: Thu, 22 Sep 2022 21:31:05 +0600 Subject: [PATCH 33/86] Added welcome message after Login --- .../quizmanagement/AddQuestionController.java | 12 ++++++++-- .../example/quizmanagement/Credentials.java | 9 ++++++++ .../quizmanagement/LoginController.java | 1 + .../quizmanagement/MainController.java | 14 +++++------- .../com/example/quizmanagement/add-view.fxml | 22 +++++++++---------- 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/example/quizmanagement/AddQuestionController.java b/src/main/java/com/example/quizmanagement/AddQuestionController.java index 144a273..b40565f 100644 --- a/src/main/java/com/example/quizmanagement/AddQuestionController.java +++ b/src/main/java/com/example/quizmanagement/AddQuestionController.java @@ -2,6 +2,7 @@ import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; +import javafx.fxml.Initializable; import javafx.geometry.Pos; import javafx.scene.Parent; import javafx.scene.Scene; @@ -12,15 +13,17 @@ import javafx.scene.layout.VBox; import javafx.stage.Stage; +import java.net.URL; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; +import java.util.ResourceBundle; -public class AddQuestionController { +public class AddQuestionController implements Initializable { @FXML private Button goBack; @FXML - private Label error; + private Label error, username; @FXML private TextArea question; @FXML @@ -58,4 +61,9 @@ private void onClickSubmit() throws Exception { } } + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + username.setText("Welcome, " + Credentials.getUsername()); + } } \ No newline at end of file diff --git a/src/main/java/com/example/quizmanagement/Credentials.java b/src/main/java/com/example/quizmanagement/Credentials.java index 3ed97ce..df58a5f 100644 --- a/src/main/java/com/example/quizmanagement/Credentials.java +++ b/src/main/java/com/example/quizmanagement/Credentials.java @@ -2,6 +2,7 @@ public class Credentials { private static boolean isLoggedIn = false; + private static String username; public static boolean isLoggedIn() { return isLoggedIn; @@ -10,4 +11,12 @@ public static boolean isLoggedIn() { public static void setLoggedIn(boolean data) { isLoggedIn = data; } + + public static String getUsername() { + return username; + } + + public static void setUsername(String name) { + username = name; + } } diff --git a/src/main/java/com/example/quizmanagement/LoginController.java b/src/main/java/com/example/quizmanagement/LoginController.java index 9cbe49c..2c37151 100644 --- a/src/main/java/com/example/quizmanagement/LoginController.java +++ b/src/main/java/com/example/quizmanagement/LoginController.java @@ -44,6 +44,7 @@ private void onLogin() throws Exception { "`password` = " + "'" + hashedPass + "'"); if (rs != null && rs.next()) { Credentials.setLoggedIn(true); + Credentials.setUsername(username.getText()); Stage primaryStage = (Stage) cancel.getScene().getWindow(); Parent root = FXMLLoader.load(getClass().getResource("add-view.fxml")); root.getStylesheets().add(getClass().getResource("/com/example/quizmanagement/styles.css").toExternalForm()); diff --git a/src/main/java/com/example/quizmanagement/MainController.java b/src/main/java/com/example/quizmanagement/MainController.java index 92fcf63..ebf97fe 100644 --- a/src/main/java/com/example/quizmanagement/MainController.java +++ b/src/main/java/com/example/quizmanagement/MainController.java @@ -17,19 +17,17 @@ public class MainController { @FXML private void onClickAddButton() throws Exception { Stage primaryStage = (Stage) addButton.getScene().getWindow(); + Parent root; if (Credentials.isLoggedIn()) { - Parent root = FXMLLoader.load(getClass().getResource("add-view.fxml")); - root.getStylesheets().add(getClass().getResource("/com/example/quizmanagement/styles.css").toExternalForm()); + root = FXMLLoader.load(getClass().getResource("add-view.fxml")); primaryStage.setTitle("Add question"); - primaryStage.setScene(new Scene(root, 400, 600)); - primaryStage.show(); } else { - Parent root = FXMLLoader.load(getClass().getResource("login-view.fxml")); - root.getStylesheets().add(getClass().getResource("/com/example/quizmanagement/styles.css").toExternalForm()); + root = FXMLLoader.load(getClass().getResource("login-view.fxml")); primaryStage.setTitle("Login"); - primaryStage.setScene(new Scene(root, 400, 600)); - primaryStage.show(); } + root.getStylesheets().add(getClass().getResource("/com/example/quizmanagement/styles.css").toExternalForm()); + primaryStage.setScene(new Scene(root, 400, 600)); + primaryStage.show(); } @FXML diff --git a/src/main/resources/com/example/quizmanagement/add-view.fxml b/src/main/resources/com/example/quizmanagement/add-view.fxml index b6f858a..f4ec361 100644 --- a/src/main/resources/com/example/quizmanagement/add-view.fxml +++ b/src/main/resources/com/example/quizmanagement/add-view.fxml @@ -2,19 +2,19 @@ - - - - - - - + From 827c13b66d210c31254514380f57d58ef3ca431f Mon Sep 17 00:00:00 2001 From: RobinSrk Date: Sun, 25 Sep 2022 22:23:57 +0600 Subject: [PATCH 39/86] updated readme file --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index e69de29..2748d28 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,3 @@ +# Java quiz application + +This is an quiz management application that provides quiz management functionality. \ No newline at end of file From c7ca91f0d81fd2891b16cd8ad0a36ad4b52b8ef6 Mon Sep 17 00:00:00 2001 From: RobinSrk Date: Sun, 25 Sep 2022 22:24:31 +0600 Subject: [PATCH 40/86] added functionality to login by pressing enter --- .../java/com/example/quizmanagement/LoginController.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/example/quizmanagement/LoginController.java b/src/main/java/com/example/quizmanagement/LoginController.java index 2c37151..3064a5b 100644 --- a/src/main/java/com/example/quizmanagement/LoginController.java +++ b/src/main/java/com/example/quizmanagement/LoginController.java @@ -7,6 +7,8 @@ import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyEvent; import javafx.stage.Stage; import java.math.BigInteger; @@ -66,4 +68,11 @@ private void onCancel() throws Exception { primaryStage.setScene(new Scene(root, 400, 600)); primaryStage.show(); } + + @FXML + private void setOnKeyPressed(KeyEvent k) throws Exception { + if (k.getCode().equals(KeyCode.ENTER)) { + onLogin(); + } + } } From e6b993e580eac4e45a84899ba4eefc304f612d41 Mon Sep 17 00:00:00 2001 From: RobinSrk Date: Sun, 25 Sep 2022 22:24:56 +0600 Subject: [PATCH 41/86] added database error message while loggin in --- .../quizmanagement/LoginController.java | 57 ++++++++++--------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/example/quizmanagement/LoginController.java b/src/main/java/com/example/quizmanagement/LoginController.java index 3064a5b..38a3c01 100644 --- a/src/main/java/com/example/quizmanagement/LoginController.java +++ b/src/main/java/com/example/quizmanagement/LoginController.java @@ -28,34 +28,39 @@ public class LoginController { private Button cancel, login; @FXML - private void onLogin() throws Exception { - if (username.getText().equals("") || pass.getText().equals("")) { - error.setText("Please fill all fields"); - } else { - MessageDigest md = MessageDigest.getInstance("MD5"); - byte[] bytes = md.digest(pass.getText().getBytes()); - BigInteger no = new BigInteger(1, bytes); - String hashedPass = no.toString(16); - while (hashedPass.length() < 32) { - hashedPass = "0" + hashedPass; - } - Class.forName("com.mysql.jdbc.Driver"); - Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/quiz", "root", ""); - Statement st = con.createStatement(); - ResultSet rs = st.executeQuery("select * from `users` where `username` = '" + username.getText() + "' and " + - "`password` = " + "'" + hashedPass + "'"); - if (rs != null && rs.next()) { - Credentials.setLoggedIn(true); - Credentials.setUsername(username.getText()); - Stage primaryStage = (Stage) cancel.getScene().getWindow(); - Parent root = FXMLLoader.load(getClass().getResource("add-view.fxml")); - root.getStylesheets().add(getClass().getResource("/com/example/quizmanagement/styles.css").toExternalForm()); - primaryStage.setTitle("Online Java Quiz Management System"); - primaryStage.setScene(new Scene(root, 400, 600)); - primaryStage.show(); + private void onLogin() { + try { + if (username.getText().equals("") || pass.getText().equals("")) { + error.setText("Please fill all fields"); } else { - error.setText("Incorrect username or password"); + MessageDigest md = MessageDigest.getInstance("MD5"); + byte[] bytes = md.digest(pass.getText().getBytes()); + BigInteger no = new BigInteger(1, bytes); + String hashedPass = no.toString(16); + while (hashedPass.length() < 32) { + hashedPass = "0" + hashedPass; + } + Class.forName("com.mysql.jdbc.Driver"); + Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/quiz", "root", ""); + Statement st = con.createStatement(); + ResultSet rs = st.executeQuery("select * from `users` where `username` = '" + username.getText() + "' and " + + "`password` = " + "'" + hashedPass + "'"); + if (rs != null && rs.next()) { + Credentials.setLoggedIn(true); + Credentials.setUsername(username.getText()); + Stage primaryStage = (Stage) cancel.getScene().getWindow(); + Parent root = FXMLLoader.load(getClass().getResource("add-view.fxml")); + root.getStylesheets().add(getClass().getResource("/com/example/quizmanagement/styles.css").toExternalForm()); + primaryStage.setTitle("Online Java Quiz Management System"); + primaryStage.setScene(new Scene(root, 400, 600)); + primaryStage.show(); + } else { + error.setText("Incorrect username or password"); + } } + + } catch (Exception e) { + error.setText("Error connecting to database"); } } From 59831798f4405df3e736d9fef795d9ba30b4341a Mon Sep 17 00:00:00 2001 From: RobinSrk Date: Sun, 25 Sep 2022 22:25:59 +0600 Subject: [PATCH 42/86] fixed result value from float to int --- .../java/com/example/quizmanagement/QuizController.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/quizmanagement/QuizController.java b/src/main/java/com/example/quizmanagement/QuizController.java index dd5d864..17953c1 100644 --- a/src/main/java/com/example/quizmanagement/QuizController.java +++ b/src/main/java/com/example/quizmanagement/QuizController.java @@ -125,8 +125,10 @@ private void onClickStart() throws Exception { quizBox.getChildren().clear(); ObservableList pieChartData = FXCollections.observableArrayList( - new PieChart.Data(String.valueOf((((qsSize - result) / qsSize) * 100) + " %"), (((qsSize - result) / qsSize) * 100)), - new PieChart.Data(String.valueOf(((result / qsSize) * 100) + " %"), ((result / qsSize) * 100))); + new PieChart.Data(String.valueOf(Math.round(((qsSize - result) / qsSize) * 100) + " %"), + (((qsSize - result) / qsSize) * 100)), + new PieChart.Data(String.valueOf(Math.round((result / qsSize) * 100) + " %"), + ((result / qsSize) * 100))); final PieChart chart = new PieChart(pieChartData); chart.setAnimated(true); chart.setLegendVisible(false); From 3fcf27ec3742a40fa661280b9bfa90fb8c2ab4ba Mon Sep 17 00:00:00 2001 From: RobinSrk Date: Sun, 25 Sep 2022 22:26:19 +0600 Subject: [PATCH 43/86] added result button at the end of quiz --- src/main/java/com/example/quizmanagement/QuizController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/quizmanagement/QuizController.java b/src/main/java/com/example/quizmanagement/QuizController.java index 17953c1..76d8395 100644 --- a/src/main/java/com/example/quizmanagement/QuizController.java +++ b/src/main/java/com/example/quizmanagement/QuizController.java @@ -33,7 +33,7 @@ public class QuizController implements Initializable { @FXML private VBox quizBox; @FXML - private Button goBack; + private Button goBack, nextButton; @FXML private Label question, report; @FXML @@ -123,6 +123,7 @@ private void onClickStart() throws Exception { updateQuestion(); } else { quizBox.getChildren().clear(); + nextButton.setText("View result"); ObservableList pieChartData = FXCollections.observableArrayList( new PieChart.Data(String.valueOf(Math.round(((qsSize - result) / qsSize) * 100) + " %"), From 4adde6553ba891168273a4253c77e85236cfd7f6 Mon Sep 17 00:00:00 2001 From: RobinSrk Date: Sun, 25 Sep 2022 22:26:53 +0600 Subject: [PATCH 44/86] added login and result button function --- src/main/resources/com/example/quizmanagement/login-view.fxml | 2 +- src/main/resources/com/example/quizmanagement/quiz-view.fxml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/com/example/quizmanagement/login-view.fxml b/src/main/resources/com/example/quizmanagement/login-view.fxml index e968e28..c381088 100644 --- a/src/main/resources/com/example/quizmanagement/login-view.fxml +++ b/src/main/resources/com/example/quizmanagement/login-view.fxml @@ -27,7 +27,7 @@ - + diff --git a/src/main/resources/com/example/quizmanagement/quiz-view.fxml b/src/main/resources/com/example/quizmanagement/quiz-view.fxml index 99abe17..b8cdcb9 100644 --- a/src/main/resources/com/example/quizmanagement/quiz-view.fxml +++ b/src/main/resources/com/example/quizmanagement/quiz-view.fxml @@ -54,7 +54,7 @@ - + + + + From f4e1f5a46b4ab770f6a3221b199ca8bce3264c3b Mon Sep 17 00:00:00 2001 From: RobinSrk Date: Sat, 1 Oct 2022 00:11:12 +0600 Subject: [PATCH 51/86] added question table --- .../example/quizmanagement/QuestionTable.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/quizmanagement/QuestionTable.java b/src/main/java/com/example/quizmanagement/QuestionTable.java index 5ec8fd4..f54a8fd 100644 --- a/src/main/java/com/example/quizmanagement/QuestionTable.java +++ b/src/main/java/com/example/quizmanagement/QuestionTable.java @@ -1,2 +1,33 @@ -package com.example.quizmanagement;public class QuestionTable { +package com.example.quizmanagement; + +import javafx.scene.control.Button; + +public class QuestionTable { + private String question; + private Button delete; + + public QuestionTable() { + this.question = ""; + } + + public QuestionTable(String question, Button delete) { + this.question = question; + this.delete = delete; + } + + public String getQuestion() { + return question; + } + + public void setQuestion(String question) { + this.question = question; + } + + public Button getDelete() { + return delete; + } + + public void setDelete(Button delete) { + this.delete = delete; + } } From d209e00f1a2604093403207b73f53457c108f3b7 Mon Sep 17 00:00:00 2001 From: RobinSrk Date: Sat, 1 Oct 2022 00:12:01 +0600 Subject: [PATCH 52/86] added correct and wrong result in result page --- src/main/java/com/example/quizmanagement/QuizController.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/quizmanagement/QuizController.java b/src/main/java/com/example/quizmanagement/QuizController.java index 76d8395..fb02d9b 100644 --- a/src/main/java/com/example/quizmanagement/QuizController.java +++ b/src/main/java/com/example/quizmanagement/QuizController.java @@ -35,7 +35,7 @@ public class QuizController implements Initializable { @FXML private Button goBack, nextButton; @FXML - private Label question, report; + private Label question, report, corLab, wrnLab; @FXML private HBox opBox1, opBox2; @FXML @@ -135,6 +135,8 @@ private void onClickStart() throws Exception { chart.setLegendVisible(false); chart.setTitle("Quiz result"); quizBox.getChildren().add(chart); + corLab.setText("Correct: " + Math.round(result)); + wrnLab.setText("Wrong: " + Math.round(qsSize - result)); applyCustomColorSequence(pieChartData, "red", "green"); } ans = null; From 88fdd533e9e1e8f526d9cbacd49b9c65713691f6 Mon Sep 17 00:00:00 2001 From: RobinSrk Date: Sat, 1 Oct 2022 00:12:43 +0600 Subject: [PATCH 53/86] removed button at the end of result --- src/main/java/com/example/quizmanagement/QuizController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/quizmanagement/QuizController.java b/src/main/java/com/example/quizmanagement/QuizController.java index fb02d9b..4c5b65b 100644 --- a/src/main/java/com/example/quizmanagement/QuizController.java +++ b/src/main/java/com/example/quizmanagement/QuizController.java @@ -37,7 +37,7 @@ public class QuizController implements Initializable { @FXML private Label question, report, corLab, wrnLab; @FXML - private HBox opBox1, opBox2; + private HBox opBox1, opBox2, btnContainer; @FXML private ProgressBar pb; @@ -123,7 +123,7 @@ private void onClickStart() throws Exception { updateQuestion(); } else { quizBox.getChildren().clear(); - nextButton.setText("View result"); + btnContainer.getChildren().remove(nextButton); ObservableList pieChartData = FXCollections.observableArrayList( new PieChart.Data(String.valueOf(Math.round(((qsSize - result) / qsSize) * 100) + " %"), From 7cc56989ece3e2f3fec5fa8119ce178707e2b7ba Mon Sep 17 00:00:00 2001 From: RobinSrk Date: Sat, 1 Oct 2022 00:13:17 +0600 Subject: [PATCH 54/86] updated texts --- .../com/example/quizmanagement/main-view.fxml | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/resources/com/example/quizmanagement/main-view.fxml b/src/main/resources/com/example/quizmanagement/main-view.fxml index ba9322e..161c264 100644 --- a/src/main/resources/com/example/quizmanagement/main-view.fxml +++ b/src/main/resources/com/example/quizmanagement/main-view.fxml @@ -1,20 +1,23 @@ - - - - - - + + + + + + - + - + - + + + + + diff --git a/src/main/resources/com/example/quizmanagement/teacher-report-view.fxml b/src/main/resources/com/example/quizmanagement/teacher-report-view.fxml new file mode 100644 index 0000000..9bebd8c --- /dev/null +++ b/src/main/resources/com/example/quizmanagement/teacher-report-view.fxml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + From 8001b74262714c4ea400ec7f40a0325c0fc6da82 Mon Sep 17 00:00:00 2001 From: RobinSrk Date: Mon, 3 Oct 2022 07:00:57 +0600 Subject: [PATCH 68/86] added data to database after completing quiz --- .../quizmanagement/QuizController.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/quizmanagement/QuizController.java b/src/main/java/com/example/quizmanagement/QuizController.java index ccfc21b..c6c4551 100644 --- a/src/main/java/com/example/quizmanagement/QuizController.java +++ b/src/main/java/com/example/quizmanagement/QuizController.java @@ -24,11 +24,14 @@ import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.ResourceBundle; public class QuizController implements Initializable { ResultSet rs; + Statement st; float qsSize, progress = 0; String ans; float result = 0; @@ -48,7 +51,7 @@ public void initialize(URL url, ResourceBundle resourceBundle) { try { Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/quiz", "root", ""); - Statement st = con.createStatement(); + st = con.createStatement(); rs = st.executeQuery("Select * from quiz_list"); if (rs != null) { rs.last(); @@ -104,7 +107,7 @@ public void changed(ObservableValue observableValue, Toggle to @FXML private void onClickGoBack() throws Exception { Stage primaryStage = (Stage) goBack.getScene().getWindow(); - Parent root = FXMLLoader.load(getClass().getResource("main-view.fxml")); + Parent root = FXMLLoader.load(getClass().getResource("student-view.fxml")); root.getStylesheets().add(getClass().getResource("/com/example/quizmanagement/styles.css").toExternalForm()); primaryStage.setTitle("Online Java Quiz Management System"); primaryStage.setScene(new Scene(root, 400, 600)); @@ -124,6 +127,24 @@ private void onClickStart() throws Exception { } else { quizBox.getChildren().clear(); btnContainer.getChildren().remove(nextButton); + Button reportButton = new Button("Show report"); + reportButton.setId("purple-button"); + reportButton.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent actionEvent) { + try { + Stage primaryStage = (Stage) goBack.getScene().getWindow(); + Parent root = FXMLLoader.load(getClass().getResource("student-report-view.fxml")); + root.getStylesheets().add(getClass().getResource("/com/example/quizmanagement/styles.css").toExternalForm()); + primaryStage.setTitle("Online Java Quiz Management System"); + primaryStage.setScene(new Scene(root, 400, 600)); + primaryStage.show(); + } catch (Exception e) { + System.out.println(e); + } + } + }); + btnContainer.getChildren().add(reportButton); ObservableList pieChartData = FXCollections.observableArrayList( new PieChart.Data("Correct " + String.valueOf(Math.round((result / qsSize) * 100) + "% (" + Math.round(result) + @@ -133,6 +154,7 @@ private void onClickStart() throws Exception { "% (" + Math.round(qsSize - result) + ")"), (((qsSize - result) / qsSize) * 100))); final PieChart chart = new PieChart(pieChartData); + st.executeUpdate("INSERT INTO `result`(`name`, `date`, `mark`) VALUES ('" + Credentials.getUsername() + "','" + new SimpleDateFormat("dd-MMM hh:mm aa").format(new Date()) + "','" + Math.round(result) + "/" + Math.round(qsSize) + "')"); chart.setAnimated(true); chart.setLabelsVisible(false); chart.setTitle("Quiz result"); From 2a06eb19b0a7a7e53a493f974c6d427541f95e14 Mon Sep 17 00:00:00 2001 From: RobinSrk Date: Mon, 3 Oct 2022 08:04:00 +0600 Subject: [PATCH 69/86] added account adding feature --- .../quizmanagement/AccountController.java | 82 +++++++++++++++++++ .../example/quizmanagement/add-acc-view.fxml | 58 +++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 src/main/java/com/example/quizmanagement/AccountController.java create mode 100644 src/main/resources/com/example/quizmanagement/add-acc-view.fxml diff --git a/src/main/java/com/example/quizmanagement/AccountController.java b/src/main/java/com/example/quizmanagement/AccountController.java new file mode 100644 index 0000000..e1d687c --- /dev/null +++ b/src/main/java/com/example/quizmanagement/AccountController.java @@ -0,0 +1,82 @@ +package com.example.quizmanagement; + +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +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.PasswordField; +import javafx.scene.control.TextField; +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyEvent; +import javafx.scene.layout.VBox; +import javafx.stage.Stage; + +import java.math.BigInteger; +import java.security.MessageDigest; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.Statement; + +public class AccountController { + @FXML + private TextField username, email; + @FXML + private PasswordField pass; + @FXML + private Label error; + + @FXML + private VBox container; + @FXML + private Button back; + + @FXML + private void onCreate() { + try { + if (username.getText().equals("") || pass.getText().equals("") || email.getText().equals("")) { + error.setText("Please fill all fields"); + } else { + MessageDigest md = MessageDigest.getInstance("MD5"); + byte[] bytes = md.digest(pass.getText().getBytes()); + BigInteger no = new BigInteger(1, bytes); + String hashedPass = no.toString(16); + while (hashedPass.length() < 32) { + hashedPass = "0" + hashedPass; + } + Class.forName("com.mysql.jdbc.Driver"); + Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/quiz", "root", ""); + Statement st = con.createStatement(); + int rs = st.executeUpdate("INSERT INTO `users`(`username`, `email`, `password`, `admin`) VALUES ('" + username.getText() + "','" + email.getText() + "','" + hashedPass + "','0')"); + if (rs == 1) { + container.getChildren().clear(); + container.getChildren().add(new Label("Question added successfully")); + container.getChildren().add(back); + container.setAlignment(Pos.CENTER); + } + } + + } catch (Exception e) { + error.setText("Error connecting to database"); + } + } + + @FXML + private void onCancel() throws Exception { + Stage primaryStage = (Stage) back.getScene().getWindow(); + Parent root = FXMLLoader.load(getClass().getResource("teacher-view.fxml")); + root.getStylesheets().add(getClass().getResource("/com/example/quizmanagement/styles.css").toExternalForm()); + primaryStage.setTitle("Test"); + primaryStage.setScene(new Scene(root, 400, 600)); + primaryStage.show(); + } + + @FXML + private void setOnKeyPressed(KeyEvent k) throws Exception { + if (k.getCode().equals(KeyCode.ENTER)) { + onCreate(); + } + } +} diff --git a/src/main/resources/com/example/quizmanagement/add-acc-view.fxml b/src/main/resources/com/example/quizmanagement/add-acc-view.fxml new file mode 100644 index 0000000..2ae3263 --- /dev/null +++ b/src/main/resources/com/example/quizmanagement/add-acc-view.fxml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 4c814ed738dfc7140acca5b8b1ff227164f437a2 Mon Sep 17 00:00:00 2001 From: RobinSrk Date: Mon, 3 Oct 2022 08:04:14 +0600 Subject: [PATCH 70/86] added new account create button --- src/main/resources/com/example/quizmanagement/teacher-view.fxml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/com/example/quizmanagement/teacher-view.fxml b/src/main/resources/com/example/quizmanagement/teacher-view.fxml index 6d6a191..af9ef6a 100644 --- a/src/main/resources/com/example/quizmanagement/teacher-view.fxml +++ b/src/main/resources/com/example/quizmanagement/teacher-view.fxml @@ -19,5 +19,5 @@ - - + + + + + + + + + + + + + + +