Advertisement
Guest User

Untitled

a guest
Dec 4th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 60.79 KB | None | 0 0
  1. package DogHouse;
  2.  
  3. import java.net.URL;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.PreparedStatement;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. import java.sql.Statement;
  10. import java.time.LocalDate;
  11. import java.util.ArrayList;
  12. import java.util.HashSet;
  13. import java.util.Optional;
  14. import javafx.application.Application;
  15. import javafx.collections.FXCollections;
  16. import javafx.collections.ObservableList;
  17. import javafx.geometry.Insets;
  18. import javafx.geometry.Pos;
  19. import javafx.scene.Group;
  20. import javafx.scene.Scene;
  21. import javafx.scene.control.Alert;
  22. import javafx.scene.control.Alert.AlertType;
  23. import javafx.scene.image.Image;
  24. import javafx.scene.image.ImageView;
  25. import javafx.scene.control.Button;
  26. import javafx.scene.control.ChoiceBox;
  27. import javafx.scene.control.DatePicker;
  28. import javafx.scene.control.Label;
  29. import javafx.scene.control.TableColumn;
  30. import javafx.scene.control.TableView;
  31. import javafx.scene.control.TextField;
  32. import javafx.scene.control.TextInputDialog;
  33. import javafx.scene.control.cell.PropertyValueFactory;
  34. import javafx.scene.layout.AnchorPane;
  35. import javafx.scene.layout.Background;
  36. import javafx.scene.layout.BackgroundFill;
  37. import javafx.scene.layout.Border;
  38. import javafx.scene.layout.BorderPane;
  39. import javafx.scene.layout.BorderStroke;
  40. import javafx.scene.layout.BorderStrokeStyle;
  41. import javafx.scene.layout.BorderWidths;
  42. import javafx.scene.layout.GridPane;
  43. import javafx.scene.layout.HBox;
  44. import javafx.scene.layout.VBox;
  45. import javafx.scene.media.Media;
  46. import javafx.scene.media.MediaPlayer;
  47. import javafx.scene.paint.Color;
  48. import javafx.scene.text.Font;
  49. import javafx.scene.text.Text;
  50. import javafx.stage.Stage;
  51. import javafx.util.Duration;
  52.  
  53. public class UserInputPane extends Application {
  54.  
  55. private static MediaPlayer welcomeMessage;
  56. private static MediaPlayer welcomeBGM;
  57. private static MediaPlayer userInputSpeak;
  58. private static MediaPlayer informationSaved;
  59. private static MediaPlayer readyed;
  60. private static MediaPlayer error;
  61. private static MediaPlayer saved;
  62. private static MediaPlayer deleted;
  63. private static MediaPlayer properWeightOrHeight;
  64. private static MediaPlayer entryExisted;
  65. private static MediaPlayer properPhoneNumber;
  66.  
  67.  
  68. public static TableView<Dog> table = new TableView<Dog>();
  69.  
  70. public static TableView<Dog> table1 = new TableView<Dog>();
  71.  
  72. public static ArrayList<Dog> dogInformation = new ArrayList<>();
  73.  
  74. public static ObservableList<Dog> data = FXCollections.observableArrayList();
  75.  
  76. public boolean unique = true;
  77.  
  78. public Dog dog;
  79.  
  80. @Override
  81. public void start(Stage primaryStage) throws Exception {
  82.  
  83. /*
  84. * line 102
  85. * and removed some mp3 please check
  86. * line 288
  87. * line 465
  88. */
  89.  
  90.  
  91. /////////////////////First Pane That Has Dog House Logo/////////////////////
  92.  
  93. BorderPane border = new BorderPane();
  94. border.setBackground(new Background(new BackgroundFill(Color.WHITE, null, null)));
  95. border.setPadding(new Insets(25, 25, 25, 25));
  96.  
  97. /////////////////////Buttons for first pane /////////////////////
  98.  
  99. Button button = new Button("OK");
  100. // Button backToJavaFXPane = new Button("Back");
  101.  
  102.  
  103. // backToJavaFXPane.setOnAction(value ->{
  104. // javaFXPane js = new javaFXPane();
  105. // Stage jsStage = new Stage();
  106. // try {
  107. // js.start(jsStage);
  108. // primaryStage.close();
  109. // welcomeMessage.stop();
  110. // welcomeBGM.stop();
  111. // }catch (Exception e3) {
  112. // // TODO Auto-generated catch block
  113. // e3.printStackTrace();
  114. // }
  115. // });
  116.  
  117. /////////////////////Buttons needed after entering the information/////////////////////
  118.  
  119. Button ready = new Button("Ready");
  120. Button notReady = new Button("Clear");
  121. Button viewInfor = new Button("View");
  122. Button AddPet = new Button("Add");
  123.  
  124. /////////////////////Buttons for entering the information /////////////////////
  125.  
  126. Button save = new Button("Save");
  127. Button proceed = new Button("Proceed");
  128. Button back = new Button("Back");
  129. Button backToPrimary = new Button("Back");
  130. Button viewDatabase = new Button("View");
  131.  
  132. button.setTextFill(Color.WHITE);
  133. button.setStyle("-fx-background-color: Black");
  134. button.setOnAction(e->{
  135.  
  136. /////////////////////Entering Dog information /////////////////////
  137.  
  138. primaryStage.close();
  139. welcomeMessage.stop();
  140. final URL resource2 = getClass().getResource("userInput.mp3");
  141. final Media media2 = new Media(resource2.toString());
  142. userInputSpeak = new MediaPlayer(media2);
  143. userInputSpeak.play();
  144. Stage secondaryStage = new Stage();
  145. GridPane pane = new GridPane();
  146.  
  147. pane.setAlignment(Pos.CENTER);
  148. pane.setHgap(5);
  149. pane.setVgap(5);
  150. pane.setBackground(new Background(new BackgroundFill(Color.WHITE, null, null)));
  151. //The user input fields
  152. Label name = new Label("name: ");
  153. name.setFont(new Font("Times New Roman",17));
  154. pane.add(name, 0, 1);
  155. TextField nameText = new TextField();
  156. nameText.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  157. pane.add(nameText, 1 ,1);
  158.  
  159.  
  160. Label breed = new Label("breed: ");
  161. breed.setFont(new Font("Times New Roman",17));
  162. pane.add(breed, 0, 2);
  163. ChoiceBox<String> breedChoice = new ChoiceBox<String>(FXCollections.observableArrayList(
  164. "Retrievers (Labrador) ", "German Shepherds", "Retrievers (Golden) ","French Bulldogs "
  165. ,"Bulldogs","Beagles","Poodles","Rottweilers","Yorkshire Terriers","Pointers (German Shorthaired)"
  166. , "Boxers","Siberian Huskies", "Great Danes","Pomeranians","Pugs","Huskies","Chihuahua"
  167. , "Corgis","Doberman Pinschers","Shih Tzu","Boston Terriers","Havanese","Shetland Sheepdogs","Maltese"
  168. ,"Weimaraners","Collies","Shiba Inu","Retrievers (Chesapeake Bay)","Akitas","Papillons","Dalmatians"
  169. ,"Italian Greyhounds","Mixed","Other")
  170. );
  171. breedChoice.setStyle("-fx-background-color: WHITE");
  172. breedChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  173. breedChoice.getSelectionModel().select(0);
  174. pane.add(breedChoice, 1, 2);
  175.  
  176.  
  177. Label gender = new Label("gender: ");
  178. gender.setFont(new Font("Times New Roman",17));
  179. pane.add(gender, 0, 3);
  180. ChoiceBox<String> genderChoice= new ChoiceBox<>();
  181. genderChoice.setStyle("-fx-background-color: WHITE");
  182. genderChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  183. genderChoice.getItems().addAll("Male", "Female");
  184. genderChoice.getSelectionModel().select(0);
  185. pane.add(genderChoice, 1 ,3);
  186.  
  187.  
  188. Label furColor = new Label("fur color: ");
  189. furColor.setFont(new Font("Times New Roman",17));
  190. pane.add(furColor, 0, 4);
  191. ChoiceBox<String> furColorChoice= new ChoiceBox<>();
  192. furColorChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  193. furColorChoice.setStyle("-fx-background-color: WHITE");
  194. furColorChoice.getItems().addAll("Brown", "Red","Gold","Yellow","Cream","Blue","Gray","Two color striped","Three color striped","Dotted","Beige","Tan","Orange","Light Brown"
  195. ,"Dark Brown","Apricot","Fawn","Chestnut","Black","Rust","Wheaten","White","Other");
  196. furColorChoice.getSelectionModel().select(0);
  197. pane.add(furColorChoice, 1, 4);
  198.  
  199.  
  200. Label weight = new Label("weight(in lb): ");
  201. weight.setFont(new Font("Times New Roman",17));
  202. pane.add(weight, 0, 5);
  203. TextField weightText = new TextField();
  204. weightText.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  205. pane.add(weightText, 1 ,5);
  206.  
  207.  
  208. Label height = new Label("height(in inches): ");
  209. height.setFont(new Font("Times New Roman",17));
  210. pane.add(height, 0, 6);
  211. TextField heightText = new TextField();
  212. heightText.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  213. pane.add(heightText, 1, 6);
  214.  
  215.  
  216. Label birthday = new Label("birthday: ");
  217. birthday.setFont(new Font("Times New Roman",17));
  218. pane.add(birthday, 0, 7);
  219. DatePicker datePicker = new DatePicker();
  220. datePicker.setStyle("-fx-control-inner-background: WHITE;");
  221. datePicker.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  222. pane.add(datePicker, 1, 7);
  223.  
  224.  
  225. Label neutorSpay= new Label("Is your pet neutored or spayed? ");
  226. neutorSpay.setFont(new Font("Times New Roman",17));
  227. pane.add(neutorSpay, 0, 8);
  228. ChoiceBox<String> neutorSpayChoice = new ChoiceBox<String>(FXCollections.observableArrayList(
  229. "Yes", "No")
  230. );
  231. neutorSpayChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  232. neutorSpayChoice.setStyle("-fx-background-color: WHITE");
  233. neutorSpayChoice.getSelectionModel().select(0);
  234. pane.add(neutorSpayChoice, 1 ,8);
  235.  
  236.  
  237. Label microchipped = new Label("Does your pet have microchip? ");
  238. microchipped.setFont(new Font("Times New Roman",17));
  239. pane.add(microchipped, 0, 9);
  240. ChoiceBox<String> microchippedChoice= new ChoiceBox<>();
  241. microchippedChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  242. microchippedChoice.setStyle("-fx-background-color: WHITE");
  243. microchippedChoice.getItems().addAll("Yes","No");
  244. microchippedChoice.getSelectionModel().select(0);
  245. pane.add(microchippedChoice, 1, 9);
  246.  
  247. Label phoneNumber = new Label("phone number: ");
  248. phoneNumber.setFont(new Font("Times New Roman",17));
  249. pane.add(phoneNumber, 0, 10);
  250. TextField phoneNumberText = new TextField();
  251. phoneNumberText.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  252. pane.add(phoneNumberText, 1 ,10);
  253.  
  254.  
  255. Label provider = new Label("provider: ");
  256. provider.setFont(new Font("Times New Roman",17));
  257. pane.add(provider, 0, 11);
  258. ChoiceBox<String> providerChoice= new ChoiceBox<>();
  259. providerChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  260. providerChoice.setStyle("-fx-background-color: WHITE");
  261. providerChoice.getItems().addAll("Metropcs","ATT","TMobile","Sprint","Cricket");
  262. providerChoice.getSelectionModel().select(0);
  263. pane.add(providerChoice, 1, 11);
  264.  
  265. save.setOnAction(e3->{
  266.  
  267. /////////////////////Save the information /////////////////////
  268.  
  269. String option = genderChoice.getValue().toString();
  270. String neutorSpayOption = neutorSpayChoice.getValue().toString();
  271. String breedOption = breedChoice.getValue().toString();
  272. String furColorOption = furColorChoice.getValue().toString();
  273. String providerOption = providerChoice.getValue().toString();
  274. String microchippedOption = microchippedChoice.getValue().toString();
  275. LocalDate value = datePicker.getValue();
  276. String breedSpecify = "";
  277. String furColorSpecify = "";
  278.  
  279.  
  280. if(!nameText.getText().trim().isEmpty()&&!option.trim().isEmpty() &&
  281. !neutorSpayOption.trim().isEmpty()&& !breedOption.trim().isEmpty()
  282. &&!furColorOption.trim().isEmpty()&& !microchippedOption.trim().isEmpty()
  283. &&value!=null&&!weightText.getText().trim().isEmpty()&&!heightText.getText().trim().isEmpty()
  284. &&!phoneNumberText.getText().trim().isEmpty()
  285. &&!providerOption.trim().isEmpty()
  286. ) {
  287.  
  288. ///////////////////// Specify when choose "Other" /////////////////////
  289.  
  290. if(breedOption.equalsIgnoreCase("Other") || breedOption.equalsIgnoreCase("Mixed")) {
  291. userInputSpeak.stop();
  292.  
  293.  
  294. TextInputDialog dialog = new TextInputDialog("Golden Retriever");
  295. dialog.setTitle("Specify breed");
  296. dialog.setHeaderText(null);
  297. dialog.setContentText("Please specify breed:");
  298. Optional<String> result = dialog.showAndWait();
  299. if(result.isPresent())
  300. breedSpecify = result.get();
  301.  
  302. }else {
  303. breedSpecify = breedOption;
  304. }
  305.  
  306. if(furColorOption.equalsIgnoreCase("Other")) {
  307. userInputSpeak.stop();
  308.  
  309. TextInputDialog dialog = new TextInputDialog("Brown");
  310. dialog.setTitle("Specify fur color");
  311. dialog.setHeaderText(null);
  312. dialog.setContentText("Please specify fur color:");
  313. Optional<String> result = dialog.showAndWait();
  314. if(result.isPresent())
  315. furColorSpecify = result.get();
  316.  
  317. }else {
  318. furColorSpecify = furColorOption;
  319.  
  320. }
  321.  
  322. /////////////////////Numerical validation /////////////////////
  323.  
  324. if(isValidWeight(weightText.getText())==false||isValidHeight(heightText.getText())==false) {
  325. userInputSpeak.stop();
  326. final URL properWOHUrl = getClass().getResource("properWeightOrHeight.mp3");
  327. final Media properWOHMedia = new Media(properWOHUrl.toString());
  328. properWeightOrHeight = new MediaPlayer(properWOHMedia);
  329. properWeightOrHeight.play();
  330. Alert alert = new Alert(AlertType.ERROR);
  331. alert.setTitle("Error!");
  332. alert.setContentText("Please enter the proper weight or height!");
  333. alert.showAndWait();
  334. properWeightOrHeight.stop();
  335.  
  336.  
  337. if(isValidWeight(weightText.getText())==false) {
  338. weightText.setText("");
  339. }
  340. if(isValidHeight(heightText.getText())==false) {
  341. heightText.setText("");
  342. }
  343. }
  344. if(isValidPhoneNumber(phoneNumberText.getText())==false) {
  345. userInputSpeak.stop();
  346. final URL phoneRe = getClass().getResource("properPhoneNumber.mp3");
  347. final Media phoneMe = new Media(phoneRe.toString());
  348. properPhoneNumber = new MediaPlayer(phoneMe);
  349. properPhoneNumber.play();
  350. Alert alert = new Alert(AlertType.ERROR);
  351. alert.setTitle("Error!");
  352. alert.setContentText("Please enter the proper phone number!");
  353. alert.showAndWait();
  354. properPhoneNumber.stop();
  355. phoneNumberText.setText("");
  356. }
  357.  
  358.  
  359. }
  360.  
  361.  
  362.  
  363. if(!weightText.getText().trim().isEmpty()&&!heightText.getText().trim().isEmpty()) {
  364. dog = new Dog(nameText.getText(),breedSpecify,option,
  365. furColorOption,Double.parseDouble(weightText.getText()),Double.parseDouble(heightText.getText()),
  366. value,convertToBoolean(neutorSpayOption),convertToBoolean(microchippedOption),phoneNumberText.getText(),providerOption);
  367. }
  368.  
  369.  
  370.  
  371. if(!weightText.getText().trim().isEmpty()&&!heightText.getText().trim().isEmpty()&&!option.trim().isEmpty()
  372. && !breedSpecify.trim().isEmpty() && !furColorSpecify.trim().isEmpty()
  373. && !neutorSpayOption.trim().isEmpty()
  374. && !microchippedOption.trim().isEmpty() && !nameText.getText().trim().isEmpty() &&
  375. !phoneNumberText.getText().trim().isEmpty()&& !providerOption.trim().isEmpty()
  376. && dogInformation.contains(dog)==false ) {
  377.  
  378.  
  379.  
  380.  
  381. dogInformation.add(dog);
  382.  
  383. /////////////////////Add the information to MySQL database /////////////////////
  384.  
  385. String url = "jdbc:mysql://localhost/cs3220stu55?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
  386. String username = "cs3220stu55";
  387. String password = "zWpa0NxR";
  388.  
  389. Connection conn;
  390.  
  391. try{
  392.  
  393. //STEP 2: Register JDBC driver
  394. Class.forName("com.mysql.cj.jdbc.Driver");
  395.  
  396. //STEP 3: Open a connection
  397.  
  398. conn = DriverManager.getConnection(url, username, password);
  399.  
  400. Statement statement = conn.createStatement() ;
  401. ResultSet resultset = statement.executeQuery("SELECT * FROM pet") ;
  402. while(resultset.next()){
  403. if(resultset.getString("name").equalsIgnoreCase(dog.getName())
  404. && resultset.getString("breed").equalsIgnoreCase(dog.getBreed())
  405. && resultset.getString("gender").equalsIgnoreCase(dog.getGender())
  406. && resultset.getString("furColor").equalsIgnoreCase(dog.getFurColor())
  407. && resultset.getDouble("weight") == dog.getWeight()
  408. && resultset.getDouble("height") == dog.getHeight()
  409. && resultset.getBoolean("neutorSpay") == dog.getNeuterSpay()
  410. && resultset.getBoolean("microchipped") == dog.getMicrochip()
  411. && resultset.getString("phoneNumber").equalsIgnoreCase(dog.getPhoneNumber())
  412. && resultset.getString("provider").equalsIgnoreCase(dog.getProvider())
  413.  
  414. ){
  415.  
  416. ///////////////////// for preventing duplicates added to the database /////////////////////
  417. unique = false;
  418. final URL entryExistedR = getClass().getResource("entryExisted.mp3");
  419. final Media entryExistedM = new Media(entryExistedR.toString());
  420. entryExisted = new MediaPlayer(entryExistedM);
  421. entryExisted.play();
  422. Alert alert = new Alert(AlertType.ERROR);
  423. alert.setTitle("Error!");
  424. alert.setContentText("Entry: " + dog.getName() + " already existed in our database!");
  425. alert.showAndWait();
  426. entryExisted.stop();
  427. weightText.clear();
  428. heightText.clear();
  429. nameText.clear();
  430. phoneNumberText.clear();
  431.  
  432. providerChoice.getSelectionModel().select(0);
  433. breedChoice.getSelectionModel().select(0);
  434. furColorChoice.getSelectionModel().select(0);
  435. neutorSpayChoice.getSelectionModel().select(0);
  436. microchippedChoice.getSelectionModel().select(0);
  437.  
  438. datePicker.setValue(null);
  439. unique = true;
  440. }
  441. }
  442. if(unique == true
  443. && !weightText.getText().trim().isEmpty()&&!heightText.getText().trim().isEmpty()) {
  444. String query = " insert into pet (name, breed,gender,furColor, weight, height,birthday, neutorSpay, microchipped, phoneNumber, provider)"
  445. + " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  446. PreparedStatement preparedStmt = conn.prepareStatement(query);
  447. preparedStmt.setString (1, nameText.getText());
  448. preparedStmt.setString (2, breedSpecify);
  449. preparedStmt.setString (3, option);
  450. preparedStmt.setString (4, furColorSpecify);
  451. preparedStmt.setDouble (5, Double.parseDouble(weightText.getText()));
  452. preparedStmt.setDouble (6, Double.parseDouble(heightText.getText()));
  453. preparedStmt.setDate (7, java.sql.Date.valueOf(value));
  454. preparedStmt.setBoolean(8, convertToBoolean(neutorSpayOption));
  455. preparedStmt.setBoolean(9, convertToBoolean(microchippedOption));
  456. preparedStmt.setString (10, phoneNumberText.getText());
  457. preparedStmt.setString (11, providerOption);
  458.  
  459.  
  460.  
  461.  
  462. // execute the preparedstatement
  463. preparedStmt.execute();
  464.  
  465. conn.close();
  466.  
  467. userInputSpeak.stop();
  468.  
  469. /////////////////////information saved /////////////////////
  470.  
  471. final URL resource3 = getClass().getResource("informationSaved.mp3");
  472. final Media media3 = new Media(resource3.toString());
  473. informationSaved = new MediaPlayer(media3);
  474. informationSaved.play();
  475. Alert alert1 = new Alert(AlertType.INFORMATION);
  476. alert1.setTitle("Saved");
  477. alert1.setContentText(dog.getName() + "' Information saved!");
  478. alert1.showAndWait();
  479. informationSaved.stop();
  480.  
  481.  
  482. }
  483. }catch(SQLException se) {
  484. se.printStackTrace();
  485. } catch (ClassNotFoundException e2) {
  486. e2.printStackTrace();
  487. }
  488.  
  489.  
  490. }
  491.  
  492. if(nameText.getText()==null || nameText.getText().trim().isEmpty()
  493. ||breedSpecify==null || breedSpecify.trim().isEmpty()
  494. ||option==null || option.trim().isEmpty()
  495. ||furColorChoice.getValue().toString()==null || furColorChoice.getValue().toString().trim().isEmpty()
  496. ||weightText.getText()==null || weightText.getText().trim().isEmpty()
  497. ||heightText.getText()==null || heightText.getText().trim().isEmpty()
  498. ||value == null
  499. ||neutorSpayOption==null || neutorSpayOption.trim().isEmpty()
  500. ||microchippedOption==null || microchippedOption.trim().isEmpty()
  501. || phoneNumberText.getText().trim().isEmpty() || phoneNumberText.getText() == null ||
  502. providerOption.trim().isEmpty()|| providerOption==null
  503. ) {
  504.  
  505.  
  506. userInputSpeak.stop();
  507. final URL resource5 = getClass().getResource("error.mp3");
  508. final Media media5 = new Media(resource5.toString());
  509. error = new MediaPlayer(media5);
  510. error.play();
  511. Alert alert = new Alert(AlertType.ERROR);
  512. alert.setTitle("Error!");
  513. alert.setContentText("Please fill in all the fields!!");
  514. alert.showAndWait();
  515. error.stop();
  516.  
  517.  
  518.  
  519.  
  520.  
  521. }
  522. else{
  523.  
  524.  
  525. }
  526. });
  527.  
  528.  
  529. backToPrimary.setOnAction(event->{
  530. secondaryStage.close();
  531. primaryStage.show();
  532. userInputSpeak.stop();
  533. welcomeMessage.play();
  534. });
  535.  
  536.  
  537. proceed.setOnAction(e1->{
  538.  
  539. /////////////////////proceed only works after saved /////////////////////
  540.  
  541. if(nameText.getText()==null || nameText.getText().trim().isEmpty()
  542. ||breedChoice.getValue()==null || breedChoice.getValue().toString().trim().isEmpty()
  543. ||genderChoice.getValue().toString()==null || genderChoice.getValue().toString().trim().isEmpty()
  544. ||furColorChoice.getValue().toString()==null || furColorChoice.getValue().toString().trim().isEmpty()
  545. ||weightText.getText()==null || weightText.getText().trim().isEmpty()
  546. ||heightText.getText()==null || heightText.getText().trim().isEmpty()
  547. || datePicker.getValue() == null
  548. ||neutorSpayChoice.getValue().toString()==null || neutorSpayChoice.getValue().toString().trim().isEmpty()
  549. ||microchippedChoice.getValue().toString()==null || microchippedChoice.getValue().toString().trim().isEmpty()
  550. ||phoneNumberText.getText().trim().isEmpty()||phoneNumberText.getText()==null
  551. ||providerChoice.getValue().toString().trim().isEmpty() || providerChoice.getValue().toString()==null
  552. ) {
  553.  
  554.  
  555. userInputSpeak.stop();
  556. final URL resource5 = getClass().getResource("error.mp3");
  557. final Media media5 = new Media(resource5.toString());
  558. error = new MediaPlayer(media5);
  559. error.play();
  560. Alert alert = new Alert(AlertType.ERROR);
  561. alert.setTitle("Error!");
  562. alert.setContentText("Please fill in all the fields!!");
  563. alert.showAndWait();
  564. error.stop();
  565. // userInputSpeak.play();
  566.  
  567.  
  568.  
  569.  
  570.  
  571. }
  572.  
  573. /////////////////////ArrayList dogInformation only add entries when save button is pressed /////////////////////
  574.  
  575. else if(dogInformation.isEmpty()) {
  576.  
  577. userInputSpeak.stop();
  578. final URL resource6 = getClass().getResource("saveAlert.mp3");
  579. final Media media6 = new Media(resource6.toString());
  580. saved = new MediaPlayer(media6);
  581. saved.play();
  582. Alert alert = new Alert(AlertType.ERROR);
  583. alert.setTitle("Error!");
  584. alert.setContentText("Please save the information to proceed!!");
  585. alert.showAndWait();
  586. }
  587. else {
  588.  
  589. userInputSpeak.stop();
  590.  
  591. final URL resource4 = getClass().getResource("ready.mp3");
  592. final Media media4 = new Media(resource4.toString());
  593. readyed = new MediaPlayer(media4);
  594. readyed.play();
  595. secondaryStage.close();
  596. Stage tertiaryStage = new Stage();
  597. GridPane gridPane = new GridPane();
  598. gridPane.setAlignment(Pos.CENTER);
  599. gridPane.setHgap(10);
  600. gridPane.setVgap(10);
  601. gridPane.setPadding(new Insets(25, 25, 25, 25));
  602. Label message = new Label("Are you ready for the ADH? ");
  603. message.setFont(new Font("Times New Roman", 30));
  604. Image image = new Image("cuteDoggy.gif");
  605. ImageView imageView = new ImageView();
  606. imageView.setImage(image);
  607. imageView.setFitHeight(150);
  608. imageView.setFitWidth(90);
  609. message.setGraphic(imageView);
  610. gridPane.add(message, 0, 1);
  611.  
  612.  
  613. ready.setOnAction(e2->{
  614. welcomeBGM.stop();
  615. readyed.stop();
  616. tertiaryStage.close();
  617. javaFXPane jp1 = new javaFXPane();
  618. Stage stage = new Stage();
  619. try {
  620. jp1.start(stage);
  621. } catch (Exception e3) {
  622. // TODO Auto-generated catch block
  623. e3.printStackTrace();
  624. }
  625. });
  626.  
  627. viewInfor.setOnAction(e6->{
  628. data.clear();
  629. String url = "jdbc:mysql://localhost/cs3220stu55?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
  630. String username = "cs3220stu55";
  631. String password = "zWpa0NxR";
  632.  
  633.  
  634.  
  635.  
  636. try {
  637. Connection c = DriverManager
  638. .getConnection( url, username, password );
  639. Statement stmt = c.createStatement();
  640.  
  641. ResultSet rs = stmt.executeQuery( "select * from pet" );
  642.  
  643. while( rs.next() )
  644. {
  645. LocalDate today = rs.getDate("birthday").toLocalDate();
  646. LocalDate tomorrow = today.plusDays(1);
  647. data.add(new Dog(rs.getString("name"),rs.getString("breed"),
  648. rs.getString("gender"),rs.getString("furColor"),rs.getInt("weight"),rs.getInt("height"),
  649. tomorrow,rs.getBoolean("neutorSpay"),rs.getBoolean("microchipped"), rs.getString("phoneNumber"),rs.getString("provider")));
  650.  
  651. }
  652.  
  653. c.close();
  654.  
  655.  
  656.  
  657.  
  658.  
  659. } catch (Exception exception) {
  660. exception.printStackTrace();
  661. //System.out.println("Error on Building Data");
  662. }
  663. table.getColumns().clear();
  664.  
  665.  
  666. Stage fifthStage = new Stage();
  667.  
  668. Scene scene = new Scene(new Group());
  669.  
  670. final Label label = new Label("Dog Information");
  671. label.setFont(new Font("Arial", 20));
  672.  
  673. table.setEditable(true);
  674.  
  675. TableColumn NameCol = new TableColumn("name");
  676. NameCol.setMaxWidth(100);
  677. NameCol.setCellValueFactory(
  678. new PropertyValueFactory<Dog, String>("name"));
  679.  
  680. TableColumn breedCol = new TableColumn("breed");
  681. breedCol.setMaxWidth(200);
  682. breedCol.setCellValueFactory(
  683. new PropertyValueFactory<Dog, String>("breed"));
  684.  
  685. TableColumn genderCol = new TableColumn("gender");
  686. genderCol.setMaxWidth(100);
  687. genderCol.setCellValueFactory(
  688. new PropertyValueFactory<Dog, String>("gender"));
  689.  
  690. TableColumn furColorCol = new TableColumn("furColor");
  691. furColorCol.setMaxWidth(200);
  692. furColorCol.setCellValueFactory(
  693. new PropertyValueFactory<Dog, String>("furColor"));
  694.  
  695. TableColumn weightCol = new TableColumn("weight(in lbs)");
  696. weightCol.setMaxWidth(100);
  697. weightCol.setCellValueFactory(
  698. new PropertyValueFactory<Dog, String>("weight"));
  699.  
  700. TableColumn heightCol = new TableColumn("height(in inches)");
  701. heightCol.setMaxWidth(150);
  702. heightCol.setCellValueFactory(
  703. new PropertyValueFactory<Dog, String>("height"));
  704.  
  705. TableColumn birthdayCol = new TableColumn("birthday");
  706. birthdayCol.setMaxWidth(100);
  707. birthdayCol.setCellValueFactory(
  708. new PropertyValueFactory<Dog, String>("birthday"));
  709.  
  710. TableColumn spayCol = new TableColumn("neuterSpay");
  711. spayCol.setMaxWidth(100);
  712. spayCol.setCellValueFactory(
  713. new PropertyValueFactory<Dog, String>("neuterSpay"));
  714.  
  715. TableColumn microchippedCol = new TableColumn("microchip");
  716. microchippedCol.setMaxWidth(100);
  717. microchippedCol.setCellValueFactory(
  718. new PropertyValueFactory<Dog, String>("microchip"));
  719.  
  720. TableColumn phoneNumberCol = new TableColumn("phone number");
  721. phoneNumberCol.setMaxWidth(120);
  722. phoneNumberCol.setCellValueFactory(
  723. new PropertyValueFactory<Dog, String>("phoneNumber"));
  724.  
  725. TableColumn providerCol = new TableColumn("provider");
  726. providerCol.setMaxWidth(120);
  727. providerCol.setCellValueFactory(
  728. new PropertyValueFactory<Dog, String>("provider"));
  729.  
  730.  
  731.  
  732. // ObservableList<Dog> list = FXCollections.observableArrayList(dogInformation);
  733. ObservableList<Dog> list = removeDuplicates(data);
  734.  
  735. table.setItems(list);
  736. table.getColumns().addAll(NameCol, breedCol, genderCol,furColorCol, weightCol,
  737. heightCol, birthdayCol, spayCol, microchippedCol,phoneNumberCol,providerCol);
  738.  
  739.  
  740. back.setOnAction(e8->{
  741. fifthStage.close();
  742.  
  743. tertiaryStage.show();
  744. });
  745. notReady.setOnAction(e5->{
  746. fifthStage.close();
  747. readyed.stop();
  748. tertiaryStage.close();
  749. final URL resource5 = getClass().getResource("deleted.mp3");
  750. final Media media5 = new Media(resource5.toString());
  751. deleted = new MediaPlayer(media5);
  752. deleted.play();
  753.  
  754. dogInformation.clear();
  755.  
  756.  
  757. Connection conn = null;
  758. Statement stmte = null;
  759. try{
  760.  
  761.  
  762. Class.forName("com.mysql.cj.jdbc.Driver");
  763.  
  764. conn = DriverManager.getConnection(url, username, password);
  765.  
  766. stmte = conn.createStatement();
  767.  
  768. String sql = "DELETE FROM pet;";
  769.  
  770. stmte.executeUpdate(sql);
  771. }catch(Exception exc) {
  772. exc.printStackTrace();
  773. }
  774. secondaryStage.show();
  775.  
  776. nameText.setText(null);
  777. breedChoice.getSelectionModel().select(0);
  778. genderChoice.getSelectionModel().select(0);
  779. weightText.setText(null);
  780. heightText.setText(null);
  781. furColorChoice.getSelectionModel().select(0);
  782. datePicker.setValue(null);
  783. neutorSpayChoice.getSelectionModel().select(0);
  784. microchippedChoice.getSelectionModel().select(0);
  785.  
  786.  
  787. Alert alert = new Alert(AlertType.INFORMATION);
  788. alert.setTitle("Information");
  789. alert.setHeaderText(null);
  790. alert.setContentText("Please fill in the following!");
  791.  
  792. alert.showAndWait();
  793. deleted.stop();
  794. // userInputSpeak.play();
  795.  
  796. });
  797. Button delete = new Button("Delete This");
  798. delete.setStyle("-fx-background-color: black");
  799. delete.setTextFill(Color.WHITE);
  800. delete.setOnAction(ee->{
  801. Dog selectedItem = table.getSelectionModel().getSelectedItem();
  802. table.getItems().remove(selectedItem);
  803. Connection conn = null;
  804. try{
  805.  
  806.  
  807. Class.forName("com.mysql.cj.jdbc.Driver");
  808.  
  809. conn = DriverManager.getConnection(url, username, password);
  810.  
  811.  
  812. String sql = "DELETE FROM pet where name = ?";
  813.  
  814. PreparedStatement preparedStmt = conn.prepareStatement(sql);
  815. preparedStmt.setString(1,selectedItem.getName());
  816. preparedStmt.execute();
  817. conn.close();
  818.  
  819. }catch(Exception exc) {
  820. exc.printStackTrace();
  821. }
  822. });
  823.  
  824. Button edit = new Button("Edit");
  825. edit.setStyle("-fx-background-color: black");
  826. edit.setTextFill(Color.WHITE);
  827.  
  828. edit.setOnAction(ee->{
  829.  
  830. Dog selectedItem = table.getSelectionModel().getSelectedItem();
  831.  
  832.  
  833.  
  834. Stage editStage = new Stage();
  835. Button editSave = new Button("Save");
  836. editSave.setStyle("-fx-background-color: black");
  837. editSave.setTextFill(Color.WHITE);
  838. GridPane editPane = new GridPane();
  839.  
  840. editPane.setAlignment(Pos.CENTER);
  841. editPane.setHgap(5);
  842. editPane.setVgap(5);
  843. editPane.setBackground(new Background(new BackgroundFill(Color.WHITE, null, null)));
  844. //The user input fields
  845. Label editName = new Label("name: ");
  846. editName.setFont(new Font("Times New Roman",17));
  847. editPane.add(editName, 0, 1);
  848. TextField editNameText = new TextField();
  849. //editNameText.setText(selectedItem.getName());
  850. editNameText.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  851. editPane.add(editNameText, 1 ,1);
  852.  
  853.  
  854. Label editBreed = new Label("breed: ");
  855. editBreed.setFont(new Font("Times New Roman",17));
  856. editPane.add(editBreed, 0, 2);
  857. ChoiceBox<String> editBreedChoice = new ChoiceBox<String>(FXCollections.observableArrayList(
  858. "Retrievers (Labrador) ", "German Shepherds", "Retrievers (Golden) ","French Bulldogs "
  859. ,"Bulldogs","Beagles","Poodles","Rottweilers","Yorkshire Terriers","Pointers (German Shorthaired)"
  860. , "Boxers","Siberian Huskies", "Great Danes","Pomeranians","Pugs","Huskies","Chihuahua"
  861. , "Pembroke Welsh Corgis","Doberman Pinschers","Shih Tzu","Boston Terriers","Havanese","Shetland Sheepdogs","Maltese"
  862. ,"Weimaraners","Collies","Shiba Inu","Retrievers (Chesapeake Bay)","Akitas","Papillons","Dalmatians"
  863. ,"Italian Greyhounds","Mixed","Other")
  864. );
  865. editBreedChoice.setStyle("-fx-background-color: WHITE");
  866. editBreedChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  867. //editBreedChoice.setValue(selectedItem.getBreed());
  868. editPane.add(editBreedChoice, 1, 2);
  869.  
  870.  
  871. Label editGender = new Label("gender: ");
  872. editGender.setFont(new Font("Times New Roman",17));
  873. editPane.add(editGender, 0, 3);
  874. ChoiceBox<String> editGenderChoice= new ChoiceBox<>();
  875. editGenderChoice.setStyle("-fx-background-color: WHITE");
  876. editGenderChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  877. editGenderChoice.getItems().addAll("Male", "Female");
  878. //editGenderChoice.setValue(selectedItem.getGender());
  879. editPane.add(editGenderChoice, 1 ,3);
  880.  
  881.  
  882. Label editFurColor = new Label("fur color: ");
  883. editFurColor.setFont(new Font("Times New Roman",17));
  884. editPane.add(editFurColor, 0, 4);
  885. ChoiceBox<String> editFurColorChoice= new ChoiceBox<>();
  886. editFurColorChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  887. editFurColorChoice.setStyle("-fx-background-color: WHITE");
  888. editFurColorChoice.getItems().addAll("Brown", "Red","Gold","Yellow","Cream","Blue","Gray","Two color striped","Three color striped","Dotted","Beige","Tan","Orange","Light Brown"
  889. ,"Dark Brown","Apricot","Fawn","Chestnut","Rust","Wheaten","White","Other");
  890. //editFurColorChoice.setValue(selectedItem.getFurColor());;
  891. editPane.add(editFurColorChoice, 1, 4);
  892.  
  893.  
  894. Label editWeight = new Label("weight(in lb): ");
  895. editWeight.setFont(new Font("Times New Roman",17));
  896. editPane.add(editWeight, 0, 5);
  897. TextField editWeightText = new TextField();
  898. //editWeightText.setText(String.valueOf(selectedItem.getWeight()));
  899. editWeightText.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  900. editPane.add(editWeightText, 1 ,5);
  901.  
  902.  
  903. Label editHeight = new Label("height(in cm): ");
  904. editHeight.setFont(new Font("Times New Roman",17));
  905. editPane.add(editHeight, 0, 6);
  906. TextField editHeightText = new TextField();
  907. //editHeightText.setText(String.valueOf(selectedItem.getHeight()));
  908. editHeightText.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  909. editPane.add(editHeightText, 1, 6);
  910.  
  911.  
  912. Label editBirthday = new Label("birthday: ");
  913. editBirthday.setFont(new Font("Times New Roman",17));
  914. editPane.add(editBirthday, 0, 7);
  915. DatePicker editDatePicker = new DatePicker();
  916. editDatePicker.setStyle("-fx-control-inner-background: WHITE;");
  917. //editDatePicker.setValue(selectedItem.getBirthday());
  918. editDatePicker.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  919. editPane.add(editDatePicker, 1, 7);
  920.  
  921.  
  922. Label editNeutorSpay= new Label("Is your pet neutored or spayed? ");
  923. editNeutorSpay.setFont(new Font("Times New Roman",17));
  924. editPane.add(editNeutorSpay, 0, 8);
  925. ChoiceBox<String> editNeutorSpayChoice = new ChoiceBox<String>(FXCollections.observableArrayList(
  926. "Yes", "No")
  927. );
  928. editNeutorSpayChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  929. editNeutorSpayChoice.setStyle("-fx-background-color: WHITE");
  930. //editNeutorSpayChoice.setValue(String.valueOf(selectedItem.getNeuterSpay()));
  931. editPane.add(editNeutorSpayChoice, 1 ,8);
  932.  
  933.  
  934. Label editMicrochipped = new Label("Does your pet have microchip? ");
  935. editMicrochipped.setFont(new Font("Times New Roman",17));
  936. editPane.add(editMicrochipped, 0, 9);
  937. ChoiceBox<String> editMicrochippedChoice= new ChoiceBox<>();
  938. editMicrochippedChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  939. editMicrochippedChoice.setStyle("-fx-background-color: WHITE");
  940. editMicrochippedChoice.getItems().addAll("Yes","No");
  941. //editMicrochippedChoice.setValue(String.valueOf(selectedItem.getMicrochip()));;
  942. editPane.add(editMicrochippedChoice, 1, 9);
  943.  
  944. Label editPhoneNumber = new Label("phone number: ");
  945. editPhoneNumber.setFont(new Font("Times New Roman",17));
  946. editPane.add(editPhoneNumber, 0, 10);
  947. TextField editPhoneNumberText = new TextField();
  948. //editNameText.setText(selectedItem.getName());
  949. editPhoneNumberText.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  950. editPane.add(editPhoneNumberText, 1 ,10);
  951.  
  952.  
  953. Label editProvider = new Label("provider: ");
  954. editProvider.setFont(new Font("Times New Roman",17));
  955. editPane.add(editProvider, 0, 11);
  956. ChoiceBox<String> editProviderChoice= new ChoiceBox<>();
  957. editProviderChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  958. editProviderChoice.setStyle("-fx-background-color: WHITE");
  959. editProviderChoice.getItems().addAll("Metropcs","ATT","TMobile","Verizon","Sprint","BoostMobile","Cricket");
  960. //editMicrochippedChoice.setValue(String.valueOf(selectedItem.getMicrochip()));;
  961. editPane.add(editProviderChoice, 1, 11);
  962.  
  963.  
  964. editNameText.setText(selectedItem.getName());
  965. editBreedChoice.setValue(selectedItem.getBreed());
  966. editGenderChoice.setValue(selectedItem.getGender());;
  967. editWeightText.setText(String.valueOf(selectedItem.getWeight()));
  968. editHeightText.setText(String.valueOf(selectedItem.getHeight()));
  969. editFurColorChoice.setValue(selectedItem.getFurColor());
  970. editDatePicker.setValue(selectedItem.getBirthday());
  971. editNeutorSpayChoice.setValue(String.valueOf(selectedItem.getNeuterSpay()));;
  972. editMicrochippedChoice.setValue(String.valueOf(selectedItem.getMicrochip()));;
  973. editPhoneNumberText.setText(selectedItem.getPhoneNumber());
  974. editProviderChoice.setValue(selectedItem.getProvider());
  975.  
  976. editPane.add(editSave, 0, 12);
  977.  
  978. editSave.setOnAction(eee->{
  979.  
  980. String editSpecifyBreed = "";
  981. String editSpecifyColor = "";
  982. Connection conn = null;
  983. try{
  984.  
  985.  
  986. if
  987. (isValidWeight(editWeightText.getText())&&isValidHeight(editHeightText.getText())&&isValidPhoneNumber(editPhoneNumberText.getText())) {
  988.  
  989. if(editBreedChoice.getValue().equalsIgnoreCase("Other")) {
  990. TextInputDialog dialog = new TextInputDialog("Golden Retriever");
  991. dialog.setTitle("Specify breed");
  992. dialog.setHeaderText(null);
  993. dialog.setContentText("Please specify breed:");
  994. Optional<String> result = dialog.showAndWait();
  995. if(result.isPresent())
  996. editSpecifyBreed = result.get();
  997. }else {
  998. editSpecifyBreed = editBreedChoice.getValue();
  999. }
  1000. if(editFurColorChoice.getValue().equalsIgnoreCase("Other")) {
  1001. TextInputDialog dialog = new TextInputDialog("Brown");
  1002. dialog.setTitle("Specify fur color");
  1003. dialog.setHeaderText(null);
  1004. dialog.setContentText("Please specify fur color:");
  1005. Optional<String> result = dialog.showAndWait();
  1006. if(result.isPresent())
  1007. editSpecifyColor = result.get();
  1008. }else {
  1009. editSpecifyColor = editFurColorChoice.getValue();
  1010. }
  1011.  
  1012.  
  1013.  
  1014.  
  1015.  
  1016. Class.forName("com.mysql.cj.jdbc.Driver");
  1017.  
  1018. conn = DriverManager.getConnection(url, username, password);
  1019.  
  1020. String sql = "update pet set breed = ?,"
  1021. + "gender = ?,"
  1022. + "furColor = ?,"
  1023. + "weight = ?,"
  1024. + "height = ?,"
  1025. + "birthday = ?,"
  1026. + "neutorSpay = ?,"
  1027. + "microchipped = ?, "
  1028. + "phoneNumber = ?, "
  1029. + "provider = ?"
  1030. + "where name = ?";
  1031.  
  1032. PreparedStatement preparedStmt = conn.prepareStatement(sql);
  1033. preparedStmt.setString(1,editSpecifyBreed);
  1034. preparedStmt.setString(2,editGenderChoice.getValue());
  1035. preparedStmt.setString(3,editSpecifyColor);
  1036. preparedStmt.setDouble(4, Double.parseDouble(editWeightText.getText()));
  1037. preparedStmt.setDouble(5, Double.parseDouble(editHeightText.getText()));
  1038. preparedStmt.setDate(6, java.sql.Date.valueOf(editDatePicker.getValue()));
  1039. preparedStmt.setBoolean(7, convertToBoolean(editNeutorSpayChoice.getValue()));
  1040. preparedStmt.setBoolean(8, convertToBoolean(editMicrochippedChoice.getValue()));
  1041. preparedStmt.setString(9, editPhoneNumberText.getText());
  1042. preparedStmt.setString(10, editProviderChoice.getValue());
  1043. preparedStmt.setString(11, selectedItem.getName());
  1044.  
  1045.  
  1046. preparedStmt.executeUpdate();
  1047. conn.close();
  1048.  
  1049. Alert alert = new Alert(AlertType.INFORMATION);
  1050. alert.setHeaderText(null);
  1051. alert.setContentText("Edited information has been saved.");
  1052. alert.showAndWait();
  1053.  
  1054. editStage.close();
  1055. }else {
  1056. Alert alert = new Alert(AlertType.ERROR);
  1057. alert.setHeaderText(null);
  1058. alert.setContentText("Please enter proper values!.");
  1059. alert.showAndWait();
  1060.  
  1061. editWeightText.clear();
  1062. editHeightText.clear();
  1063. editPhoneNumberText.clear();
  1064.  
  1065. }
  1066. refreshTable();
  1067.  
  1068. }catch(Exception exc) {
  1069. exc.printStackTrace();
  1070. }
  1071.  
  1072. });
  1073.  
  1074. editStage.setScene(new Scene(editPane,500,500));
  1075. editStage.show();
  1076.  
  1077. });
  1078. final VBox vbox = new VBox();
  1079. vbox.setSpacing(5);
  1080. vbox.setPadding(new Insets(10, 0, 0, 10));
  1081. back.setTextFill(Color.WHITE);
  1082. back.setStyle("-fx-background-color: Black");
  1083. notReady.setTextFill(Color.WHITE);
  1084. notReady.setStyle("-fx-background-color: Black");
  1085. vbox.getChildren().addAll(label, table, back, notReady, delete,edit);
  1086.  
  1087. ((Group) scene.getRoot()).getChildren().addAll(vbox);
  1088.  
  1089. fifthStage.setScene(scene);
  1090. fifthStage.show();
  1091. readyed.stop();
  1092. tertiaryStage.close();
  1093. });
  1094. AddPet.setOnAction(e7->{
  1095. tertiaryStage.close();
  1096. readyed.stop();
  1097. secondaryStage.show();
  1098. // userInputSpeak.play();
  1099. nameText.setText(dog.getName());
  1100. breedChoice.setValue(dog.getBreed());
  1101. genderChoice.setValue(dog.getGender());;
  1102. weightText.setText(String.valueOf(dog.getWeight()));
  1103. heightText.setText(String.valueOf(dog.getHeight()));
  1104. furColorChoice.setValue(dog.getFurColor());
  1105. datePicker.setValue(dog.getBirthday());
  1106. neutorSpayChoice.setValue(String.valueOf(dog.getNeuterSpay()));;
  1107. microchippedChoice.setValue(String.valueOf(dog.getMicrochip()));;
  1108. phoneNumberText.setText(dog.getPhoneNumber());
  1109. providerChoice.setValue(dog.getProvider());
  1110. });
  1111. ready.setTextFill(Color.WHITE);
  1112. ready.setStyle("-fx-background-color: Black");
  1113. viewInfor.setTextFill(Color.WHITE);
  1114. viewInfor.setStyle("-fx-background-color: Black");
  1115. AddPet.setTextFill(Color.WHITE);
  1116. AddPet.setStyle("-fx-background-color: Black");
  1117. gridPane.add(ready, 0, 2);
  1118. // gridPane.add(notReady, 0, 3);
  1119. gridPane.add(viewInfor, 0, 3);
  1120. gridPane.add(AddPet, 0, 4);
  1121.  
  1122. tertiaryStage.setScene(new Scene(gridPane,550,300));
  1123. tertiaryStage.show();
  1124. }
  1125. });
  1126.  
  1127.  
  1128. viewDatabase.setStyle("-fx-background-color: Black");
  1129. viewDatabase.setTextFill(Color.WHITE);
  1130. viewDatabase.setOnAction(event1 ->{
  1131. data.clear();
  1132. userInputSpeak.stop();
  1133. String url = "jdbc:mysql://localhost/cs3220stu55?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
  1134. String username = "cs3220stu55";
  1135. String password = "zWpa0NxR";
  1136.  
  1137. ObservableList<Dog> data = FXCollections.observableArrayList();
  1138.  
  1139.  
  1140. try {
  1141. Connection c = DriverManager
  1142. .getConnection( url, username, password );
  1143. Statement stmt = c.createStatement();
  1144.  
  1145. ResultSet rs = stmt.executeQuery( "select * from pet" );
  1146.  
  1147. while( rs.next() )
  1148. {
  1149. LocalDate today = rs.getDate("birthday").toLocalDate();
  1150. LocalDate tomorrow = today.plusDays(1);
  1151. data.add(new Dog(rs.getString("name"),rs.getString("breed"),
  1152. rs.getString("gender"),rs.getString("furColor"),rs.getInt("weight"),rs.getInt("height"),
  1153. tomorrow,rs.getBoolean("neutorSpay"),rs.getBoolean("microchipped"),rs.getString("phoneNumber"),rs.getString("provider")));
  1154.  
  1155. }
  1156.  
  1157. c.close();
  1158.  
  1159.  
  1160.  
  1161.  
  1162.  
  1163. } catch (Exception exception) {
  1164. exception.printStackTrace();
  1165. //System.out.println("Error on Building Data");
  1166. }
  1167. table1.getColumns().clear();
  1168.  
  1169.  
  1170. Stage sixthStage = new Stage();
  1171.  
  1172. Scene sceneSix = new Scene(new Group());
  1173.  
  1174. final Label label1 = new Label("Dog Information");
  1175. label1.setFont(new Font("Arial", 20));
  1176.  
  1177. table1.setEditable(true);
  1178.  
  1179. TableColumn NameCol = new TableColumn("name");
  1180. NameCol.setMaxWidth(100);
  1181. NameCol.setCellValueFactory(
  1182. new PropertyValueFactory<Dog, String>("name"));
  1183.  
  1184. TableColumn breedCol = new TableColumn("breed");
  1185. breedCol.setMaxWidth(200);
  1186. breedCol.setCellValueFactory(
  1187. new PropertyValueFactory<Dog, String>("breed"));
  1188.  
  1189. TableColumn genderCol = new TableColumn("gender");
  1190. genderCol.setMaxWidth(100);
  1191. genderCol.setCellValueFactory(
  1192. new PropertyValueFactory<Dog, String>("gender"));
  1193.  
  1194. TableColumn furColorCol = new TableColumn("furColor");
  1195. furColorCol.setMaxWidth(200);
  1196. furColorCol.setCellValueFactory(
  1197. new PropertyValueFactory<Dog, String>("furColor"));
  1198.  
  1199. TableColumn weightCol = new TableColumn("weight(in lbs)");
  1200. weightCol.setMaxWidth(100);
  1201. weightCol.setCellValueFactory(
  1202. new PropertyValueFactory<Dog, String>("weight"));
  1203.  
  1204. TableColumn heightCol = new TableColumn("height(in inches)");
  1205. heightCol.setMaxWidth(150);
  1206. heightCol.setCellValueFactory(
  1207. new PropertyValueFactory<Dog, String>("height"));
  1208.  
  1209. TableColumn birthdayCol = new TableColumn("birthday");
  1210. birthdayCol.setMaxWidth(100);
  1211. birthdayCol.setCellValueFactory(
  1212. new PropertyValueFactory<Dog, String>("birthday"));
  1213.  
  1214. TableColumn spayCol = new TableColumn("neuterSpay");
  1215. spayCol.setMaxWidth(100);
  1216. spayCol.setCellValueFactory(
  1217. new PropertyValueFactory<Dog, String>("neuterSpay"));
  1218.  
  1219. TableColumn microchippedCol = new TableColumn("microchip");
  1220. microchippedCol.setMaxWidth(100);
  1221. microchippedCol.setCellValueFactory(
  1222. new PropertyValueFactory<Dog, String>("microchip"));
  1223.  
  1224. TableColumn phoneNumberCol = new TableColumn("phone number");
  1225. phoneNumberCol.setMaxWidth(100);
  1226. phoneNumberCol.setCellValueFactory(
  1227. new PropertyValueFactory<Dog, String>("phoneNumber"));
  1228.  
  1229. TableColumn providerCol = new TableColumn("provider");
  1230. providerCol.setMaxWidth(100);
  1231. providerCol.setCellValueFactory(
  1232. new PropertyValueFactory<Dog, String>("provider"));
  1233.  
  1234.  
  1235. // ObservableList<Dog> list = FXCollections.observableArrayList(dogInformation);
  1236. ObservableList<Dog> list = removeDuplicates(data);
  1237.  
  1238. table1.setItems(list);
  1239. table1.getColumns().addAll(NameCol, breedCol, genderCol,furColorCol, weightCol,
  1240. heightCol, birthdayCol, spayCol, microchippedCol,phoneNumberCol,providerCol);
  1241.  
  1242. Button backToInput = new Button("Back");
  1243. backToInput.setStyle("-fx-background-color: Black");
  1244. backToInput.setTextFill(Color.WHITE);
  1245. backToInput.setOnAction(e8->{
  1246. sixthStage.close();
  1247. // readyed.play();
  1248. secondaryStage.show();
  1249. });
  1250. Button delete = new Button("Delete This");
  1251. delete.setStyle("-fx-background-color: black");
  1252. delete.setTextFill(Color.WHITE);
  1253. delete.setOnAction(ee->{
  1254. Dog selectedItem = table1.getSelectionModel().getSelectedItem();
  1255. table1.getItems().remove(selectedItem);
  1256. Connection conn = null;
  1257. try{
  1258. Class.forName("com.mysql.cj.jdbc.Driver");
  1259.  
  1260. conn = DriverManager.getConnection(url, username, password);
  1261.  
  1262. String sql = "DELETE FROM pet where name = ?";
  1263.  
  1264. PreparedStatement preparedStmt = conn.prepareStatement(sql);
  1265. preparedStmt.setString(1,selectedItem.getName());
  1266. preparedStmt.execute();
  1267. conn.close();
  1268.  
  1269. }catch(Exception exc) {
  1270. exc.printStackTrace();
  1271. }
  1272. });
  1273. Button clearInfor = new Button("Clear");
  1274. clearInfor.setStyle("-fx-background-color: Black");
  1275. clearInfor.setTextFill(Color.WHITE);
  1276. clearInfor.setOnAction(event2->{
  1277.  
  1278. ObservableList<Dog> items = table1.getItems();
  1279.  
  1280. if(!items.isEmpty()) {
  1281. Connection conn = null;
  1282. Statement stmte = null;
  1283. try{
  1284. Class.forName("com.mysql.cj.jdbc.Driver");
  1285.  
  1286. conn = DriverManager.getConnection(url, username, password);
  1287.  
  1288. stmte = conn.createStatement();
  1289.  
  1290. String sql = "DELETE FROM pet;";
  1291.  
  1292. stmte.executeUpdate(sql);
  1293.  
  1294. Alert alert = new Alert(AlertType.INFORMATION);
  1295. alert.setTitle(null);
  1296. alert.setContentText("Deleted!");
  1297. alert.showAndWait();
  1298.  
  1299. sixthStage.close();
  1300. secondaryStage.show();
  1301. //userInputSpeak.play();
  1302.  
  1303. }catch(Exception exc) {
  1304. exc.printStackTrace();
  1305. }
  1306. }else {
  1307. Alert alert = new Alert(AlertType.ERROR);
  1308. alert.setTitle("Error!");
  1309. alert.setContentText("Database is empty, nothing to delete!");
  1310. alert.showAndWait();
  1311. }
  1312. });
  1313.  
  1314. VBox box = new VBox();
  1315. box.setPadding(new Insets(10));
  1316.  
  1317. box.getChildren().addAll(label1,table1,backToInput,clearInfor, delete);
  1318. box.setSpacing(5);
  1319. ((Group) sceneSix.getRoot()).getChildren().addAll(box);
  1320. sixthStage.setScene(sceneSix);
  1321. sixthStage.show();
  1322.  
  1323. });
  1324. save.setTextFill(Color.WHITE);
  1325. save.setStyle("-fx-background-color: Black");
  1326. proceed.setTextFill(Color.WHITE);
  1327. proceed.setStyle("-fx-background-color: Black");
  1328. backToPrimary.setTextFill(Color.WHITE);
  1329. backToPrimary.setStyle("-fx-background-color: Black");
  1330. pane.add(proceed, 1, 12);
  1331. pane.add(save, 0, 12);
  1332. pane.add(backToPrimary, 0, 13);
  1333. pane.add(viewDatabase, 1, 13);
  1334. //pane.add(viewInfor, 0, 12);
  1335. secondaryStage.setScene(new Scene(pane,500,500));
  1336. secondaryStage.show();
  1337.  
  1338. });
  1339.  
  1340. Image image = new Image("Logo.png");
  1341. ImageView imageView = new ImageView();
  1342. imageView.setImage(image);
  1343. imageView.setFitHeight(200);
  1344. imageView.setFitWidth(250);
  1345. // backToJavaFXPane.setTextFill(Color.WHITE);
  1346. // backToJavaFXPane.setStyle("-fx-background-color: Black");
  1347. border.setCenter(imageView);
  1348. // border.setLeft(backToJavaFXPane);
  1349. border.setRight(button);
  1350. // BorderPane.setAlignment(backToJavaFXPane, Pos.BOTTOM_LEFT);
  1351. BorderPane.setAlignment(button, Pos.BOTTOM_RIGHT);
  1352.  
  1353. primaryStage.setScene(new Scene(border,500,500));
  1354. primaryStage.show();
  1355. final URL resource = getClass().getResource("speak.mp3");
  1356. final Media media = new Media(resource.toString());
  1357. final URL resource1 = getClass().getResource("welcomeBGM.mp3");
  1358. final Media media1 = new Media(resource1.toString());
  1359. welcomeBGM = new MediaPlayer(media1);
  1360. welcomeBGM.setVolume(0.1);
  1361. welcomeBGM.setOnEndOfMedia(new Runnable() {
  1362. public void run() {
  1363. welcomeBGM.seek(Duration.ZERO);
  1364. }
  1365. });
  1366. welcomeBGM.play();
  1367. welcomeMessage = new MediaPlayer(media);
  1368. welcomeMessage.play();
  1369. }
  1370. public static void main(String[] args) {
  1371. launch(args);
  1372. }
  1373. public ArrayList<Dog> getList() {
  1374.  
  1375. return dogInformation;
  1376. }
  1377. boolean convertToBoolean(String value) {
  1378. boolean returnValue = false;
  1379. if ("yes".equalsIgnoreCase(value) ||
  1380. "true".equalsIgnoreCase(value))
  1381. returnValue = true;
  1382. return returnValue;
  1383. }
  1384. static ObservableList<Dog> removeDuplicates(ObservableList<Dog> list) {
  1385.  
  1386. // Store unique items in result.
  1387. ObservableList<Dog> result = FXCollections.observableArrayList();
  1388.  
  1389. // Record encountered Strings in HashSet.
  1390. HashSet<Dog> set = new HashSet<>();
  1391.  
  1392. // Loop over argument list.
  1393. for (Dog item : list) {
  1394.  
  1395. // If String is not in set, add it to the list and the set.
  1396. if (!set.contains(item)) {
  1397. result.add(item);
  1398. set.add(item);
  1399. }
  1400. }
  1401. return result;
  1402. }
  1403. //validating whether an input is numeric
  1404. public static boolean isValidHeight(String input)
  1405. {
  1406. double num;
  1407.  
  1408.  
  1409. try
  1410. {
  1411. num = Double.parseDouble(input);
  1412. if(num<0)
  1413. return false;
  1414. if(num>45)
  1415. return false;
  1416. }
  1417. catch(NumberFormatException ex)
  1418. {
  1419. return false;
  1420. }
  1421. return true;
  1422.  
  1423. }
  1424. public static boolean isValidWeight(String input) {
  1425. double num;
  1426. try
  1427. {
  1428. num = Double.parseDouble(input);
  1429. if(num<0)
  1430. return false;
  1431. if(num>343)
  1432. return false;
  1433. }
  1434. catch(NumberFormatException ex)
  1435. {
  1436. return false;
  1437. }
  1438. return true;
  1439. }
  1440. public void refreshTable() {
  1441. data.clear();
  1442. String url = "jdbc:mysql://localhost/cs3220stu55?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
  1443. String username = "cs3220stu55";
  1444. String password = "zWpa0NxR";
  1445.  
  1446. try {
  1447. Connection c = DriverManager
  1448. .getConnection( url, username, password );
  1449. Statement stmt = c.createStatement();
  1450.  
  1451. ResultSet rs = stmt.executeQuery( "select * from pet" );
  1452.  
  1453. while( rs.next() )
  1454. {
  1455. LocalDate today = rs.getDate("birthday").toLocalDate();
  1456. LocalDate tomorrow = today.plusDays(1);
  1457. data.add(new Dog(rs.getString("name"),rs.getString("breed"),
  1458. rs.getString("gender"),rs.getString("furColor"),rs.getInt("weight"),rs.getInt("height"),
  1459. tomorrow,rs.getBoolean("neutorSpay"),rs.getBoolean("microchipped"),rs.getString("phoneNumber"),rs.getString("provider")));
  1460.  
  1461. }
  1462. c.close();
  1463. } catch (Exception exception) {
  1464. exception.printStackTrace();
  1465. //System.out.println("Error on Building Data");
  1466. }
  1467.  
  1468. table.setItems(data);
  1469.  
  1470. }
  1471. private static boolean isValidPhoneNumber(String phoneNo) {
  1472. //validate phone numbers of format "1234567890"
  1473. if (phoneNo.matches("\\d{10}")) return true;
  1474. // //validating phone number with -, . or spaces
  1475. // else if(phoneNo.matches("\\d{3}[-\\.\\s]\\d{3}[-\\.\\s]\\d{4}")) return true;
  1476. // //validating phone number with extension length from 3 to 5
  1477. // else if(phoneNo.matches("\\d{3}-\\d{3}-\\d{4}\\s(x|(ext))\\d{3,5}")) return true;
  1478. // //validating phone number where area code is in braces ()
  1479. // else if(phoneNo.matches("\\(\\d{3}\\)-\\d{3}-\\d{4}")) return true;
  1480. // //return false if nothing matches the input
  1481. else return false;
  1482.  
  1483. }
  1484.  
  1485.  
  1486. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement