Advertisement
Guest User

Untitled

a guest
Dec 7th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.00 KB | None | 0 0
  1. package cheapflights.system.gui;
  2.  
  3. import javafx.application.Application;
  4. import javafx.fxml.FXMLLoader;
  5. import javafx.scene.Parent;
  6. import javafx.scene.Scene;
  7. import javafx.stage.Stage;
  8.  
  9. public class JavaFXDB extends Application{
  10.  
  11. @Override
  12. public void start(Stage stage) throws Exception {
  13. // TODO Auto-generated method stub
  14. Parent root = FXMLLoader.load(getClass().getResource("GUIGUI.fxml"));
  15.  
  16. Scene scene = new Scene(root);
  17.  
  18. stage.setScene(scene);
  19. stage.show();
  20. }
  21.  
  22. public static void main(String[] args) {
  23.  
  24.  
  25. launch(args);
  26. }
  27.  
  28. }
  29.  
  30. package cheapflights.system.gui;
  31.  
  32. import javafx.fxml.FXML;
  33.  
  34. import javafx.scene.control.Label;
  35. import javafx.scene.control.TableColumn;
  36. import javafx.scene.control.TableView;
  37.  
  38. import java.net.URL;
  39. import java.sql.Connection;
  40. import java.sql.DriverManager;
  41. import java.sql.ResultSet;
  42. import java.sql.SQLException;
  43. import java.sql.Statement;
  44. import java.util.ResourceBundle;
  45. import java.util.logging.Level;
  46. import java.util.logging.Logger;
  47.  
  48. import com.mysql.cj.conf.IntegerProperty;
  49.  
  50. import javafx.fxml.Initializable;
  51. import javafx.beans.property.StringProperty;
  52. import javafx.collections.FXCollections;
  53. import javafx.collections.ObservableList;
  54. import javafx.fxml.FXML;
  55. import javafx.scene.*;
  56. import javafx.scene.control.TableColumn;
  57. import javafx.scene.control.TableView;
  58. import javafx.scene.control.cell.PropertyValueFactory;
  59.  
  60. public class TableController implements Initializable {
  61.  
  62. @FXML
  63. private TableView<ModelTable> table;
  64. @FXML
  65. private TableColumn<ModelTable,IntegerProperty> col_flightID;
  66. @FXML
  67. private TableColumn<ModelTable,StringProperty> col_departingCity;
  68. @FXML
  69. private TableColumn<ModelTable,StringProperty> col_arrivalCity;
  70. @FXML
  71. private TableColumn<ModelTable,StringProperty> col_departureTime;
  72. @FXML
  73. private TableColumn<ModelTable,StringProperty> col_arrivalTime;
  74. @FXML
  75. private TableColumn<ModelTable,StringProperty> col_flightDate;
  76. @FXML
  77. private TableColumn<ModelTable,IntegerProperty> col_Quantity;
  78.  
  79. ObservableList<ModelTable> oblist = FXCollections.observableArrayList();
  80.  
  81. @Override
  82. public void initialize(URL location, ResourceBundle resources) {
  83. // TODO Auto-generated method stub
  84.  
  85. Connection myConn = null;
  86. Statement myStmt = null;
  87. ResultSet myRs = null;
  88. try {
  89. myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/demo", "flightuser" , "flightuser");
  90.  
  91. myStmt = myConn.createStatement();
  92.  
  93. // 3. Execute SQL query
  94. myRs = myStmt.executeQuery("select * from Flight");
  95.  
  96. while (myRs.next()) {
  97. oblist.add(new ModelTable(myRs.getInt("flightID"), myRs.getString("departingCity"),
  98. myRs.getString("arrivalCity"), myRs.getString("departureTime"), myRs.getString("arrivalTime"), myRs.getString("flightDate"), myRs.getInt("Quantity") ));
  99. }
  100. } catch (SQLException ex) {
  101. // TODO Auto-generated catch block
  102. Logger.getLogger(TableController.class.getName()).log(Level.SEVERE, null, ex);
  103. }
  104.  
  105.  
  106.  
  107.  
  108. col_flightID.setCellValueFactory(new PropertyValueFactory<>("flightID"));
  109. col_departingCity.setCellValueFactory(new PropertyValueFactory<>("departingCity"));
  110. col_arrivalCity.setCellValueFactory(new PropertyValueFactory<>("arrivalCity"));
  111. col_departureTime.setCellValueFactory(new PropertyValueFactory<>("departureTime"));
  112. col_arrivalTime.setCellValueFactory(new PropertyValueFactory<>("arrivalTime"));
  113. col_flightDate.setCellValueFactory(new PropertyValueFactory<>("flightDate"));
  114. col_Quantity.setCellValueFactory(new PropertyValueFactory<>("Quantity"));
  115.  
  116. table.setItems(oblist);
  117. }
  118.  
  119. }
  120.  
  121. package cheapflights.system.gui;
  122.  
  123. public class ModelTable {
  124.  
  125. private int flightID;
  126. private String departingCity;
  127. private String arrivalCity;
  128. private String departureTime;
  129. private String arrivalTime;
  130. private String flightDate;
  131. private int Quantity;
  132.  
  133.  
  134.  
  135. public ModelTable(int flightID, String departingCity, String arrivalCity,String departureTime, String arrivalTime, String flightDate, int Quantity) {
  136. this.flightID = flightID;
  137. this.departingCity = departingCity;
  138. this.arrivalCity= arrivalCity;
  139. this.departureTime = departureTime;
  140. this.arrivalTime = arrivalTime;
  141. this.flightDate = flightDate;
  142. this.Quantity = Quantity;
  143. }
  144.  
  145. public int getFlight() {
  146. return flightID;
  147. }
  148.  
  149. public void setFlight(int flightID) {
  150. this.flightID = flightID;
  151. }
  152.  
  153. public String getarrivalTime() {
  154. return arrivalTime;
  155. }
  156.  
  157. public void setarrivalTime(String arrivalTime) {
  158. this.arrivalTime = arrivalTime;
  159. }
  160.  
  161. public String getdepartureTime() {
  162. return departureTime;
  163. }
  164.  
  165. public void setdepatureTime(String departureTime) {
  166. this.departureTime = departureTime;
  167. }
  168.  
  169. public String getdepartingCity() {
  170. return departingCity;
  171. }
  172.  
  173. public void setdepartingCity(String departingCity) {
  174. this.departingCity = departingCity;
  175. }
  176.  
  177. public String getarrivalCity() {
  178. return arrivalCity;
  179. }
  180. public void setarrivalCity(String arrivalCity) {
  181. this.arrivalCity = arrivalCity;
  182. }
  183.  
  184. public String getflightDate() {
  185. return flightDate;
  186. }
  187. public void setflightDate(String flightDate) {
  188. this.flightDate = flightDate;
  189. }
  190.  
  191. public int getQuantity() {
  192. return Quantity;
  193. }
  194.  
  195. public void setquntity(int Quantity) {
  196. this.Quantity = Quantity;
  197. }
  198.  
  199.  
  200. }
  201.  
  202. <?xml version="1.0" encoding="UTF-8"?>
  203.  
  204. <?import javafx.geometry.*?>
  205. <?import javafx.scene.control.*?>
  206. <?import java.lang.*?>
  207. <?import javafx.scene.layout.*?>
  208. <?import javafx.scene.layout.AnchorPane?>
  209.  
  210.  
  211. <AnchorPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller = "cheapflights.system.gui.TableController">
  212. <children>
  213. <TableView layoutX="-222.0" layoutY="-32.0" prefHeight="410.0" prefWidth="562.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
  214. <columns>
  215. <TableColumn fx:id="col_flightID" prefWidth="71.0" text="flightID" />
  216. <TableColumn fx:id="col_departingCity" prefWidth="71.0" text="departingCity" />
  217. <TableColumn fx:id="col_arrivalCity" prefWidth="89.0" text="arrivalCity" />
  218. <TableColumn fx:id="col_departureTime" prefWidth="75.0" text="departureTime" />
  219. <TableColumn fx:id="col_arrivalTime" prefWidth="95.0" text="arrivalTime" />
  220. <TableColumn fx:id="col_flightDate" minWidth="0.0" prefWidth="82.0" text="flightDate" />
  221. <TableColumn fx:id="col_Quantity" minWidth="0.0" prefWidth="73.0" text="Quantity" />
  222. </columns>
  223. </TableView>
  224. </children>
  225. </AnchorPane>
  226.  
  227. Exception in Application start method
  228. java.lang.reflect.InvocationTargetException
  229. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  230. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  231. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  232. at java.lang.reflect.Method.invoke(Method.java:498)
  233. at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
  234. at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
  235. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  236. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  237. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  238. at java.lang.reflect.Method.invoke(Method.java:498)
  239. at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
  240. Caused by: java.lang.RuntimeException: Exception in Application start method
  241. at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
  242. at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
  243. at java.lang.Thread.run(Thread.java:748)
  244. Caused by: javafx.fxml.LoadException:
  245. /home/dvd86/git/cis3270-project/TermProject/bin/cheapflights/system/gui/GUIGUI.fxml
  246.  
  247. at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
  248. at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
  249. at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
  250. at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
  251. at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
  252. at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
  253. at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
  254. at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
  255. at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
  256. at cheapflights.system.gui.JavaFXDB.start(JavaFXDB.java:14)
  257. at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
  258. at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
  259. at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
  260. at java.security.AccessController.doPrivileged(Native Method)
  261. at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
  262. at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
  263. at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
  264. at com.sun.glass.ui.gtk.GtkApplication.lambda$null$48(GtkApplication.java:139)
  265. ... 1 more
  266. Caused by: java.lang.NullPointerException
  267. at cheapflights.system.gui.TableController.initialize(TableController.java:87)
  268. at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
  269. ... 17 more
  270. Exception running application cheapflights.system.gui.JavaFXDB
  271.  
  272. Caused by: java.lang.NullPointerException
  273. at cheapflights.system.gui.TableController.initialize(TableController.java:87)
  274. at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
  275. ... 17 more
  276. Exception running application cheapflights.system.gui.JavaFXDB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement