0

Using JavaFX, I have the user input information into text fields. My MainController class allows the user to save that inputted text to a txt file and save it at a given location.

Im wondering if its possible to pass what was entered in that text file into another class so I can parse and have my program use its data.

I used strings and .getText() then used a filewriter and bufferedWriter. Can I get the .getText input into another class?

Chris
  • 9
  • 5
  • Yes. Why do you think this is not possible? What kind of issues do you expect? If you're asking about fxml in particular your question is a duplicate of this one: https://stackoverflow.com/questions/14187963/passing-parameters-javafx-fxml – fabian Nov 14 '17 at 17:27

2 Answers2

0

If your class is public than yes,you can use it in any class in your application;

  • public void Button2Action(ActionEvent event) throws IOException { String name1 = name.getText(); For example. And my other class is employee.java Sorry, been trying to figure this out – Chris Nov 14 '17 at 01:47
  • when you create a class ,if it has no errors ,its the same as the other built in classes ,you can use them anywhere ,and create objects in other classes –  Nov 14 '17 at 01:50
0

You should research for Java - Access Modifiers

but as an ideia,

public class MainController {

    private String savedFilePath;

    public String getSavedFilePath() {
        return savedFilePath;
    }

    public void setSavedFilePath(String savedFilePath) {
        this.savedFilePath = savedFilePath;
    }
}

and from the other class, when you save the file you can call:

MainController controller = new MainController();
controller.setSavedFilePath("file path");

If you don't want to create a new object MainController, you can define the savedFilePath as static

public class MainController {

    private static String savedFilePath;

    public static void setSavedFilePath(String paramSavedFilePath) {
        savedFilePath = paramSavedFilePath;
    }
}

and just call:

MainController.setSavedFilePath("file path");
Gus
  • 403
  • 7
  • 14