Initial Commit
This commit is contained in:
8
Source Code/Lab9/.idea/.gitignore
generated
vendored
Normal file
8
Source Code/Lab9/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/../../../../../../../:\ProgrammingProjects\JavaProjects\JavaYear1\CS1103\Lab9\.idea/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
7
Source Code/Lab9/.idea/codeStyles/Project.xml
generated
Normal file
7
Source Code/Lab9/.idea/codeStyles/Project.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<ScalaCodeStyleSettings>
|
||||
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
|
||||
</ScalaCodeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
5
Source Code/Lab9/.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
Source Code/Lab9/.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
6
Source Code/Lab9/.idea/discord.xml
generated
Normal file
6
Source Code/Lab9/.idea/discord.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DiscordProjectSettings">
|
||||
<option name="show" value="PROJECT_FILES" />
|
||||
</component>
|
||||
</project>
|
10
Source Code/Lab9/.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
10
Source Code/Lab9/.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@ -0,0 +1,10 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||
<Languages>
|
||||
<language minSize="110" name="Java" />
|
||||
</Languages>
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
6
Source Code/Lab9/.idea/misc.xml
generated
Normal file
6
Source Code/Lab9/.idea/misc.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
Source Code/Lab9/.idea/modules.xml
generated
Normal file
8
Source Code/Lab9/.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Lab9.iml" filepath="$PROJECT_DIR$/Lab9.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
7
Source Code/Lab9/.idea/sqldialects.xml
generated
Normal file
7
Source Code/Lab9/.idea/sqldialects.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="SqlDialectMappings">
|
||||
<file url="file://$PROJECT_DIR$/src/AcceptStudentGUI.java" dialect="GenericSQL" />
|
||||
<file url="PROJECT" dialect="MariaDB" />
|
||||
</component>
|
||||
</project>
|
12
Source Code/Lab9/Lab9.iml
Normal file
12
Source Code/Lab9/Lab9.iml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="JDBC 8.0" level="application" />
|
||||
</component>
|
||||
</module>
|
BIN
Source Code/Lab9/out/production/Lab9/AcceptStudentGUI.class
Normal file
BIN
Source Code/Lab9/out/production/Lab9/AcceptStudentGUI.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
Source Code/Lab9/out/production/Lab9/StudentTranscriptGUI.class
Normal file
BIN
Source Code/Lab9/out/production/Lab9/StudentTranscriptGUI.class
Normal file
Binary file not shown.
139
Source Code/Lab9/src/AcceptStudentGUI.java
Normal file
139
Source Code/Lab9/src/AcceptStudentGUI.java
Normal file
@ -0,0 +1,139 @@
|
||||
import javafx.application.Application;
|
||||
import javafx.application.Platform;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.geometry.Insets;
|
||||
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.paint.Color;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class AcceptStudentGUI extends Application {
|
||||
|
||||
private static TextField nameField;
|
||||
private static TextField emailField;
|
||||
private static TextField averageField;
|
||||
private static Text response;
|
||||
|
||||
public void start(Stage primaryStage) {
|
||||
primaryStage.setTitle("Accept a Student");
|
||||
|
||||
Label nameLabel = new Label("Name:");
|
||||
Label emailLabel = new Label("Email:");
|
||||
Label averageLabel = new Label("Average:");
|
||||
|
||||
nameField = new TextField();
|
||||
nameField.setPrefWidth(150);
|
||||
nameField.setMaxWidth(300);
|
||||
|
||||
emailField = new TextField();
|
||||
emailField.setPrefWidth(150);
|
||||
emailField.setMaxWidth(300);
|
||||
|
||||
averageField = new TextField();
|
||||
averageField.setPrefWidth(60);
|
||||
averageField.setMaxWidth(60);
|
||||
|
||||
averageField.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (!newValue.matches("\\d{0,3}([.]\\d{0,2})?")) {
|
||||
averageField.setText(oldValue);
|
||||
}
|
||||
});
|
||||
|
||||
Button accept = new Button("Accept");
|
||||
accept.setOnAction(this::processAcceptStudent);
|
||||
Button quit = new Button("Quit");
|
||||
quit.setOnAction(this::quitApp);
|
||||
|
||||
response = new Text("");
|
||||
|
||||
GridPane grid = new GridPane();
|
||||
grid.setHgap(10);
|
||||
grid.setVgap(10);
|
||||
grid.setPadding(new Insets(0, 10, 0, 10));
|
||||
|
||||
// Row 1: Buttons
|
||||
grid.add(accept, 0, 0);
|
||||
grid.add(quit, 2, 0);
|
||||
//Row 2: name
|
||||
grid.add(nameLabel, 0, 1);
|
||||
grid.add(nameField, 1, 1);
|
||||
//Row 3: email
|
||||
grid.add(emailLabel, 0, 2);
|
||||
grid.add(emailField, 1, 2);
|
||||
//Row 4: HS average
|
||||
grid.add(averageLabel, 0, 3);
|
||||
grid.add(averageField, 1, 3);
|
||||
//Row 5: response
|
||||
grid.add(response, 0, 4, 2, 4);
|
||||
|
||||
|
||||
Scene scene = new Scene(grid, 300, 200);
|
||||
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
}
|
||||
|
||||
|
||||
public void processAcceptStudent(ActionEvent event) {
|
||||
|
||||
Connection connection = openConnection();
|
||||
String studentName = nameField.getText();
|
||||
String emailAddress = emailField.getText();
|
||||
String highSchoolAverage = averageField.getText();
|
||||
try {
|
||||
String query = "{CALL AcceptStudent(?, ?, ?)}";
|
||||
CallableStatement statement = connection.prepareCall(query);
|
||||
statement.setString(1, studentName);
|
||||
statement.setString(2, emailAddress);
|
||||
statement.setString(3, highSchoolAverage);
|
||||
statement.executeQuery();
|
||||
response.setText("Student accepted.");
|
||||
response.setFill(Color.GREEN);
|
||||
} catch (SQLException sqlException) {
|
||||
response.setFill(Color.RED);
|
||||
response.setText(sqlException.getMessage());
|
||||
}
|
||||
closeConnection(connection);
|
||||
}
|
||||
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
private static Connection openConnection() {
|
||||
final String url = "jdbc:mysql://cs1103.cs.unb.ca:3306/ishoebot";
|
||||
final String user = "ishoebot";
|
||||
final String password = "k7FOLH5B";
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = DriverManager.getConnection(url, user, password);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
response.setFill(Color.RED);
|
||||
response.setText("Couldn't open a connection: " + exception.getMessage());
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
private static void closeConnection(Connection conn) {
|
||||
try {
|
||||
conn.close();
|
||||
}
|
||||
catch (Exception exception) {
|
||||
response.setFill(Color.RED);
|
||||
response.setText("Couldn't close a connection: " + exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void quitApp(ActionEvent event) {
|
||||
Platform.exit();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
159
Source Code/Lab9/src/StudentTranscriptGUI.java
Normal file
159
Source Code/Lab9/src/StudentTranscriptGUI.java
Normal file
@ -0,0 +1,159 @@
|
||||
import javafx.application.Application;
|
||||
import javafx.application.Platform;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.geometry.HPos;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
public class StudentTranscriptGUI extends Application {
|
||||
|
||||
private static TextField studentIDField;
|
||||
private static TableView<CourseGrade> tableView;
|
||||
|
||||
private static Text response;
|
||||
|
||||
public void start(Stage primaryStage) {
|
||||
primaryStage.setTitle("Get a Transcript");
|
||||
|
||||
Label studentIDLabel = new Label("Student ID:");
|
||||
|
||||
tableView = new TableView<>();
|
||||
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
|
||||
|
||||
TableColumn<CourseGrade, String> course = new TableColumn<>("Course");
|
||||
TableColumn<CourseGrade, String> grade = new TableColumn<>("Grade");
|
||||
|
||||
tableView.getColumns().add(course);
|
||||
tableView.getColumns().add(grade);
|
||||
tableView.setPrefWidth(300);
|
||||
|
||||
//depreciated
|
||||
course.impl_setReorderable(false);
|
||||
grade.impl_setReorderable(false);
|
||||
|
||||
course.setCellValueFactory(new PropertyValueFactory<>("course"));
|
||||
grade.setCellValueFactory(new PropertyValueFactory<>("grade"));
|
||||
|
||||
studentIDField = new TextField();
|
||||
studentIDField.setPrefWidth(150);
|
||||
studentIDField.setMaxWidth(300);
|
||||
|
||||
|
||||
|
||||
Button accept = new Button("Get Transcript");
|
||||
accept.setOnAction(this::processAcceptStudent);
|
||||
Button quit = new Button("Quit");
|
||||
quit.setOnAction(this::quitApp);
|
||||
|
||||
response = new Text("");
|
||||
|
||||
GridPane grid = new GridPane();
|
||||
grid.setHgap(10);
|
||||
grid.setVgap(10);
|
||||
grid.setPadding(new Insets(0, 10, 0, 10));
|
||||
GridPane.setHalignment(quit, HPos.RIGHT);
|
||||
|
||||
// Row 1: Buttons
|
||||
grid.add(accept, 0, 0);
|
||||
grid.add(quit, 2, 0);
|
||||
//Row 2: name
|
||||
grid.add(studentIDLabel, 0, 1);
|
||||
grid.add(studentIDField, 2, 1);
|
||||
//Row 3: tableView
|
||||
grid.add(tableView, 0, 2, 3, 1);
|
||||
//Row 4: response
|
||||
grid.add(response, 0, 3, 3, 4);
|
||||
|
||||
|
||||
Scene scene = new Scene(grid, 300, 300);
|
||||
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
}
|
||||
|
||||
|
||||
public void processAcceptStudent(ActionEvent event) {
|
||||
|
||||
Connection connection = openConnection();
|
||||
String studentID = studentIDField.getText();
|
||||
tableView.getItems().clear();
|
||||
try {
|
||||
String query = "{CALL studentTranscript(?)}";
|
||||
CallableStatement statement = connection.prepareCall(query);
|
||||
statement.setString(1, studentID);
|
||||
ResultSet rs = statement.executeQuery();
|
||||
while(rs.next()) {
|
||||
tableView.getItems().add(new CourseGrade(rs.getString(1), rs.getString(2)));
|
||||
}
|
||||
response.setText("Student transcript request completed.");
|
||||
response.setFill(Color.GREEN);
|
||||
} catch (SQLException sqlException) {
|
||||
response.setFill(Color.RED);
|
||||
response.setText(sqlException.getMessage());
|
||||
}
|
||||
closeConnection(connection);
|
||||
}
|
||||
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
private static Connection openConnection() {
|
||||
final String url = "jdbc:mysql://cs1103.cs.unb.ca:3306/ishoebot";
|
||||
final String user = "ishoebot";
|
||||
final String password = "k7FOLH5B";
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = DriverManager.getConnection(url, user, password);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
response.setFill(Color.RED);
|
||||
response.setText("Couldn't open a connection: " + exception.getMessage());
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
private static void closeConnection(Connection conn) {
|
||||
try {
|
||||
conn.close();
|
||||
}
|
||||
catch (Exception exception) {
|
||||
response.setFill(Color.RED);
|
||||
response.setText("Couldn't close a connection: " + exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void quitApp(ActionEvent event) {
|
||||
Platform.exit();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static class CourseGrade {
|
||||
private String course;
|
||||
private String grade;
|
||||
|
||||
public CourseGrade(String course, String grade) {
|
||||
this.course = course;
|
||||
this.grade = grade;
|
||||
}
|
||||
public void setCourse(String course) {
|
||||
this.course = course;
|
||||
}
|
||||
public String getCourse() {
|
||||
return course;
|
||||
}
|
||||
public String getGrade() {
|
||||
return grade;
|
||||
}
|
||||
public void setGrade(String grade) {
|
||||
this.grade = grade;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user