• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Passing values back from inner classes

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there:
I have a program using actionlistener to create a non-modal dialog (pop-up window).
the pop-up window display a Jcombobox to select some variables, but I can not pass the value back
to the parent window
here is an extract of the code:
String s_alr1 = null;
.
.
.
// pmc button
gbc.gridx = 2;
pmcButton = new JButton("PMC");
topPanel.add(pmcButton,gbc);
pmcButton.addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
showpmc();
}
} );

.
.
.
.
.

/** Method which builds and launches a non-modal dialog */
public void showpmc ()
{
JPanel panel0 = new JPanel(new GridLayout(7,1));
JPanel panel1 = new JPanel(new FlowLayout());
JPanel panel2 = new JPanel(new FlowLayout());
JPanel panel3 = new JPanel(new FlowLayout());
JPanel panel4 = new JPanel(new FlowLayout());
JPanel panel5 = new JPanel(new FlowLayout());
JPanel panel6 = new JPanel(new FlowLayout());
JPanel panel7 = new JPanel(new FlowLayout());
dialog = new JDialog();
String[] listmdc = { "MDC","MDC1","MDC2","MDC3"};
mdc1 = new JComboBox(listmdc);
mdc1.setEditable(false);
mdc1.setSelectedIndex(0);
panel1.add(mdc1);
mdc2 = new JComboBox(listmdc);
mdc2.setEditable(false);
mdc2.setSelectedIndex(0);
panel2.add(mdc2);
.
.
.
.
.
okButton = new JButton("Ok");
cancelButton = new JButton("Cancel");
panel7.add(okButton);
panel7.add(cancelButton);
okButton.addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
addmdc();

// this shows a null value
textArea.append("!!!back from addalr" + s_alr1 + "\n");
dialog.setVisible(false);
dialog.dispose();
}
} );

cancelButton.addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
dialog.setVisible(false);
dialog.dispose();
}
} );
panel0.add(panel1);
panel0.add(panel2);
panel0.add(panel3);
panel0.add(panel4);
panel0.add(panel5);
panel0.add(panel6);
panel0.add(panel7);
dialog.setContentPane(panel0);
dialog.setLocation(300,300);
dialog.setSize(300,100);
dialog.pack();
dialog.setVisible(true);
}

public void addmdc( )
{
// this comment display OK
textArea.append("!!! in addmdc\n");
alr1.addItemListener( new ItemListener()
{
public void itemStateChanged( ItemEvent e )
{
if( e.getStateChange() == ItemEvent.SELECTED )
{
s_alr1 = (String)e.getItem()+",";

// this comment never shows......
textArea.append("!!! alr1 selected" + s_alr1 + "\n");


}
}
}
);
.
.
.
.
}
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am not exactly sure that I can help you because I don't understand from your code where things are. From you topic label I am guessing that you have created an inner class that is the popup window. Since non-static inner classes can access outer member variables just use one to get the information. Have your inner class 'close/ok/actionPerformed' routine call some parent class method to then use the member variable.
If your popup window is not an inner class then you need to use some AWTEvent extension so that your parent window could listen to the child window and then perform something being given the event structure with user information (chosen items from child window).
Regards,
Manfred.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic