daily pastebin goal
27%
SHARE
TWEET

Gui for mySQL

rjsantiago0001 May 7th, 2016 (edited) 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // Ricardo Santiago
  3. // 5/06/16
  4. // CSCI-112
  5. // Gui for mySQL
  6.  
  7. import javafx.application.Application;
  8. import javafx.geometry.Insets;
  9. import javafx.geometry.Pos;
  10. import javafx.scene.Scene;
  11. import javafx.scene.control.Button;
  12. import javafx.scene.control.Label;
  13. import javafx.scene.control.TextArea;
  14. import javafx.scene.control.TextField;
  15. import javafx.scene.layout.BorderPane;
  16. import javafx.scene.layout.FlowPane;
  17. import javafx.scene.shape.Line;
  18. import javafx.stage.Stage;
  19. import java.util.regex.Pattern;
  20.  
  21. public class Gui extends Application {
  22.  
  23.     private TextField tfZip;
  24.     private TextArea taCity;
  25.     private TextArea taState;
  26.     private TextField tfCity;
  27.     private Button btnZipToCity;
  28.     private Button btnCityToZip;
  29.     private TextField tfState;
  30.     private TextArea statusBody;
  31.     private TextArea zipBody;
  32.     private static String temp;
  33.     static final String regexForZip = "^\\d{5}$";
  34.     static final String regexForCity = "^[a-zA-Z]+(?:[\\s-][a-zA-Z]+)*$";
  35.     static final String regexForState = "^[A-Z]{2}$";
  36.    
  37.     private static final String DATABASE = "silvestri";
  38.     private static final String USERNAME = "readonly";
  39.     private static final String PASSWORD = "readonly";
  40.  
  41.     static String driver = "com.mysql.jdbc.Driver";
  42.     static String url = "jdbc:mysql://cs.stcc.edu/" + DATABASE +
  43.                         "?user=" + USERNAME + "&password=" + PASSWORD;
  44.  
  45.     public void start(Stage primaryStage) {
  46.  
  47.         FlowPane tPane = new FlowPane(5, 5);
  48.         tPane.setAlignment(Pos.CENTER);
  49.         tPane.setPadding(new Insets(10, 10, 10, 10));
  50.         tPane.setHgap(10);
  51.         tfZip = new TextField();
  52.         tfZip.setPrefColumnCount(5);
  53.         btnZipToCity = new Button("Zip To City");
  54.         taCity = new TextArea();
  55.         taCity.setPrefColumnCount(13);
  56.         taCity.setPrefRowCount(1);
  57.         taCity.setEditable(false);
  58.         taState = new TextArea();
  59.         taState.setPrefColumnCount(3);
  60.         taState.setPrefRowCount(1);
  61.         taState.setEditable(false);
  62.  
  63.         Label lblZip = new Label("Zip Code:");
  64.         lblZip.setStyle("-fx-font-weight: bold; -fx-font-size: 12pt");
  65.         Label lblCity1 = new Label("City:");
  66.         lblCity1.setStyle("-fx-font-weight: bold; -fx-font-size: 12pt");
  67.         Label lblState1 = new Label("State:");
  68.         lblState1.setStyle("-fx-font-weight: bold; -fx-font-size: 12pt");
  69.         Line sepLine1 = new Line(10, 340, 600, 340);
  70.         tPane.getChildren().addAll(lblZip, tfZip, btnZipToCity, lblCity1, taCity, lblState1, taState, sepLine1);
  71.  
  72.         FlowPane cPane = new FlowPane(5, 5);
  73.         cPane.setAlignment(Pos.CENTER);
  74.         cPane.setPadding(new Insets(10, 10, 10, 10));
  75.         cPane.setHgap(10);
  76.         tfCity = new TextField();
  77.         tfCity.setPrefColumnCount(13);
  78.         btnCityToZip = new Button("City to Zip");
  79.         tfState = new TextField();
  80.         tfState.setPrefSize(50, 20);
  81.  
  82.         tfState.setText("  ");
  83.         tfState.setText(tfState.getText().substring(0, 2));
  84.         Label lblCity2 = new Label("City:");
  85.         lblCity2.setStyle("-fx-font-weight: bold; -fx-font-size: 12pt");
  86.         Label lblState2 = new Label("State:");
  87.         lblState2.setStyle("-fx-font-weight: bold; -fx-font-size: 12pt");
  88.         zipBody = new TextArea();
  89.         zipBody.setPrefColumnCount(9);
  90.         zipBody.setPrefRowCount(6);
  91.         zipBody.setText("Zip Code(s)");
  92.         zipBody.setEditable(false);
  93.         cPane.getChildren().addAll(lblCity2, tfCity, lblState2, tfState, btnCityToZip, zipBody);
  94.  
  95.         FlowPane bPane = new FlowPane(5, 5);
  96.         bPane.setAlignment(Pos.CENTER);
  97.         bPane.setPadding(new Insets(5, 5, 5, 5));
  98.         Line sepLine2 = new Line(10, 340, 600, 340);
  99.         Label lblStatus = new Label("Status:");
  100.         lblStatus.setStyle("-fx-font-weight: bold; -fx-font-size: 12pt");
  101.         statusBody = new TextArea();
  102.         statusBody.setPrefColumnCount(30);
  103.         statusBody.setPrefRowCount(1);
  104.         statusBody.setEditable(false);
  105.        
  106.         bPane.getChildren().addAll(sepLine2, lblStatus, statusBody);
  107.  
  108.         BorderPane bp = new BorderPane();
  109.         bp.setTop(tPane);
  110.         bp.setCenter(cPane);
  111.         bp.setBottom(bPane);
  112.         bp.setStyle("-fx-border-color: Black;");
  113.  
  114.         btnZipToCity.setOnAction(e -> {
  115.  
  116.             statusBody.setText(null);
  117.  
  118.             String strZip;
  119.  
  120.             temp = tfZip.getText();
  121.             strZip = temp.trim();
  122.  
  123.             if (isValidZip(strZip) == false) {
  124.  
  125.                 statusBody.setText("ERROR: Zipcode input is not valid, must be 5 consecutive digits.");
  126.                 statusBody.setStyle("-fx-font-weight: bold; -fx-text-fill:red");
  127.             }
  128.             else{
  129.                 statusBody.setText("SUCCESS!!! Zipcode input is valid.");
  130.                 statusBody.setStyle("-fx-font-weight: bold; -fx-text-fill: green");
  131.             }
  132.         });
  133.  
  134.         btnCityToZip.setOnAction(e -> {
  135.  
  136.             statusBody.setText(null);
  137.  
  138.             String strCity;
  139.             String strState;
  140.  
  141.             temp = tfCity.getText();
  142.             strCity = temp.trim();
  143.             temp = tfState.getText();
  144.             strState = temp.trim();
  145.  
  146.             if (strCity.length() > 25 || isValidCity(strCity) == false) {
  147.                 statusBody.setText("City input is not valid, or exceeds 25 characters.");
  148.                 statusBody.setStyle("-fx-font-weight: bold; -fx-text-fill:red");
  149.             }
  150.  
  151.             else if (isValidState(strState) == false) {
  152.                 statusBody.setText("State input is not valid, or exceeds 2 characters.");
  153.                 statusBody.setStyle("-fx-font-weight: bold; -fx-text-fill:red");
  154.             }
  155.            
  156.             else {
  157.                 statusBody.setText("SUCCESS!!! City/State input is valid.");
  158.                 statusBody.setStyle("-fx-font-weight: bold; -fx-text-fill:green");
  159.            
  160.             }
  161.  
  162.         });
  163.  
  164.         Scene scene = new Scene(bp, 620, 250);
  165.         primaryStage.setTitle("Query Zip Codes Application");
  166.  
  167.         primaryStage.setScene(scene);
  168.         primaryStage.show();
  169.         primaryStage.setResizable(false);
  170.  
  171.     }
  172.  
  173.     public static void main(String[] args) {
  174.         Application.launch(args);
  175.     }
  176.  
  177.     public static boolean isValidZip(String zip) {
  178.         return Pattern.matches(regexForZip, zip);
  179.     }
  180.  
  181.     public static boolean isValidCity(String city) {
  182.         return Pattern.matches(regexForCity, city);
  183.     }
  184.  
  185.     public static boolean isValidState(String state) {
  186.         return Pattern.matches(regexForState, state);
  187.     }
  188.  
  189. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand