Question

Intro to Java - Assignment JAVA ASSIGNMENT 13 - Object Methods During Event Handling Assignment 13...

Intro to Java - Assignment

JAVA ASSIGNMENT 13 - Object Methods During Event Handling
Assignment 13
Assignment 13 Preparation

This assignment will focus on the use of object methods during event handling.

Assignment 13
Assignment 13 Submission


Follow the directions below to submit Assignment 13:

This assignment will be a modification of the Assignment 12 program (see EncryptionApplication11.java below).

Replace the use of String concatenation operations in the methods with StringBuilder or StringBuffer objects and their methods.

EncryptTextMethods.java
======================
package Utils;
import java.util.Scanner;
public class EncryptTextMethods {
public static String encryptString(String message) {
//convert string to character array
char stringChars[] = message.toCharArray();
//for each character
for(int i=0; i< stringChars.length; i++) {
char ch = stringChars[i];
//if character within range of alphabet
if(ch <= 'z' && ch >= 'a') {
stringChars[i] = (char)('a' + ((int)(ch - 'a') + 1) % 26 );
}
}
//construct the string message
return String.valueOf(stringChars);
}
public static String decryptString(String message) {
//convert string to character array
char stringChars[] = message.toCharArray();
//for each character
for(int i=0; i< stringChars.length; i++) {
char ch = stringChars[i];
//if character within range of alphabet
if(ch <= 'z' && ch >= 'a') {
stringChars[i] = (char)('a' + ((int)(ch - 'a') - 1) % 26 );
}
}
//construct the string message
return String.valueOf(stringChars);
}
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter text to encrypt: ");
String message = keyboard.nextLine();
message = message.toLowerCase();
String encryptedStr = encryptString(message);
System.out.println("Encrypted String: " + encryptedStr);
String decryptedStr =decryptString(encryptedStr);
System.out.println("Decrypted String : " + decryptedStr);
keyboard.close();
}
}

EncryptionApplication11.java   (this is Assignment 12)
============================


package Utils;
import javafx.application.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.*;
public class EncryptionApplication11 extends Application {
public void start(Stage primaryStage) {
// 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);
TextArea inputTextArea=new TextArea();
inputTextArea.setPromptText("Input text here");
pane.add(inputTextArea, 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);
Button encryptButton = new Button("Encrypt");
Button clearButton = new Button("Clear");
Button decryptButton = new Button("Decrypt");
btnPane.getChildren().addAll(encryptButton, clearButton, decryptButton);
pane.add(btnPane, 0, 2);
// Place nodes in the GridPane pane
pane.add(new Label("Output Text:"), 0, 3);
TextArea outputTextArea=new TextArea("");
outputTextArea.setPromptText("Output text here");
pane.add(outputTextArea, 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();
// Buttons events
encryptButton.addEventHandler(ActionEvent.ACTION, new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
String text = inputTextArea.getText();
if(text != null && !text.trim().equals(""))
outputTextArea.setText(EncryptTextMethods.encryptString(text.trim()));
}});
clearButton.addEventHandler(ActionEvent.ACTION, new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
inputTextArea.clear();
outputTextArea.clear();
}
});
decryptButton.addEventHandler(ActionEvent.ACTION, new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
String text = inputTextArea.getText();
if(text != null && !text.trim().equals(""))
outputTextArea.setText(EncryptTextMethods.decryptString(text.trim()));
}});
}
/**
* 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);
}
}

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Intro to Java - Assignment JAVA ASSIGNMENT 13 - Object Methods During Event Handling Assignment 13...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Java Programming Assignment (JavaFX required). You will modify the SudokuCheckApplication program that is listed below. Start...

    Java Programming Assignment (JavaFX required). You will modify the SudokuCheckApplication program that is listed below. Start with the bolded comment section in the code below. Create a class that will take string input and process it as a multidimensional array You will modify the program to use a multi-dimensional array to check the input text. SudokuCheckApplication.java 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 SudokuCheckApplication extends Application { public void start(Stage primaryStage)...

  • Please Help, JavaFX assignment. This assignment will focus on the use anonymous inner class handlers to...

    Please Help, JavaFX assignment. This assignment will focus on the use anonymous inner class handlers to implement event handling. Assignment 12 Assignment 12 Submission Follow the directions below to submit Assignment 12: This assignment will be a modification of the Assignment 11 program. This program should use the controls and layouts from the previous assignment. No controls or layouts should be added or removed for this assignment. Add event handlers for the three buttons. The event handlers should be implemented...

  • (5 points) Analyze the following codes. b) import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import...

    (5 points) Analyze the following codes. b) import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.HBox; import javafx.stage.Stage; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { Button btOK = new Button("OK"); Button btCancel = new Button("Cancel"); EventHandler<ActionEvent> handler = new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("The OK button is clicked"); } }; btOK.setOnAction(handler); btCancel.setOnAction(handler); HBox pane = new HBox(5); pane.getChildren().addAll(btOK, btCancel); Scene...

  • Using JAVA FX how would I combine the two programs below into one interface that allows...

    Using JAVA FX how would I combine the two programs below into one interface that allows the user to pick which specific program they would like to play. They should be able to choose which one they want to play and then switch between them if necesary. All of this must be done in JAVA FX code Black jack javafx - first game program package application; import java.util.Arrays; import java.util.ArrayList; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.application.Application; import javafx.geometry.Pos; import javafx.geometry.Insets;...

  • use this code of converting Km to miles , to create Temperature converter by using java...

    use this code of converting Km to miles , to create Temperature converter by using java FX import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.geometry.Pos; import javafx.geometry.Insets; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.control.Button; import javafx.event.EventHandler; import javafx.event.ActionEvent; /** * Kilometer Converter application */ public class KiloConverter extends Application { // Fields private TextField kiloTextField; private Label resultLabel; public static void main(String[] args) { // Launch the application. launch(args); } @Override public void start(Stage primaryStage) { //...

  • For this question you will need to complete the methods to create a JavaFX GUI application...

    For this question you will need to complete the methods to create a JavaFX GUI application that implements two String analysis algorithms. Each algorithm is activated when its associated button is pressed. They both take their input from the text typed by the user in a TextField and they both display their output via a Text component at the bottom of the GUI, which is initialized to “Choose a string methods as indicated in the partially completed class shown after...

  • I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label;...

    I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label; import java.awt.TextArea; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Fall_2017 {    public TextArea courseInput;    public Label textAreaLabel;    public JButton addData;    public Dialog confirmDialog;    HashMap<Integer, ArrayList<String>> students;    public Fall_2017(){    courseInput = new TextArea(20, 40);    textAreaLabel = new Label("Student's data:");    addData = new JButton("Add...

  • The JavaFX framework provides more than one way to handle events. For event handlers, we could...

    The JavaFX framework provides more than one way to handle events. For event handlers, we could use inner classes, anonymous inner classes, or the new Java 8 feature of lambda expressions. In this discussion, you will explore these different ways of writing event handles in JavaFX. To prepare for this discussion, you must unzip the attached NetBeans project zip file (U4D1_HandleEvents.zip) and load it into your NetBeans IDE. The project uses an inner class to handle the click event on...

  • JAVA SOLUTION This lab has four parts: Create a window. Create 5 buttons in that window....

    JAVA SOLUTION This lab has four parts: Create a window. Create 5 buttons in that window. Create an event when a button is pushed. Create an event listener that will respond to the button being pushed event. Task 1 – Create a Window For Java: Please ensure that the following import statements are used: import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.GridPane; import javafx.scene.text.Text; import javafx.event.EventHandler; import javafx.scene.input.MouseEvent; Next, ensure that there is a main method which is...

  • I tried to add exception handling to my program so that when the user puts in...

    I tried to add exception handling to my program so that when the user puts in an amount of change that is not the integer data type, the code will catch it and tell them to try again, but my try/catch isnt working. I'm not sure how to fix this problem. JAVA code pls package Chapter9; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class GUIlab extends JFrame implements ActionListener {    private static final int WIDTH = 300;    private...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT