/* Title: Chapter 13 Assignment Name: Joseph Schuman Date: 4/14/2015 Description: Uses JavaFX to create an Encryption Application form. Creates action event handlers for the three buttons that call the requested method. */ import javafx.application.*; import javafx.event.*; import javafx.geometry.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.*; public class EncryptApplication extends Application { public void start(Stage primaryStage) { // Create addressable controls // Reachable from the event handlers TextArea taInput = new TextArea("Input text here"); TextArea taOutput = new TextArea("Output Text:"); // Create the GridPane pane GridPane pane = new GridPane(); pane.setPadding(new Insets(10, 10, 10, 10)); pane.setVgap(5); // Place nodes in the GridPane pane pane.add(new Label("Input Text:"), 0, 0); pane.add(taInput, 0, 1); // Create FlowPane pane FlowPane btnPane = new FlowPane(); btnPane.setAlignment(Pos.CENTER); pane.setHgap(5); // Place nodes in the FlowPane pane and place // pane in the GridPane pane btnPane.setPadding(new Insets(10, 10, 10, 10)); btnPane.setHgap(10); // Create buttons // Encrypt Button Button btnEncrypt = new Button("Encrypt"); // Clear Button Button btnClear = new Button("Clear"); btnClear.setOnAction(new EventHandler() { public void handle(ActionEvent e) { taInput.setText(""); taOutput.setText(""); } }); // Decrypt Button Button btnDecrypt = new Button("Decrypt"); // Place Buttons on the FlowPane and place FlowPane on GridPane btnPane.getChildren().addAll(btnEncrypt, btnClear, btnDecrypt); pane.add(btnPane, 0, 2); // Place nodes in the GridPane pane pane.add(new Label("Output Text:"), 0, 3); pane.add(taOutput, 0, 4); //Create scene and place it on the stage Scene scene = new Scene(pane); primaryStage.setTitle("CPT 236 Encryption Application"); primaryStage.setScene(scene); primaryStage.show(); //Action event handler for decrypt button; Decryption handler class. btnEncrypt.setOnAction(new EventHandler() { @Override //Override the event handler. public void handle(ActionEvent e) { MiscString strObj = new MiscString(taInput.getText()); taOutput.setText(strObj.encryptMiscString()); } }); //Action event for the encrypt button; Decryption handler class. btnDecrypt.setOnAction(new EventHandler() { @Override //Override the event handler. public void handle(ActionEvent e) { MiscString strObj = new MiscString(taInput.getText()); taOutput.setText(strObj.decryptMiscString()); } }); } /** * The main method is only needed for the IDE with limited * JavaFX support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } /* Name: Joseph Schuman Date: 4/14/2015 File: Chapter 13 Assignment, AnyString Descripetion: Superclass that is inherited to the MiscString class. */ public class AnyString { // private variable hidden from user protected String str; // Constructor method - sets the object variable to // the string passed to it public AnyString(String s) { str = new String(s); } // Constructor method - sets the object variable to // the character array passed to it public AnyString(char[] chArray) { str = new String(chArray); } // Method to get the value of the string // and return to the caller public String getString() { return str; } // Returns of length of the object variable public int getLength() { return str.length(); } // Return the string value public String toString() { return str; } // Returns boolean value based on two objects // being equal public boolean equals(MiscString s) { return str.equals(s.getString()); } } /* Name: Joseph Schuman Date: 4/14/2015 File: Chapter 13 Assignment, MiscString Descripetion: Contains code to manipulate a string and check to see if a string is all characters, numbers, and equals to a certain string. Shares abstract class with AnyString class. *Added encryptMiscString and decryptMiscString methods to handle action events in EncryptionApplication. */ public class MiscString extends AnyString { // Constructor method - sets the object variable to // the string passed to it public MiscString(String s) { super(s); } // Constructor method - sets the object variable to // the character array passed to it public MiscString(char[] chArray) { super(chArray); } // Returns a lowercase string value public String toLowerCase() { return str.toLowerCase(); } // Returns a uppercase string value public String toUpperCase() { return str.toUpperCase(); } // Object/Instance method to determine if the object is a // palindrome public boolean checkPalindrome() { // Convert to lowercase for testing - create resultString // to hold all the letters detected in lowerString String lowerString = str.toLowerCase(); String resultString = ""; // If letter found store it in resultString for(int i=0; i