Question: Question 67 pts When creating an application using JavaFX, what class does the main class need to extend? a. JFrame b. JPanel c. Application d.

Question 67 pts

When creating an application using JavaFX, what class does the main class need to extend?

a. JFrame
b. JPanel
c. Application
d. Stage
e. Scene

Question 68 pts

What is happening at lines 70, 75, 80, and 85 in class DatabaseJavaFx?

a. The title of the TableColumn is being set
b. The title of the TableView is being set
c. The data from the database is being bound to the UI
d. The data from class FilmDAO is being bound to the UI
e. None of the above

Question 69 pts

What is happening at line 95 in class DatabaseJavaFx?

a. An event handler is being declared to establish what happens when the user clicks the associated button
b. An event handler is being declared to establish what happens when the user starts the application
c. An event handler is being declared to establish what happens when the user selects the associated menu item
d. An event handler is being declared to establish what happens when the user closes the application

Question 70 pts

What is happening at line 133 in class DatabaseJavaFx?

a. The application is trying to make a connection to the database by calling method fetchFilms()
b. The application is trying to make a connection to the database by calling method getConnection()
c. The application is trying to query data from the database by calling method getConnection()
d. The application is trying to query data from the database by calling method fetchFilms()
e. None of the above

Question 71 pts

What is happening at line 176 - 178 in class DatabaseJavaFx?

a. Establishing a connection to the database
b. Querying data from the database
c. Storing data in the database
d. The SQL query statement is being created
e. None of the above

Question 72 pts

What object stores the results of a database query DatabaseJavaFx?

a. Statement
b. st
c. ResultSet
d. rs
e. con

Question 73 pts

What is purpose of class XmlParser?

a. To store data retrieved from the database
b. To make a connection to the database
c. To create the JavaFX UI to display the data from the database
d. To parse the properties.xml file
e. To store the database connection properties

Question 74 pts

What is purpose of class ConnectionData?

a. To store data retrieved from the database
b. To make a connection to the database
c. To create the JavaFX UI to display the data from the database
d. To parse the properties.xml file
e. To store the database connection properties

Question 75 pts

What is purpose of class FilmDAO?

a. To store data retrieved from the database
b. To make a connection to the database
c. To create the JavaFX UI to display the data from the database
d. To parse the properties.xml file
e. To store the database connection properties

Question 76 pts

What is purpose of class PostgreSQLConnect?

a. To store data retrieved from the database
b. To make a connection to the database
c. To create the JavaFX UI to display the data from the database
d. To parse the properties.xml file
e. To store the database connection properties

Question 77 pts

What is purpose of file properties.xml?

a. To store data retrieved from the database
b. To make a connection to the database
c. To create the JavaFX UI to display the data from the database
d. To store the properties to connect to the database
e. To parse the properties.xml file

Question 78 pts

What is method toString() in class ConnectionData doing?

a. Concatenates the database connection data into the expected format to successfully connect to the database
b. To store data retrieved from the database
c. To make a connection to the database
d. To parse the properties.xml file
e. None of the above

Question 79 pts

What is Javadoc?

a. a tool that generates HTML documentation from comments in the code
b. a tool that generates HTML documentation from Javadoc comments in the code
c. a tree structure that contains all of the elements of the document
d. code comments
e. project documentation

Question 80 pts

What is the correct format of Javadoc comments?

a. @comment
b. // comment
c. /* comment */
d. /** comment */
e. /* comment **/

C:/Users/kwhiting/Documents/NetBeansProjects/DatabaseJavaFx/src/databasejavafx/DatabaseJavaFx.java

 1 /* 2 * Karin Whiting 3 * COP 3330 Object Oriented Programming 4 * University of Central Florida 5 */ 6 package databasejavafx; 7 8 import inputOutput.PostgreSQLConnect; 9 import dataModel.FilmDAO; 
10 import inputOutput.ConnectionData; 11 import inputOutput.XmlParser; 12 import java.sql.Connection; 13 import java.sql.ResultSet; 
14 import java.sql.SQLException; 15 import java.sql.Statement; 16 import java.util.logging.Level; 17 import java.util.logging.Logger; 18 import javafx.application.Application; 19 import javafx.collections.FXCollections; 20 import javafx.collections.ObservableList; 21 import javafx.event.ActionEvent; 
22 import javafx.event.EventHandler; 23 import javafx.scene.Group; 24 import javafx.scene.Scene; 25 import javafx.scene.control.Button; 26 import javafx.scene.control.Label; 27 import javafx.scene.control.TableColumn; 28 import javafx.scene.control.TableView; 29 import javafx.scene.layout.VBox; 
30 import javafx.scene.text.Font; 31 import javafx.stage.Stage; 32 import javafx.scene.control.cell.PropertyValueFactory; 33 import static javafx.application.Application.launch; 34 35 /** 36 * 37 * @author kwhiting 38 */ 39 public class DatabaseJavaFx extends Application 40 { 
41 private static final Logger logger = Logger.getLogger(DatabaseJavaFx.class.getName()); 
42 private ObservableList data = FXCollections.observableArrayList(); 

43 44 /** 45 *

* @param args

46 47 48 49 {

 */ public static void main(String[] args) 

50 lh()

1.1 of 5 2016.11.30 14:25:23

C:/Users/kwhiting/Documents/NetBeansProjects/DatabaseJavaFx/src/databasejavafx/DatabaseJavaFx.java

50 launch(args); 51 } 52 53 @Override 
54 public void start(Stage stage) 55 { 

56 /**

57 * set up the tableView

58 * make sure the tableView data cannot be modified 

59 */

60

61 TableView tableView = new TableView(); 
62 tableView.setEditable(true); 
63 final Label label = new Label("Films"); 
64 label.setFont(new Font("Arial", 20)); 

65

66 // bind the UI columns to display data from the DAO 
67 TableColumn title = new TableColumn("Title"); 
68 title.setMinWidth(200); 
69 // binding the data from the FilmDAO to the UI TableView column 
70 title.setCellValueFactory( 
71 new PropertyValueFactory("filmName")); 

72

73 TableColumn description = new TableColumn("Description"); 
74 description.setMinWidth(700); 
75 description.setCellValueFactory( 
76 new PropertyValueFactory("filmDescription")); 

77

78 TableColumn rate = new TableColumn("Rental Rate"); 
79 rate.setMinWidth(100); 
80 rate.setCellValueFactory( 
81 new PropertyValueFactory("filmPrice")); 

82

83 TableColumn rating = new TableColumn("Rating"); 
84 rating.setMinWidth(100); 
85 rating.setCellValueFactory( 
86 new PropertyValueFactory("filmRating")); 

87

88 // add the columns to the tableView 
89 tableView.getColumns().addAll(title, description, rate, rating); 

90

91 // same as a JButton in swing

92 final Button fetchData = new Button("Fetch films from database"); 

93

94 // this is the same as JButton.addActionListener() in swing 
95 fetchData.setOnAction(new EventHandler() 

96 {

97 // same as ActionListener's actionPerformed() 
98 @Override public void handle(ActionEvent event) 

99 {

2.1 of 5 2016.11.30 14:25:23

C:/Users/kwhiting/Documents/NetBeansProjects/DatabaseJavaFx/src/databasejavafx/DatabaseJavaFx.java

99 {

100 // call method and pass UI control ListView 
101 fetchData(tableView); 

102 }

103 });

104

105 // create a Scene 
106 Scene scene = new Scene(new Group()); 

107 // create a JPanel type of class like in swing

108 final VBox vbox = new VBox(); 
109 // setting the dimensions like in swing 
110 vbox.setPrefHeight(500); 

111

112 // set the style, similar to CSS 
113 vbox.setStyle("-fx-background-color: cornsilk; -fx-padding: 50;"); 
114 // everything part of the UI control VBox are the children 
115 vbox.getChildren().addAll(label, tableView); 
116 ((Group) scene.getRoot()).getChildren().addAll(vbox, fetchData); 

117

118 // set up the UI

119 stage.setTitle("Films for Rent"); 

120 // create the Scene using the layout manager

121 stage.setScene(scene); 
122 // show the UI 
123 stage.show(); 

124 } 125 /**

126 127 128 129 130 131 { 132 
133 134 135 136 137 138 139 140 141 142 143 } 144 
 * fetchData() ~ it is responsible for interacting with * the database to retrieve the data * @param tableView */ 
private void fetchData(TableView tableView) 
// call method getConnection in the class to connect to the database try (Connection con = getConnection()) { 
 // populate the UI control ListView with the data from the database // by calling method fetchNames() tableView.setItems(fetchFilms(con)); 
} catch (SQLException | ClassNotFoundException ex) { 
 logger.log(Level.SEVERE, null, ex); } 

145 /**

146 * getConnection() ~ creates a connection to the PostgreSQL 
147 * database using properties from the properties.xml file 
148 * parsed using an XML parser 

3.1 of 5 2016.11.30 14:25:23

C:/Users/kwhiting/Documents/NetBeansProjects/DatabaseJavaFx/src/databasejavafx/DatabaseJavaFx.java

149 *

150 * @return Connection 
151 * @throws ClassNotFoundException 
152 * @throws SQLException 

153 */

154 private Connection getConnection() throws ClassNotFoundException, SQLException 

155 {

156 // using the logger to track application progress for the user 
157 logger.info("Getting a database connection"); 

158

159 // read in the database properties from XML 
160 // pass the location of the XML file as an argument 
161 XmlParser xml = new XmlParser("inputOutput/properties.xml"); 
162 ConnectionData data = xml.getConnectionData(); 

163

164 // create the connection using the data from the XML file 
165 PostgreSQLConnect connect = new PostgreSQLConnect(data); 
166 Connection dbConnect = connect.getConnection(); 
167 168 return dbConnect; 
169 } 170 171 private ObservableList fetchFilms(Connection con) throws SQLException 172 { 
173 logger.info("Fetching films from database"); 
174 ObservableList films = FXCollections.observableArrayList(); 

175

176 String select = "SELECT title, rental_rate, rating, description " +

177 "FROM film " + 
178 "ORDER BY title;"; 
179 180 logger.info("Select statement " + select); 181 
182 Statement st = con.createStatement(); 
183 ResultSet rs = st.executeQuery(select); 

184

185 while (rs.next()) 

186 {

187 // create the DAO 
188 FilmDAO film = new FilmDAO(); 
189 film.setFilmName(rs.getString("title")); 
190 film.setFilmRating(rs.getString("rating")); 
191 film.setFilmDescription(rs.getString("description")); 
192 film.setFilmPrice(rs.getDouble("rental_rate")); 

193

194 films.add(film); 

195 }

196 197 logger.info("Found " + films.size() + " films"); 

98

4.1 of 5 2016.11.30 14:25:23

C:/Users/kwhiting/Documents/NetBeansProjects/DatabaseJavaFx/src/databasejavafx/DatabaseJavaFx.java

198 199 return films; 200 } 201 } 

5.1 of 5 2016.11.30 14:25:23

C:/Users/kwhiting/Documents/NetBeansProjects/DatabaseJavaFx/src/inputOutput/XmlParser.java

 1 /* 2 * Karin Whiting 3 * COP 3330 Object Oriented Programming 4 * University of Central Florida 5 */ 6 package inputOutput; 7 8 import java.io.IOException; 9 import java.util.logging.Logger; 

10 import javax.xml.parsers.DocumentBuilder; 11 import javax.xml.parsers.DocumentBuilderFactory; 12 import javax.xml.parsers.ParserConfigurationException; 13 import org.w3c.dom.Document; 14 import org.w3c.dom.Element; 15 import org.w3c.dom.Node; 16 import org.w3c.dom.NodeList; 17 import org.xml.sax.SAXException; 18 19 /** 20 * 21 * @author kwhiting 22 */ 23 public class XmlParser 24 {

25 private ConnectionData connectionData; 
26 private Document document; 

27 private static final Logger logger = Logger.getLogger(XmlParser.class.getName());

28 29 /** 30 *

31 32 33 34 { 35 parseXmlFile(file); 36 } 
37 38 private void parseXmlFile(String fileName) 39 { 
40 //Get the DOM Builder Factory 

41 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

42 43 try 44 {

45 //Using factory get an instance of document builder 
46 DocumentBuilder db = dbf.newDocumentBuilder(); 

47

48 //Load and Parse the XML document 
49 //document contains the complete XML as a Tree. 

50 document = db.parse(ClassLoader.getSystemResourceAsStream(fileName));

* @param file

 */ public XmlParser(String file) 

1.1 of 3 2016.11.21 23:02:58

C:/Users/kwhiting/Documents/NetBeansProjects/DatabaseJavaFx/src/inputOutput/XmlParser.java

51

52 //Iterating through the nodes and extracting the data. 

53 NodeList nodeList = document.getDocumentElement().getChildNodes();

54 55 for(int i = 0; i < nodeList.getLength(); i++) 56 { 
57 /** get the  element */ 
58 Node node = nodeList.item(i); 
59 60 if(node instanceof Element) 61 { 

62 //for each element get text or int values of

63 //name ,id, age and name 

64 String type = node.getAttributes().getNamedItem("type").getNodeValue();

65 //Create a new ConnectionData 
66 connectionData = new ConnectionData(); 
67 connectionData.setType(type); 
68 69 NodeList childNodes = node.getChildNodes(); 70 71 for (int j = 0; j < childNodes.getLength(); j++) 72 { 73 Node cNode = childNodes.item(j); 74 
75 //Identifying the child tag of employee encountered. 
76 if (cNode instanceof Element) 

77 {

78 String content = cNode.getLastChild().getTextContent().trim();

79 switch (cNode.getNodeName()) 

80 { 81 82

 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 } 

100 }

case "url": connectionData.setUrl(content); 
 break; case "ipaddress": 
 connectionData.setIpaddress(content); 
 break; case "port": 
 connectionData.setPort(content); 
 break; case "database": 
 connectionData.setDatabase(content); 
 break; case "login": 
 connectionData.setLogin(content); 
 break; case "password": 
 connectionData.setPassword(content); break; 

2.1 of 3 2016.11.21 23:02:58

C:/Users/kwhiting/Documents/NetBeansProjects/DatabaseJavaFx/src/inputOutput/XmlParser.java

100 }

101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 
124 125 126 127 } 

} }

} }

 catch(ParserConfigurationException pce) { 
 pce.printStackTrace(); } 
 catch(SAXException se) { 
 se.printStackTrace(); } 
 catch(IOException ioe) { 
 ioe.printStackTrace(); } 

}

/** *

* @return

 */ public ConnectionData getConnectionData() 
{ return connectionData; 

}

3.1 of 3 2016.11.21 23:02:58

C:/Users/kwhiting/Documents/NetBeansProjects/DatabaseJavaFx/src/inputOutput/ConnectionData.java

 1 /* 2 * Karin Whiting 3 * COP 3330 Object Oriented Programming 4 * University of Central Florida 5 */ 6 package inputOutput; 7 8 import java.util.logging.Logger; 9 
10 /** 11 * 12 * @author kwhiting 13 */ 14 public class ConnectionData 15 { 
16 private String type; 
17 private String url; 
18 private String ipaddress; 
19 private String port; 
20 private String database; 
21 private String login; 
22 private String password; 

23 24 /**

25 26 27 28 29 } 30 

31 /**

32 33 34 35 36 } 37 

38 /**

* @return the type 
 */ public String getType() { 

return type;

 * @param type the type to set 
 this.type = type; 

39 * @return the url 1.1 of 4

 */ public void setType(String type) { 

2016.11.21 23:03:34

C:/Users/kwhiting/Documents/NetBeansProjects/DatabaseJavaFx/src/inputOutput/ConnectionData.java

39 @return the url 

40 41

 */ public String getUrl() { 
42 43 } 44 45 /** 

return url;

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

 * @param port the port to set 
 */ public void setPort(String port) { 
 this.port = port; 
* @param url the url to set 
 */ public void setUrl(String url) { 
this.url = url; 
* @return the ipaddress 
 */ public String getIpaddress() { 
return ipaddress; 
* @param ipaddress the ipaddress to set 
 */ public void setIpaddress(String ipaddress) { 
this.ipaddress = ipaddress; 
* @return the port 
 */ public String getPort() { 

return port;

2.1 of 4 2016.11.21 23:03:34

C:/Users/kwhiting/Documents/NetBeansProjects/DatabaseJavaFx/src/inputOutput/ConnectionData.java

pp;

78 } 79 80 /**

81 82

* @return the database */ 
83 84 85 } 86 87 /** 
88 89 90 91 92 } 93 

94 /**

95 96 97 98 99 }

100 101 /**

102 103 104 105 106 } 107 

108 /**

109 110 111 112 113 } 114 

115 /**

public String getDatabase() { return database; 
* @param database the database to set 
 */ public void setDatabase(String database) { 
this.database = database; 
* @return the login 
 */ public String getLogin() { 
return login; 
* @param login the login to set 
 */ public void setLogin(String login) { 
this.login = login; 
* @return the password 
 */ public String getPassword() { 
return password; 

3.1 of 4 2016.11.21 23:03:34

C:/Users/kwhiting/Documents/NetBeansProjects/DatabaseJavaFx/src/inputOutput/ConnectionData.java

116 117 118 119 120 } 121 

122 /**

* @param password the password to set 
 */ public void setPassword(String password) { 
 this.password = password; 
124 125 126 127 { 
128 // format should be 
129 // "jdbc:postgresql://localhost:5432/dvdrental" 

130

131 return url + "://" + ipaddress + ":" + port + "/" + database; 132 133 } 134 } 

123

*

* @return

 */ public String toString() 

4.1 of 4 2016.11.21 23:03:34

C:/Users/kwhiting/Documents/NetBeansProjects/DatabaseJavaFx/src/inputOutput/PostgreSQLConnect.java

 1 /* 2 * Karin Whiting 3 * COP 3330 Object Oriented Programming 4 * University of Central Florida 5 */ 6 package inputOutput; 7 8 import inputOutput.ConnectionData; 9 import java.sql.Connection; 
10 import java.sql.DriverManager; 11 12 /** 13 * 
14 * @author kwhiting 15 */ 16 public class PostgreSQLConnect 17 { 18 Connection connect = null; 19 // ConnectionData data = null; 20 21 /** 22 * 
23 24 25 26 { 27 try 28 { 29 System.out.println("data is " + data.toString()); 
30 Class.forName(data.getType()); 
31 connect = DriverManager.getConnection(data.toString(), data.getLogin(), data.getPassword()); 
32 } 33 catch(Exception ex) 34 { 
35 ex.printStackTrace(); 36 } 37 38 System.out.println("Opened database successfully"); 39 

40 } 41

42 /** 43 *

* @param data

 */ public PostgreSQLConnect(ConnectionData data) 
44 45 46 47 { 48 return connect; 49 } 

50 }

* @return Connection to database 
 */ public Connection getConnection() 

1.1 of 1 2016.11.22 00:59:07

C:/Users/kwhiting/Documents/NetBeansProjects/DatabaseJavaFx/src/dataModel/FilmDAO.java

 1 /* 2 * Karin Whiting 3 * COP 3330 Object Oriented Programming 4 * University of Central Florida 5 */ 6 package dataModel; 7 8 import databasejavafx.DatabaseJavaFx; 9 import java.util.logging.Logger; 
10 11 /** 12 * 13 * @author kwhiting 14 */ 15 public class FilmDAO 16 { 
17 private String filmName; 
18 private String filmRating; 
19 private String filmDescription; 
20 private Double filmPrice; 
21 private static final Logger logger = Logger.getLogger(FilmDAO.class.getName()); 
22 23 // Data Access Object (DAO) 24 25 /** 26 * 27 */ 28 public FilmDAO() 29 { 30 31 } 32 33 /** 34 * 
35 * @param name 
36 * @param rating 
37 * @param description 
38 * @param price 

39 */

40 public FilmDAO(String name, String rating, String description, Double price) 

41 {

42 this.filmName = name; 
43 this.filmRating = rating; 
44 this.filmDescription = description; 
45 this.filmPrice = price; 

46 }

1.1 of 3 2016.11.30 14:24:19

C:/Users/kwhiting/Documents/NetBeansProjects/DatabaseJavaFx/src/dataModel/FilmDAO.java

46 }

47 48 /** 49 *

50 51 52 53 { 54 return filmName; 55 } 

56 57 /** 58 *

* @return

 */ public String getFilmName() 
59 60 61 62 { 63 this.filmName = filmName; 64 } 

65 66 /** 67 *

* @param filmName 
 */ public void setFilmName(String filmName) 
68 69 70 71 { 72 return filmRating; 73 } 

74 75 /** 76 *

* @return

 */ public String getFilmRating() 
77 78 79 80 { 81 this.filmRating = filmRating; 82 } 

83 84 /** 85 *

* @param filmRating 
 */ public void setFilmRating(String filmRating) 
86 87 88 89 { 90 return filmDescription; 91 } 

* @return

 */ public String getFilmDescription() 

2.1 of 3 2016.11.30 14:24:19

C:/Users/kwhiting/Documents/NetBeansProjects/DatabaseJavaFx/src/dataModel/FilmDAO.java

92 93 /** 94 *

 95 96 97 98 { 99 this.filmDescription = filmDescription; 
100 } 101 102 /** 
* @param filmDescription 
 */ public void setFilmDescription(String filmDescription) 
103 104 105 106 107 { 108 return filmPrice; 109 } 

110 111 /**

* * @return */

public Double getFilmPrice() 
112 113 114 115 116 { 117 this.filmPrice = filmPrice; 118 } 

119 }

* * @param filmPrice */ 
public void setFilmPrice(Double filmPrice) 

3.1 of 3 2016.11.30 14:24:19

C:/Users/kwhiting/Documents/NetBeansProjects/DatabaseJavaFx/src/inputOutput/properties.xml

 1  2  7  
 8  
 9 jdbc:postgresql 
10 localhost 
11 5432 
12 dvdrental 
13 postgres 
14 cop3330 

15

16  

1.1 of 1 2016.11.09 15:03:43

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!