1

I wanted to pass the exact instance that was created in the main method to the new Executor which has a MPGui as a parameter. Is this possible?

public class MPGui {
  public MPGui() {
    //initialize GUI
  }

  public class ExecuteListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {

      Executor execu = new Executor(MLA, /*the MPGUI() instance */);
      execu.execute();          
    }
  }

  public static void main(String[] args) {
    MPGui a = new MPGui();
  }
}
Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
rukshiin
  • 87
  • 2
  • 9
  • This kind of depends on how you plan to use `ExecuteListener`. One obvious solution is to create a constructor for it and pass the MPGui instance to it. You've shown it as an inner class though. What @subtenante says might be what you are looking for. – Radiodef Jan 21 '14 at 09:10

1 Answers1

5

Try this (well.... MPGUI.this actually):

public class MPGui {
        public MPGui() {
                //initialize GUI
        }

        public class ExecuteListener implements ActionListener {
                public void actionPerformed(ActionEvent e) {

                        Executor execu = new Executor(MLA, MPGUI.this);
                        execu.execute();

                }
        }

        public static void main(String[] args) {
                MPGui a = new MPGui();
        }
}
glmxndr
  • 45,516
  • 29
  • 93
  • 118