Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Name: Lu Liu
- * Date: 5/10/2016
- * Course Number: CSC-112
- * Course Name: Intermediate Topics in Java Programming
- * Email: lliu0001@student.stcc.edu
- *
- * Assignment: HW # 17
- * Programe Description:
- * A Zip code to City/State Translator Database GUI
- */
- import java.util.Scanner;
- import javafx.application.Application;
- import javafx.geometry.Insets;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.TextArea;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.BorderPane;
- import javafx.scene.layout.HBox;
- import javafx.scene.paint.Color;
- import javafx.scene.shape.Line;
- import javafx.stage.Stage;
- public class ZipCodeTranslationGUI extends Application {
- public void start(Stage primaryStage) {
- // Create pane to hold the label and text field
- HBox hBox = new HBox(10);
- TextField tfZipCode = new TextField();
- tfZipCode.setAlignment(Pos.CENTER_LEFT);
- TextField tfCITY = new TextField();
- tfCITY.setAlignment(Pos.CENTER_LEFT);
- TextField tfSTATE = new TextField();
- tfSTATE.setAlignment(Pos.CENTER_LEFT);
- Button bnToCity = new Button("Zip to City");
- hBox.setPadding(new Insets(5, 15, 25, 5));
- hBox.getChildren().addAll(new Label("Zip Code:"), tfZipCode, bnToCity, new Label("City:"), tfCITY,
- new Label("State:"), tfSTATE);
- HBox hBox2 = new HBox(10);
- hBox2.setPadding(new Insets(5, 15, 25, 5));
- TextField tfCity = new TextField();
- tfCity.setAlignment(Pos.CENTER_LEFT);
- TextField tfState = new TextField();
- tfState.setAlignment(Pos.CENTER_LEFT);
- Button bnToZip = new Button("City to Zip");
- TextArea ta = new TextArea();
- ta.setMaxSize(130, 130);
- ta.setText("Zip Codes");
- hBox2.getChildren().addAll(new Label("City:"), tfCity, new Label("State:"), tfState, bnToZip, ta);
- Line line1 = new Line(10, 10, 750, 10);
- line1.setStrokeWidth(3);
- line1.setStroke(Color.WHITE);
- BorderPane centerPane = new BorderPane();
- centerPane.setTop(line1);
- centerPane.setCenter(hBox2);
- HBox hBox3 = new HBox(10);
- hBox3.setPadding(new Insets(5, 15, 25, 80));
- TextField tfStatus = new TextField();
- tfStatus.setMinSize(510, 20);
- tfStatus.setAlignment(Pos.CENTER);
- hBox3.getChildren().addAll(new Label("Status:"), tfStatus);
- Line line2 = new Line(10, 200, 750, 200);
- line2.setStrokeWidth(3);
- line2.setStroke(Color.WHITE);
- BorderPane bottomPane = new BorderPane();
- bottomPane.setCenter(hBox3);
- bottomPane.setTop(line2);
- // Create pane to hold the panefor all
- BorderPane mainPane = new BorderPane();
- mainPane.setPadding(new Insets(25, 5, 5, 5));
- mainPane.setStyle("-fx-background-color: #D3D3D3;");
- mainPane.setTop(hBox);
- mainPane.setCenter(centerPane);
- mainPane.setBottom(bottomPane);
- // catch the invalid input
- bnToCity.setOnAction(e -> {
- try {
- int zipCode = Integer.parseInt(tfZipCode.getText());
- if (tfZipCode.getText().length() == 5) {
- tfStatus.setText("Valid Zip Code");
- } else {
- tfStatus.setText("The ZIP Code must be 5 digits integer");
- }
- } catch (Exception ex) {
- tfStatus.setText("The ZIP Code must be 5 digits integer");
- }
- // bnToCity.fire();
- });
- // Create a scene and place it in the stage
- Scene scene = new Scene(mainPane, 760, 300);
- primaryStage.setTitle("Zip Code Translation System"); // Set the stage
- primaryStage.setScene(scene); // Place the scene in the stage
- primaryStage.show(); // Display the stage
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement