Getting value from dialogwindow

Started by
0 comments, last by MattieB 18 years, 11 months ago
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);			
		}
	}
}
Here we are now,entertain us.
Advertisement
Hmm, maybe JOptionPane is a good solution.
Here we are now,entertain us.

This topic is closed to new replies.

Advertisement