I have an existing frame with 2 panels on it. When the user presses one of the JButtons found on the JPanel, I need to handle the event by opening a JDialog box that allows the user to set settings - settings that include 3 sliders and 2 drop lists, when the user saves the settings I need to pull them from this dialog and use them later. I'm new to GUI and for the past 2 and a half days I have searched for many ways to create this such of thing, and I have succeeded to make a slider and a drop list each one by its own, but I still haven't figured out how to handle an event while a frame is open, because from what I have seen I need a new JFrame, but what happens to the one alrady open? In addition, how can I make this dialog with these sliders and drop lists?
Here is the code I wrote for the slider:
public void setSlider()
{
optionPane = new JOptionPane();
JSlider slider = getSlider(optionPane);
JSlider slider2=getSlider(optionPane);
optionPane.setMessage(new Object[] { "Select animal's speed: ", slider });
optionPane.setMessageType(JOptionPane.QUESTION_MESSAGE);
optionPane.setOptionType(JOptionPane.OK_CANCEL_OPTION);
dialog = optionPane.createDialog(Frame, "Set speed");
dialog.pack();
dialog.setVisible(true);
int speed = (int) optionPane.getInputValue();
}
static JSlider getSlider(final JOptionPane optionPane) {
JSlider slider = new JSlider();
slider.setMajorTickSpacing(1);
slider.setMaximum(10);
slider.setPaintTicks(true);
slider.setPaintLabels(true);
ChangeListener changeListener = new ChangeListener() {
public void stateChanged(ChangeEvent changeEvent) {
JSlider theSlider = (JSlider) changeEvent.getSource();
if (!theSlider.getValueIsAdjusting()) {
optionPane.setInputValue(new Integer(theSlider.getValue()));
}
}
};
slider.addChangeListener(changeListener);
return slider;
}
I hope this post is specified enough. Thanks!!!