-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataController.java
More file actions
86 lines (70 loc) · 2.29 KB
/
DataController.java
File metadata and controls
86 lines (70 loc) · 2.29 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
package controller;
import CBTdata.SQLEngine;
import Main.Signin;
import com.jfoenix.controls.JFXButton;
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.scene.image.ImageView;
import javafx.stage.Stage;
import model.StudentModel;
import java.net.URL;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;
public class DataController implements Initializable
{
@FXML
private TableView<StudentModel> table;
@FXML
private TableColumn<StudentModel, String> tblFirstname;
@FXML
private TableColumn<StudentModel, String> tblLastname;
@FXML
private TableColumn<StudentModel, String> tblScore;
@FXML
private JFXButton btnLoad;
@FXML
private ImageView arrow;
private ObservableList<StudentModel> data;
private SQLEngine sql;
Signin su;
Stage stage;
public void Main(Signin su, Stage stage)
{
this.stage = stage;
this.su = su;
}
@Override
public void initialize(URL location, ResourceBundle resources)
{
sql = new SQLEngine();
arrow.setOnMouseClicked(e->
{
su.introductionWindow();
su.settingWindowClose();
});
}
@FXML
void loadData(ActionEvent event) throws SQLException
{
Connection con = sql.createConnection();
data = FXCollections.observableArrayList();
ResultSet resultSet = con.createStatement().executeQuery("SELECT * FROM DETAIL");
while(resultSet.next())
{
data.add(new StudentModel(resultSet.getString(1),resultSet.getString(2),resultSet.getString(3)));
}
tblFirstname.setCellValueFactory(new PropertyValueFactory<>("firstname"));
tblLastname.setCellValueFactory(new PropertyValueFactory<>("lastname"));
tblScore.setCellValueFactory(new PropertyValueFactory<>("score"));
table.setItems(null);
table.setItems(data);
}
}