It depends on how you structured it. In general, instances do not have a reference to the instance that created them, unless you pass it in and store it somewhere. However, if you do:
public class YourClass {
public void foo() {
JButton b = new JButton();
b.addActionListener(new ActionListener() {
@Override public void actionPerformed(ActionEvent e) {
}
});
}
}
then you can access the outside YourClassusingYourClass.this
source
share