-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQuestionBankController.java
More file actions
97 lines (73 loc) · 2.79 KB
/
QuestionBankController.java
File metadata and controls
97 lines (73 loc) · 2.79 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
package jobinterviewpreparationsystem;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import jobinterviewpreparationsystem.DB.DatabaseHandler;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.ListView;
import javafx.scene.control.Button;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.ListView;
import javafx.concurrent.Task;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
public class QuestionBankController {
@FXML
private ListView<String> questionListView;
private DatabaseHandler databaseHandler;
public QuestionBankController() {
databaseHandler = new DatabaseHandler(); // Assuming DatabaseHandler is properly implemented
}
@FXML
private void initialize() {
loadQuestions();
}
private void loadQuestions() {
Task<ObservableList<String>> loadQuestionsTask = new Task<ObservableList<String>>() {
@Override
protected ObservableList<String> call() {
ObservableList<String> questions = FXCollections.observableArrayList();
try {
questions = databaseHandler.getAllQuestions(); // Assuming this returns an ObservableList<String>
} catch (Exception e) {
e.printStackTrace();
showError("Database Error", "Failed to load questions.");
}
return questions;
}
};
loadQuestionsTask.setOnSucceeded(event -> {
questionListView.setItems(loadQuestionsTask.getValue()); // Update the ListView with questions
});
loadQuestionsTask.setOnFailed(event -> {
showError("Error", "Failed to fetch questions from the database.");
});
new Thread(loadQuestionsTask).start();
}
@FXML
private void handleBackToMainMenuBtn(ActionEvent event) {
JobInterviewPreparationSystem.showJobSeekercreen();
}
private void showError(String title, String message) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle(title);
alert.setHeaderText(null);
alert.setContentText(message);
alert.showAndWait();
}
}