Question
In Java application create a TextArea (the word processing window) where the user can type any string of text two TextFields allow the user to
In Java application create a TextArea (the word processing window) where the user can type any string of text two TextFields allow the user to type the find string and the replace string. Buttons are the Find button and the Replace button. Create event handlers that respond to the two buttons. If the user clicks the Find button, use string manipulation techniques to determine if the find substring is located within the word processing string. If this is determined to be true, display the location (index) of the find substring within the string in a showMessageDialog(). Otherwise display an error message. If the user instead clicks the Replace button, use string manipulation to determine if the find substring is located within the word processing string. If this is true, use the contents of the replace string TextField to replace the found string within the TextArea. If the find string is not found within the TextArea, show an error message in a showMessageDialog().Both buttons in this application begin by looking for the find substring within the TextArea and display an error message in a showMessageDialog() if it is not present. In one way or another, implement this task in your application so that it is coded just once.
create and use for all the event processing above a programmed-defined class FindAndReplace with two String instance variables initialString and findString. The constructor takes two String parameters (get the values from the TextArea and the find TextField) and assigns them to the two instance variables. class methods are: Set methods for the two instance variables which also are called by the constructor (create and implement an exception class EmptyStringException that extends from the Java API class Exception to validate both fields) Get methods for the two instance variables. A method findString() of type int that performs the find processing from above and returns the index of the find substring within the initial string, or a default value -1. A method replaceString() of type String that performs the replace processing from above and returns an updated string with the find string substituted in the initial string (this method uses the method findString to validate that the find string is located within the initial string)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started