Student's Name: - Bogun Pathmaraj - ID: - 300829172
Student's Name: - Bogun Pathmaraj - ID: - 300829172
CENTENNIAL COLLEGE
COMP 228: JAVA PROGRAMMING
FINAL LAB TEST (Version 3)
Full Marks: 100
Maximum Allowable Time: 4 hours
1. MS Word document:
[IN THE BEGINNING OF THIS DOCUMENT, YOU MUST PROVIDE A SCREEN
SHOT OF THE TIME YOU START TO WRITE CODE AND AT THE END, YOU MUST
PROVIDE A SCREEN SHOT OF THE TIME YOU ENDED AND SUBMITTED THE
WORD DOCUMENT.]
Use this document to provide screen shots and code. DO NOT DELETE the Question.
You should take screen shots of the application followed by the complete code that you would
use to develop this application. The screen shots should represent the full functionality of
your application.
Exercise 1
Write a GUI application in Java that allows user to select students by their city.
The user should be able to enter the city. The application should retrieve the student information
from an Oracle table named Student. Here is the definition of the table:
CREATE TABLE Students (
studentID char(9) NOT NULL,
firstName varchar (20) NOT NULL,
lastName varchar (20) NOT NULL,
address varchar (30) NOT NULL,
city varchar(30) NOT NULL,
province char(2) NOT NULL,
postalCode char(6) NOT NULL,
PRIMARY KEY (studentID)
);
Populate the table with several rows as below:
insert into Students values('300111222','Sam', 'Malone', '10
Somewhere Road', 'Toronto','ON','M1Y2H2');
commit;
Use the most appropriate layout manager classes to implement the layout of this GUI.
import java.awt.BorderLayout;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
Final Lab Test Page 4 of 9
Java Programming COMP-228
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
@Override
public void start(Stage mainStage) throws Exception
{
//Create GridPane
GridPane pane = new GridPane();
pane.setPadding(new Insets(5,5,5,5));
pane.setAlignment(Pos.CENTER_LEFT);
pane.setHgap(20);
pane.setVgap(10);
pane.setPadding(new Insets(25,15,15,15));
//Create TextFields
//Button
Button update = new Button("Update");
//Create BorderPane
BorderPane border = new BorderPane();
//Create JTextArea
JTextArea ta = new JTextArea();
JFrame frame = new JFrame("JTextArea");
frame.getContentPane().setSize(800,400);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
update.setOnAction((e)->
{
//Retrieve Info
String sql = "SELECT studentID, firstName,
lastName,address,city,province,postalCode FROM Students ORDER BY studentId";
try
{
//create Statement
Statement sql_stmt =
conn.createStatement();
//Execute query
ResultSet result =
sql_stmt.executeQuery(sql);
while (result.next())
{
array[0]=result.getString(1);
ta.append(array[0] + "\t");
array[1]=result.getString(2);
ta.append(array[1] + "\t");
array[2]=result.getString(3);
ta.append(array[2] + "\t");
array[3]=result.getString(4);
ta.append(array[3] + "\t");
array[4]=result.getString(5);
ta.append(array[4] + "\t");
array[5]=result.getString(6);
ta.append(array[5] + "\t");
array[6]=result.getString(7);
ta.append(array[6] + "\n");
result.close();
//Close statements
sql_stmt.close();
System.out.print("Completed");
conn.close();
});
(100
marks)
Evaluation:
Functionality
Correct implementation of UI (using 35%
SWING or JavaFX components, event
handling)