Advertisement Jump to content
Sign in to follow this  

Getting value from dialogwindow

This topic is 5002 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")) {

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()) {			
		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()) {

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!