Click here to Skip to main content
15,441,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have two windows: JFrame (main) and JDialog (seconday, pops up if I press button to change price). Now rest of code works well but I'm stuck at transfering new price from JDialog to JFrame. In JFrame's ActionListener I copied main method of JDialog, so it opens JDialog when pressed. But after it opens, rest of code from JFrame doesn't wait for ActionListener in JDialog, and continues rest of code.

To transfer data I'm using a helping class, so when I call JDialog I pass a object of that helper class and in JDialog I change value of one of attributes of that object. Knowing they share same address, object back in JFrame should also be changed.

How do I make it wait for ActionListener in JDialog?

HelperClass pom = new HelperClass(); // HELPER CLASS
										
System.out.println("COMMENT: before: " + pom.newPrice());
		try {
				pom.oldPrice = selectedProduct.getPrice();
								
			    ChangePrice dialog = new ChangePrice(pom);
								 
                dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
                dialog.setVisible(true);
							
		    	dialog.setModal(true);
			} catch (Exception e) {
				e.printStackTrace();
			}
System.out.println("COMMENT: after: " + pom.newPrice()); 
            // ...rest of code that changes price and updates JList...


Here's a picture of GUI, but if it's not allowed to post pictures, let me know and I'll delete it.
Pictures:
<img src="https://postimg.cc/qtjTwwc7">


What I have tried:

I've tried creating a boolean that checks if the price has been changed and if yes, advances after the main method of JDialog but then it gets stuck and it never gets to do rest of code.
Posted
Updated 27-Jul-21 1:56am

 
Share this answer
 
Comments
Just Caused 27-Jul-21 6:46am    
It's a bit unknown to me since in Uni we made Dialog windows by creating it in project by adding new JDialog and then copying JDialog's main method to ActionListener in JFrame that is supposed to start JDialog. I'll check this one out and let you know.
Just Caused 27-Jul-21 7:56am    
I managed to fix it a little bit differently, thanks anyway!
I managed to find a good way to return data. In class JDialog I made method getPrice() that returns price, and back in my main class JFrame I called dialog.getPrice(). To make it work I moved dialog.setModal(true) just below line that initializes "dialog". Somehow that made difference.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900