Hi, I'm developing an application, with a main GUI and another GUI that gathers some information. Upon clicking a button in the main GUI, it initializes a second GUI object that has fields for input and then an "OK" button. I need to be able to return the information in the second GUI to the first GUI in the form of an object array, but only after the OK button is clicked.

Both GUIs are very simple, extend JFrame, are non-static, and are run by creating an object and setting its visibility and size.

I assume I will have to use threads, I just cannot figure out how to use them with these GUI object classes.

This is the code from the Main GUI, EditUser is the name of the second GUI:

public void actionPerformed(ActionEvent e) {
		if(e.getSource().equals(addnew)){
			EditUser ed = new EditUser();
			ed.setSize(159, 143);
			ed.setVisible(true);
			model.addRow(ed.getUserInput());
		}
}

And this is the getUserInput method in the second GUI:

public Object[] getUserInput() {
		
		return new Object[] { nameField.getText(),
				RankString.getRank(editRanksCombo.getSelectedIndex()),
				v2tag.isSelected() };
}

The issue is that it doesn't allow the user time to make a decision, it just gets what was given when the second GUI was created.

How do I make the first GUI wait until the second one's OK button was pressed?

Thank you in advance.

If you used a modal Dialog for the 2nd GUI to collect the info, the app would wait until the info was input before proceding. Writing your own code to synch the first app to wait for the second GUI is a pain.

To use a dialog vs a frame, build the GUI in a panel and add it to the container(dialog or frame)

Have a public method in the first class that accepts the object array as a parameter.
Pass the first window as a parameter to teh constructor of the second window.
When the user clicks OK you can then call the method in the first window to return the data.

Edit: Thanks norm: ... unless you need the first window to be blocked until the second is complete, in which case use norm's solution
J

Thank you both for your replies, I have it all working now.

Merk thread as solved? ps which solution did you use?

I used yours james, i still wanted them to be able to use the first gui while the second one was up. Thank you both for your help

Glad I could help, and thanks for the feedback
J

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.