0

ALERT: New to Java

I have tried the following to make the outer class the parent to the filechooser, but it refers to OuterClass.AddBrowseActionListener instead of OuterClass:

public class OuterClass extends JFrame{

...

    class AddBrowseActionListener implements ActionListener{
        public void actionPerformed(ActionEvent event){
            JFileChooser filechooser = new JFileChooser();
            int returnValue = filechooser.showOpenDialog(this);
            File infile = filechooser.getSelectedFile();
            System.out.println(infile.getName());
        }
    }
}

I know about anonymous classes so you don't have to show me about that unless that is the only way to solve the problem.

Also, using reflection isn't really what I am looking for.

RoryG
  • 1,113
  • 1
  • 10
  • 20

2 Answers2

2

Technically, this is no more than a private member of the containing object, therefore you can use the class to find the field:

int returnValue = filechooser.showOpenDialog(OuterClass.this);

This is known as the "Qualified this" in the Java Language Specification.

Ray
  • 3,084
  • 2
  • 19
  • 27
0
int returnValue = filechooser.showOpenDialog(OuterClass.this);
Liquid
  • 1