Hi all, I have just started learning JavaFX and I have some questions.
Hi everyone, I have 2 GUIs, main and edit gui, in which I am trying to pass this Person object from the edit gui to the main gui.
In my main gui, it has this Edit Person button, which calls for the edit gui as follows:
public class EditGui { private static Stage window; private static Person currentPers; private static Button saveBtn; public static void display(String msg, Person persObj) { currentPers = persObj; // Creation of the GUI elements saveBtn = new Button("Save"); ... ... setEventHandler(); Scene scene = new Scene(gridPane); window.setScene(scene); window.setResizable(false); window.showAndWait(); } private static void setEventHandler() { saveBtn.setOnAction(evt -> saveMemberInfo()); } private static Person saveMemberInfo() { Person tempNew = new Person(firstnameTxt.getText()); if (tempNew.isEqual(currentPers)) { System.out.println("No changes found. Nothing to save."); tempNew = currentPers; } return tempNew; } }
In my main gui/ code, the code used is:
Person pObj = EditGui.display(getSelectedTreeItemName(), getSelectedTreeItemPersonObj());
I am attempting to return the Person object from Edit gui back to main code and that results an error since display() return type is void but I had thought that since the action stems from the save button, should the end product not comes from there?
Even so, based on the above code,
1. Is it a good idea to split up the event-handling? (See setEventHandler() in my edit gui) I split them up, thinking it will help facilitate my understanding and troubleshooting?
2. How can I go about resolving the issue such that when Save button is clicked upon, the Person object will be passed back to the main gui?