Jump to content
  • Advertisement
Sign in to follow this  
MattieB

Getting value from dialogwindow

This topic is 4911 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm working on a program with a gui. I've got a window (subclass of JFrame) with a menubar and menus. I've got a class MenuActionManager. Everytime the user clicks on a menuItem, a method is called from MenuActionManager which executes a certain action. Some actions require the user to fill in a value in a dialogwindow which appears on top of the main window. This dialogwindow has a text, a textfield and an okButton (JButton). When the user clicks on this button, the value in the textfield should be given to a value from menuActionManager. The problem is that my program has to wait untill the users gives the value and clicks ok. How can i solve this. My relevant code (I've tried to use and endless whilel-loop, but that wasn't a good idea):
public class Window extends JFrame implements ActionListener{

       public void actionPerformed(ActionEvent event) {
		String menuName;
		menuName= event.getActionCommand();
                 ....
                else if(menuName.equals("Set Zoom Factor")) {
			getMenuActionManager().setZoomFactorClicked();
		}
       }
}

public class MenuActionManager {
        public void setZoomFactorClicked() {
		DialogWindowDouble dialog = newDialogwindowDouble(getWindow(), "Title", "Question");
		double value = dialog.getValue();
	}
}

public class DialogWindowDouble extends DialogWindow{

         public double getValue() {
		while (!getOkPressed()) {			
		}
		changeOkPressed(false);
		String inputString = getInputField().getText();
		double inputDouble = Double.parseDouble(inputString);
		return inputDouble;		
	}
}

public class DialogWindow extends JDialog implements ActionListener{

         public void actionPerformed(ActionEvent event) {
		JButton clickedButton = (JButton) event.getSource();
		
		if(clickedButton == getOkButton()) {
			setOkPressed(true);			
		}
	}
}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!