From ordinary exam, VOP F15.
You will be working with the following file(s) for this exercise: FXMLController.java, Primary.FXML
Purpose: Using JavaFX to create a GUI application with search and replace functionality.
-
Add the following components to your scene:
- A
Labeland aTextFieldfor the text you will be searching for - A
Labeland aTextFieldfor the text you will be replacing it with. - A
TextAreafor showcasing the text you will be search-and-replacing in - A
Buttonfor implementing the Replace All functionality.
- A
-
Program an
actionHandlerfor the button, so every occurrence of the text in the “search”-field will be replaced by the text in the “replace”-field
Your stage should look like this at the end of Task 1
Purpose: To be able to load the text you wish to use the search-and-replace functionality from a file and saving the altered text in another file.
You will be working with the following file(s) for this assignment: FXMLController.java, Primary.FXML, ”HelloWorld.txt”
- Create a FileChooser instance-variable.
- Initialize the FileChooser, in the FXMLController’s
initialize()-method and set theInitialDirectoryto the project folder(new File(".")), as followsfileChooser.setInitialDirectory(new File(".")) - Add 2 buttons to your scene, “Open file” and “Save as".
- Create an
ActionHandlerfor the ”Open file”-button which uses theFileChooser, to select the desired file as follows:File inFile = fileChooser.showOpenDialog(null);Read the content of the inFile and load into theTextArea. - Create an
ActionHandlerfor the “Save as”-button, which uses theFileChooser, to pick an existing file, or creating a new file, as follows:File outFile = fileChooser.showSaveDialog(null);The content of theTextArea,should be written in the outFile.
Example of the final stage visible below:
In this example ”HelloWorld.txt” has been loaded. (found in the root of the project folder), all occurrences of the word ”World” has been changed to ”Moon” and the result has been saved to ”HelloMoon.txt”.

