Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 60.74 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. *
  85. * line 102
  86. * and removed some mp3 please check
  87. * line 288
  88. * line 465
  89. */
  90.  
  91.  
  92. /////////////////////First Pane That Has Dog House Logo/////////////////////
  93.  
  94. BorderPane border = new BorderPane();
  95. border.setBackground(new Background(new BackgroundFill(Color.WHITE, null, null)));
  96. border.setPadding(new Insets(25, 25, 25, 25));
  97.  
  98. /////////////////////Buttons for first pane /////////////////////
  99.  
  100. Button button = new Button("OK");
  101. Button backToJavaFXPane = new Button("Back");
  102.  
  103.  
  104. backToJavaFXPane.setOnAction(value ->{
  105. javaFXPane js = new javaFXPane();
  106. Stage jsStage = new Stage();
  107. try {
  108. js.start(jsStage);
  109. primaryStage.close();
  110. welcomeMessage.stop();
  111. welcomeBGM.stop();
  112. }catch (Exception e3) {
  113. // TODO Auto-generated catch block
  114. e3.printStackTrace();
  115. }
  116. });
  117.  
  118. /////////////////////Buttons needed after entering the information/////////////////////
  119.  
  120. Button ready = new Button("Ready");
  121. Button notReady = new Button("Clear");
  122. Button viewInfor = new Button("View");
  123. Button AddPet = new Button("Add");
  124.  
  125. /////////////////////Buttons for entering the information /////////////////////
  126.  
  127. Button save = new Button("Save");
  128. Button proceed = new Button("Proceed");
  129. Button back = new Button("Back");
  130. Button backToPrimary = new Button("Back");
  131. Button viewDatabase = new Button("View");
  132.  
  133. button.setTextFill(Color.WHITE);
  134. button.setStyle("-fx-background-color: Black");
  135. button.setOnAction(e->{
  136.  
  137. /////////////////////Entering Dog information /////////////////////
  138.  
  139. primaryStage.close();
  140. welcomeMessage.stop();
  141. final URL resource2 = getClass().getResource("userInput.mp3");
  142. final Media media2 = new Media(resource2.toString());
  143. userInputSpeak = new MediaPlayer(media2);
  144. userInputSpeak.play();
  145. Stage secondaryStage = new Stage();
  146. GridPane pane = new GridPane();
  147.  
  148. pane.setAlignment(Pos.CENTER);
  149. pane.setHgap(5);
  150. pane.setVgap(5);
  151. pane.setBackground(new Background(new BackgroundFill(Color.WHITE, null, null)));
  152. //The user input fields
  153. Label name = new Label("name: ");
  154. name.setFont(new Font("Times New Roman",17));
  155. pane.add(name, 0, 1);
  156. TextField nameText = new TextField();
  157. nameText.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  158. pane.add(nameText, 1 ,1);
  159.  
  160.  
  161. Label breed = new Label("breed: ");
  162. breed.setFont(new Font("Times New Roman",17));
  163. pane.add(breed, 0, 2);
  164. ChoiceBox<String> breedChoice = new ChoiceBox<String>(FXCollections.observableArrayList(
  165. "Retrievers (Labrador) ", "German Shepherds", "Retrievers (Golden) ","French Bulldogs "
  166. ,"Bulldogs","Beagles","Poodles","Rottweilers","Yorkshire Terriers","Pointers (German Shorthaired)"
  167. , "Boxers","Siberian Huskies", "Great Danes","Pomeranians","Pugs","Huskies","Chihuahua"
  168. , "Corgis","Doberman Pinschers","Shih Tzu","Boston Terriers","Havanese","Shetland Sheepdogs","Maltese"
  169. ,"Weimaraners","Collies","Shiba Inu","Retrievers (Chesapeake Bay)","Akitas","Papillons","Dalmatians"
  170. ,"Italian Greyhounds","Mixed","Other")
  171. );
  172. breedChoice.setStyle("-fx-background-color: WHITE");
  173. breedChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  174. breedChoice.getSelectionModel().select(0);
  175. pane.add(breedChoice, 1, 2);
  176.  
  177.  
  178. Label gender = new Label("gender: ");
  179. gender.setFont(new Font("Times New Roman",17));
  180. pane.add(gender, 0, 3);
  181. ChoiceBox<String> genderChoice= new ChoiceBox<>();
  182. genderChoice.setStyle("-fx-background-color: WHITE");
  183. genderChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  184. genderChoice.getItems().addAll("Male", "Female");
  185. genderChoice.getSelectionModel().select(0);
  186. pane.add(genderChoice, 1 ,3);
  187.  
  188.  
  189. Label furColor = new Label("fur color: ");
  190. furColor.setFont(new Font("Times New Roman",17));
  191. pane.add(furColor, 0, 4);
  192. ChoiceBox<String> furColorChoice= new ChoiceBox<>();
  193. furColorChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  194. furColorChoice.setStyle("-fx-background-color: WHITE");
  195. furColorChoice.getItems().addAll("Brown", "Red","Gold","Yellow","Cream","Blue","Gray","Two color striped","Three color striped","Dotted","Beige","Tan","Orange","Light Brown"
  196. ,"Dark Brown","Apricot","Fawn","Chestnut","Black","Rust","Wheaten","White","Other");
  197. furColorChoice.getSelectionModel().select(0);
  198. pane.add(furColorChoice, 1, 4);
  199.  
  200.  
  201. Label weight = new Label("weight(in lb): ");
  202. weight.setFont(new Font("Times New Roman",17));
  203. pane.add(weight, 0, 5);
  204. TextField weightText = new TextField();
  205. weightText.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  206. pane.add(weightText, 1 ,5);
  207.  
  208.  
  209. Label height = new Label("height(in inches): ");
  210. height.setFont(new Font("Times New Roman",17));
  211. pane.add(height, 0, 6);
  212. TextField heightText = new TextField();
  213. heightText.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  214. pane.add(heightText, 1, 6);
  215.  
  216.  
  217. Label birthday = new Label("birthday: ");
  218. birthday.setFont(new Font("Times New Roman",17));
  219. pane.add(birthday, 0, 7);
  220. DatePicker datePicker = new DatePicker();
  221. datePicker.setStyle("-fx-control-inner-background: WHITE;");
  222. datePicker.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  223. pane.add(datePicker, 1, 7);
  224.  
  225.  
  226. Label neutorSpay= new Label("Is your pet neutored or spayed? ");
  227. neutorSpay.setFont(new Font("Times New Roman",17));
  228. pane.add(neutorSpay, 0, 8);
  229. ChoiceBox<String> neutorSpayChoice = new ChoiceBox<String>(FXCollections.observableArrayList(
  230. "Yes", "No")
  231. );
  232. neutorSpayChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  233. neutorSpayChoice.setStyle("-fx-background-color: WHITE");
  234. neutorSpayChoice.getSelectionModel().select(0);
  235. pane.add(neutorSpayChoice, 1 ,8);
  236.  
  237.  
  238. Label microchipped = new Label("Does your pet have microchip? ");
  239. microchipped.setFont(new Font("Times New Roman",17));
  240. pane.add(microchipped, 0, 9);
  241. ChoiceBox<String> microchippedChoice= new ChoiceBox<>();
  242. microchippedChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  243. microchippedChoice.setStyle("-fx-background-color: WHITE");
  244. microchippedChoice.getItems().addAll("Yes","No");
  245. microchippedChoice.getSelectionModel().select(0);
  246. pane.add(microchippedChoice, 1, 9);
  247.  
  248. Label phoneNumber = new Label("phone number: ");
  249. phoneNumber.setFont(new Font("Times New Roman",17));
  250. pane.add(phoneNumber, 0, 10);
  251. TextField phoneNumberText = new TextField();
  252. phoneNumberText.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  253. pane.add(phoneNumberText, 1 ,10);
  254.  
  255.  
  256. Label provider = new Label("provider: ");
  257. provider.setFont(new Font("Times New Roman",17));
  258. pane.add(provider, 0, 11);
  259. ChoiceBox<String> providerChoice= new ChoiceBox<>();
  260. providerChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  261. providerChoice.setStyle("-fx-background-color: WHITE");
  262. providerChoice.getItems().addAll("Metropcs","ATT","TMobile","Sprint","Cricket");
  263. providerChoice.getSelectionModel().select(0);
  264. pane.add(providerChoice, 1, 11);
  265.  
  266. save.setOnAction(e3->{
  267.  
  268. /////////////////////Save the information /////////////////////
  269.  
  270. String option = genderChoice.getValue().toString();
  271. String neutorSpayOption = neutorSpayChoice.getValue().toString();
  272. String breedOption = breedChoice.getValue().toString();
  273. String furColorOption = furColorChoice.getValue().toString();
  274. String providerOption = providerChoice.getValue().toString();
  275. String microchippedOption = microchippedChoice.getValue().toString();
  276. LocalDate value = datePicker.getValue();
  277. String breedSpecify = "";
  278. String furColorSpecify = "";
  279.  
  280.  
  281. if(!nameText.getText().trim().isEmpty()&&!option.trim().isEmpty() &&
  282. !neutorSpayOption.trim().isEmpty()&& !breedOption.trim().isEmpty()
  283. &&!furColorOption.trim().isEmpty()&& !microchippedOption.trim().isEmpty()
  284. &&value!=null&&!weightText.getText().trim().isEmpty()&&!heightText.getText().trim().isEmpty()
  285. &&!phoneNumberText.getText().trim().isEmpty()
  286. &&!providerOption.trim().isEmpty()
  287. ) {
  288.  
  289. ///////////////////// Specify when choose "Other" /////////////////////
  290.  
  291. if(breedOption.equalsIgnoreCase("Other") || breedOption.equalsIgnoreCase("Mixed")) {
  292. userInputSpeak.stop();
  293.  
  294.  
  295. TextInputDialog dialog = new TextInputDialog("Golden Retriever");
  296. dialog.setTitle("Specify breed");
  297. dialog.setHeaderText(null);
  298. dialog.setContentText("Please specify breed:");
  299. Optional<String> result = dialog.showAndWait();
  300. if(result.isPresent())
  301. breedSpecify = result.get();
  302.  
  303. }else {
  304. breedSpecify = breedOption;
  305. }
  306.  
  307. if(furColorOption.equalsIgnoreCase("Other")) {
  308. userInputSpeak.stop();
  309.  
  310. TextInputDialog dialog = new TextInputDialog("Brown");
  311. dialog.setTitle("Specify fur color");
  312. dialog.setHeaderText(null);
  313. dialog.setContentText("Please specify fur color:");
  314. Optional<String> result = dialog.showAndWait();
  315. if(result.isPresent())
  316. furColorSpecify = result.get();
  317.  
  318. }else {
  319. furColorSpecify = furColorOption;
  320.  
  321. }
  322.  
  323. /////////////////////Numerical validation /////////////////////
  324.  
  325. if(isValidWeight(weightText.getText())==false||isValidHeight(heightText.getText())==false) {
  326. userInputSpeak.stop();
  327. final URL properWOHUrl = getClass().getResource("properWeightOrHeight.mp3");
  328. final Media properWOHMedia = new Media(properWOHUrl.toString());
  329. properWeightOrHeight = new MediaPlayer(properWOHMedia);
  330. properWeightOrHeight.play();
  331. Alert alert = new Alert(AlertType.ERROR);
  332. alert.setTitle("Error!");
  333. alert.setContentText("Please enter the proper weight or height!");
  334. alert.showAndWait();
  335. properWeightOrHeight.stop();
  336.  
  337.  
  338. if(isValidWeight(weightText.getText())==false) {
  339. weightText.setText("");
  340. }
  341. if(isValidHeight(heightText.getText())==false) {
  342. heightText.setText("");
  343. }
  344. }
  345. if(isValidPhoneNumber(phoneNumberText.getText())==false) {
  346. userInputSpeak.stop();
  347. final URL phoneRe = getClass().getResource("properPhoneNumber.mp3");
  348. final Media phoneMe = new Media(phoneRe.toString());
  349. properPhoneNumber = new MediaPlayer(phoneMe);
  350. properPhoneNumber.play();
  351. Alert alert = new Alert(AlertType.ERROR);
  352. alert.setTitle("Error!");
  353. alert.setContentText("Please enter the proper phone number!");
  354. alert.showAndWait();
  355. properPhoneNumber.stop();
  356. phoneNumberText.setText("");
  357. }
  358.  
  359.  
  360. }
  361.  
  362.  
  363.  
  364. if(!weightText.getText().trim().isEmpty()&&!heightText.getText().trim().isEmpty()) {
  365. dog = new Dog(nameText.getText(),breedSpecify,option,
  366. furColorOption,Double.parseDouble(weightText.getText()),Double.parseDouble(heightText.getText()),
  367. value,convertToBoolean(neutorSpayOption),convertToBoolean(microchippedOption),phoneNumberText.getText(),providerOption);
  368. }
  369.  
  370.  
  371.  
  372. if(!weightText.getText().trim().isEmpty()&&!heightText.getText().trim().isEmpty()&&!option.trim().isEmpty()
  373. && !breedSpecify.trim().isEmpty() && !furColorSpecify.trim().isEmpty()
  374. && !neutorSpayOption.trim().isEmpty()
  375. && !microchippedOption.trim().isEmpty() && !nameText.getText().trim().isEmpty() &&
  376. !phoneNumberText.getText().trim().isEmpty()&& !providerOption.trim().isEmpty()
  377. && dogInformation.contains(dog)==false ) {
  378.  
  379.  
  380.  
  381.  
  382. dogInformation.add(dog);
  383.  
  384. /////////////////////Add the information to MySQL database /////////////////////
  385.  
  386. String url = "jdbc:mysql://localhost/cs3220stu55?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
  387. String username = "cs3220stu55";
  388. String password = "zWpa0NxR";
  389.  
  390. Connection conn;
  391.  
  392. try{
  393.  
  394. //STEP 2: Register JDBC driver
  395. Class.forName("com.mysql.cj.jdbc.Driver");
  396.  
  397. //STEP 3: Open a connection
  398.  
  399. conn = DriverManager.getConnection(url, username, password);
  400.  
  401. Statement statement = conn.createStatement() ;
  402. ResultSet resultset = statement.executeQuery("SELECT * FROM pet") ;
  403. while(resultset.next()){
  404. if(resultset.getString("name").equalsIgnoreCase(dog.getName())
  405. && resultset.getString("breed").equalsIgnoreCase(dog.getBreed())
  406. && resultset.getString("gender").equalsIgnoreCase(dog.getGender())
  407. && resultset.getString("furColor").equalsIgnoreCase(dog.getFurColor())
  408. && resultset.getDouble("weight") == dog.getWeight()
  409. && resultset.getDouble("height") == dog.getHeight()
  410. && resultset.getBoolean("neutorSpay") == dog.getNeuterSpay()
  411. && resultset.getBoolean("microchipped") == dog.getMicrochip()
  412. && resultset.getString("phoneNumber").equalsIgnoreCase(dog.getPhoneNumber())
  413. && resultset.getString("provider").equalsIgnoreCase(dog.getProvider())
  414.  
  415. ){
  416.  
  417. ///////////////////// for preventing duplicates added to the database /////////////////////
  418. unique = false;
  419. final URL entryExistedR = getClass().getResource("entryExisted.mp3");
  420. final Media entryExistedM = new Media(entryExistedR.toString());
  421. entryExisted = new MediaPlayer(entryExistedM);
  422. entryExisted.play();
  423. Alert alert = new Alert(AlertType.ERROR);
  424. alert.setTitle("Error!");
  425. alert.setContentText("Entry: " + dog.getName() + " already existed in our database!");
  426. alert.showAndWait();
  427. entryExisted.stop();
  428. weightText.clear();
  429. heightText.clear();
  430. nameText.clear();
  431. phoneNumberText.clear();
  432.  
  433. providerChoice.getSelectionModel().select(0);
  434. breedChoice.getSelectionModel().select(0);
  435. furColorChoice.getSelectionModel().select(0);
  436. neutorSpayChoice.getSelectionModel().select(0);
  437. microchippedChoice.getSelectionModel().select(0);
  438.  
  439. datePicker.setValue(null);
  440. unique = true;
  441. }
  442. }
  443. if(unique == true
  444. && !weightText.getText().trim().isEmpty()&&!heightText.getText().trim().isEmpty()) {
  445. String query = " insert into pet (name, breed,gender,furColor, weight, height,birthday, neutorSpay, microchipped, phoneNumber, provider)"
  446. + " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  447. PreparedStatement preparedStmt = conn.prepareStatement(query);
  448. preparedStmt.setString (1, nameText.getText());
  449. preparedStmt.setString (2, breedSpecify);
  450. preparedStmt.setString (3, option);
  451. preparedStmt.setString (4, furColorSpecify);
  452. preparedStmt.setDouble (5, Double.parseDouble(weightText.getText()));
  453. preparedStmt.setDouble (6, Double.parseDouble(heightText.getText()));
  454. preparedStmt.setDate (7, java.sql.Date.valueOf(value));
  455. preparedStmt.setBoolean(8, convertToBoolean(neutorSpayOption));
  456. preparedStmt.setBoolean(9, convertToBoolean(microchippedOption));
  457. preparedStmt.setString (10, phoneNumberText.getText());
  458. preparedStmt.setString (11, providerOption);
  459.  
  460.  
  461.  
  462.  
  463. // execute the preparedstatement
  464. preparedStmt.execute();
  465.  
  466. conn.close();
  467.  
  468. userInputSpeak.stop();
  469.  
  470. /////////////////////information saved /////////////////////
  471.  
  472. final URL resource3 = getClass().getResource("informationSaved.mp3");
  473. final Media media3 = new Media(resource3.toString());
  474. informationSaved = new MediaPlayer(media3);
  475. informationSaved.play();
  476. Alert alert1 = new Alert(AlertType.INFORMATION);
  477. alert1.setTitle("Saved");
  478. alert1.setContentText(dog.getName() + "' Information saved!");
  479. alert1.showAndWait();
  480. informationSaved.stop();
  481.  
  482.  
  483. }
  484. }catch(SQLException se) {
  485. se.printStackTrace();
  486. } catch (ClassNotFoundException e2) {
  487. e2.printStackTrace();
  488. }
  489.  
  490.  
  491. }
  492.  
  493. if(nameText.getText()==null || nameText.getText().trim().isEmpty()
  494. ||breedSpecify==null || breedSpecify.trim().isEmpty()
  495. ||option==null || option.trim().isEmpty()
  496. ||furColorChoice.getValue().toString()==null || furColorChoice.getValue().toString().trim().isEmpty()
  497. ||weightText.getText()==null || weightText.getText().trim().isEmpty()
  498. ||heightText.getText()==null || heightText.getText().trim().isEmpty()
  499. ||value == null
  500. ||neutorSpayOption==null || neutorSpayOption.trim().isEmpty()
  501. ||microchippedOption==null || microchippedOption.trim().isEmpty()
  502. || phoneNumberText.getText().trim().isEmpty() || phoneNumberText.getText() == null ||
  503. providerOption.trim().isEmpty()|| providerOption==null
  504. ) {
  505.  
  506.  
  507. userInputSpeak.stop();
  508. final URL resource5 = getClass().getResource("error.mp3");
  509. final Media media5 = new Media(resource5.toString());
  510. error = new MediaPlayer(media5);
  511. error.play();
  512. Alert alert = new Alert(AlertType.ERROR);
  513. alert.setTitle("Error!");
  514. alert.setContentText("Please fill in all the fields!!");
  515. alert.showAndWait();
  516. error.stop();
  517.  
  518.  
  519.  
  520.  
  521.  
  522. }
  523. else{
  524.  
  525.  
  526. }
  527. });
  528.  
  529.  
  530. backToPrimary.setOnAction(event->{
  531. secondaryStage.close();
  532. primaryStage.show();
  533. userInputSpeak.stop();
  534. welcomeMessage.play();
  535. });
  536.  
  537.  
  538. proceed.setOnAction(e1->{
  539.  
  540. /////////////////////proceed only works after saved /////////////////////
  541.  
  542. if(nameText.getText()==null || nameText.getText().trim().isEmpty()
  543. ||breedChoice.getValue()==null || breedChoice.getValue().toString().trim().isEmpty()
  544. ||genderChoice.getValue().toString()==null || genderChoice.getValue().toString().trim().isEmpty()
  545. ||furColorChoice.getValue().toString()==null || furColorChoice.getValue().toString().trim().isEmpty()
  546. ||weightText.getText()==null || weightText.getText().trim().isEmpty()
  547. ||heightText.getText()==null || heightText.getText().trim().isEmpty()
  548. || datePicker.getValue() == null
  549. ||neutorSpayChoice.getValue().toString()==null || neutorSpayChoice.getValue().toString().trim().isEmpty()
  550. ||microchippedChoice.getValue().toString()==null || microchippedChoice.getValue().toString().trim().isEmpty()
  551. ||phoneNumberText.getText().trim().isEmpty()||phoneNumberText.getText()==null
  552. ||providerChoice.getValue().toString().trim().isEmpty() || providerChoice.getValue().toString()==null
  553. ) {
  554.  
  555.  
  556. userInputSpeak.stop();
  557. final URL resource5 = getClass().getResource("error.mp3");
  558. final Media media5 = new Media(resource5.toString());
  559. error = new MediaPlayer(media5);
  560. error.play();
  561. Alert alert = new Alert(AlertType.ERROR);
  562. alert.setTitle("Error!");
  563. alert.setContentText("Please fill in all the fields!!");
  564. alert.showAndWait();
  565. error.stop();
  566. // userInputSpeak.play();
  567.  
  568.  
  569.  
  570.  
  571.  
  572. }
  573.  
  574. /////////////////////ArrayList dogInformation only add entries when save button is pressed /////////////////////
  575.  
  576. else if(dogInformation.isEmpty()) {
  577.  
  578. userInputSpeak.stop();
  579. final URL resource6 = getClass().getResource("saveAlert.mp3");
  580. final Media media6 = new Media(resource6.toString());
  581. saved = new MediaPlayer(media6);
  582. saved.play();
  583. Alert alert = new Alert(AlertType.ERROR);
  584. alert.setTitle("Error!");
  585. alert.setContentText("Please save the information to proceed!!");
  586. alert.showAndWait();
  587. }
  588. else {
  589.  
  590. userInputSpeak.stop();
  591.  
  592. final URL resource4 = getClass().getResource("ready.mp3");
  593. final Media media4 = new Media(resource4.toString());
  594. readyed = new MediaPlayer(media4);
  595. readyed.play();
  596. secondaryStage.close();
  597. Stage tertiaryStage = new Stage();
  598. GridPane gridPane = new GridPane();
  599. gridPane.setAlignment(Pos.CENTER);
  600. gridPane.setHgap(10);
  601. gridPane.setVgap(10);
  602. gridPane.setPadding(new Insets(25, 25, 25, 25));
  603. Label message = new Label("Are you ready for the ADH? ");
  604. message.setFont(new Font("Times New Roman", 30));
  605. Image image = new Image("cuteDoggy.gif");
  606. ImageView imageView = new ImageView();
  607. imageView.setImage(image);
  608. imageView.setFitHeight(150);
  609. imageView.setFitWidth(90);
  610. message.setGraphic(imageView);
  611. gridPane.add(message, 0, 1);
  612.  
  613.  
  614. ready.setOnAction(e2->{
  615. welcomeBGM.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