Skip to content

Muhammed-als/exercise-main

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lesson 2: Exercise, Search And Replace

From ordinary exam, VOP F15.

Task 1 - Search and Replace

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.

  1. Add the following components to your scene:

    • A Label and a TextField for the text you will be searching for
    • A Label and a TextField for the text you will be replacing it with.
    • A TextArea for showcasing the text you will be search-and-replacing in
    • A Button for implementing the Replace All functionality.
  2. Program an actionHandler for the button, so every occurrence of the text in the “search”-field will be replaced by the text in the “replace”-field

Final stage at end of assignment a

Your stage should look like this at the end of Task 1

Task 2 - Simple File-I/O

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”

  1. Create a FileChooser instance-variable.
  2. Initialize the FileChooser, in the FXMLController’s initialize()-method and set the InitialDirectory to the project folder (new File(".")), as follows fileChooser.setInitialDirectory(new File("."))
  3. Add 2 buttons to your scene, “Open file” and “Save as".
  4. Create an ActionHandler for the ”Open file”-button which uses the FileChooser, to select the desired file as follows: File inFile = fileChooser.showOpenDialog(null); Read the content of the inFile and load into the TextArea.
  5. Create an ActionHandler for the “Save as”-button, which uses the FileChooser, to pick an existing file, or creating a new file, as follows: File outFile = fileChooser.showSaveDialog(null); The content of the TextArea,should be written in the outFile.

Example of the final stage visible below:

Final stage at end of assignment b

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”.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages