Howto popup-dialog and get events/values from buttons/elements back?

Hi, I’m having a hard time to get a popup-dialog working in the 3d view:



It should have a text, slider and cancel, ok-button.

But it looks like I mixed something, hard to understand how dialogs work as InternalFrame in the 3d window.

Also I would like to have the slider between the text and the cancel/ok buttons.

Can anyone help me?

Here is my code, it sadly always recives ‘uninitializedValue’ from the buttons:

[java]private void showArmyDialog(int armyNr, int cityNr) {

final JDesktopPane desktopPane = jmeDesktop.getJDesktop();

final JInternalFrame modalDialog = new JInternalFrame(“Army” + DataModel.vArmies.get(armyNr).get_name());

String whatDoStr ="";



if (DataModel.aCities[cityNr].get_party() != (DataModel.vArmies.get(armyNr).get_party())) {

whatDoStr=“Army “+ armyNr+” player(”+DataModel.vArmies.get(armyNr).get_party()+") “+DataModel.aGenerals[DataModel.vArmies.get(armyNr).get_general()-1].get_name()+“nattacks: " + DataModel.aCities[cityNr].get_name()+” player(”+DataModel.aCities[cityNr].get_party()+")";

Debug.text(whatDoStr);

} else {

whatDoStr=“Army “+ armyNr+” player(”+DataModel.vArmies.get(armyNr).get_party()+") “+DataModel.aGenerals[DataModel.vArmies.get(armyNr).get_general()-1].get_name()+“nmoves: " + DataModel.aCities[cityNr].get_name()+” player(”+DataModel.aCities[cityNr].get_party()+")";

Debug.text(whatDoStr);

}



Object[] options = {“attack”,“cancel”};



int n;

JOptionPane optionPane = new JOptionPane(whatDoStr,JOptionPane.QUESTION_MESSAGE,

JOptionPane.YES_NO_OPTION, null, //do not use a custom Icon

options, //the titles of buttons

options[0]);



modalDialog.getContentPane().add(optionPane);

jmeDesktop.setModalComponent(modalDialog);

desktopPane.add(modalDialog, 0);

modalDialog.setVisible(true);

modalDialog.setSize(300, 300);//getPreferredSize());

modalDialog.setLocation((desktopPane.getWidth() - modalDialog.getWidth()) / 2,

(desktopPane.getHeight() - modalDialog.getHeight()) / 2);



final JPanel anPanel = new JPanel();



JButton lbutton = new JButton("<");

JButton rbutton = new JButton(">");

lbutton.setSize(lbutton.getPreferredSize());

/*lbutton.setLocation( (int) ( ( display.getWidth() - lbutton.getWidth() ) / 2

  • display.getWidth() ), display.getHeight() - 40 - lbutton.getHeight() / 2 );

    rbutton.setSize( rbutton.getPreferredSize() );

    rbutton.setLocation( (int) ( ( display.getWidth() - rbutton.getWidth() ) / 2
  • display.getWidth() ), display.getHeight() - 40 - rbutton.getHeight() / 2 );*/

    anPanel.add(lbutton);



    JSlider slider = new JSlider(0, DataModel.vArmies.get(armyNr).get_strength(),DataModel.vArmies.get(armyNr).get_strength());

    //Debug.text(""+DataModel.vArmies.get(armyNr).get_strength());



    //slider.setValue(DataModel.vArmies.get(armyNr).get_strength());

    //slider.setMaximum(DataModel.vArmies.get(armyNr).get_strength());

    anPanel.add(slider);

    anPanel.setDoubleBuffered(false);

    //anPanel.setOpaque( false );



    anPanel.add(rbutton);

    optionPane.add(anPanel);



    optionPane.revalidate();

    jmeDesktop.setFocusOwner(optionPane);



    desktopPane.repaint();



    Object selectedValue = optionPane.getValue();

    System.out.println("Ja gewählt: "+selectedValue);

    if(selectedValue != null && selectedValue instanceof Integer){

    int option = ((Integer)optionPane.getValue()).intValue();

    if ( option == optionPane.YES_OPTION )

    System.out.println(“Ja gewählt”);

    }





    optionPane.addPropertyChangeListener(JOptionPane.VALUE_PROPERTY, new PropertyChangeListener() {



    public void propertyChange(PropertyChangeEvent evt) {

    modalDialog.setVisible(false);

    jmeDesktop.setModalComponent(null);

    desktopPane.remove(modalDialog);

    popup = false;

    }

    });



    }[/java]



    (I hope ‘Development discussion’ is the right forum, if not please tell me where I should have posted else)