It acts on the inner class

I have a class that contains an inner class. I want to send a value equal to the upper class, but "this" sends the value of the inner class. What can I do?

package Controller; public class MessageFrameListener{ private MessageFrame mf; private User us; private Contact cn; private Timer timer; private Running run; private ListFrame lf; public MessageFrameListener(ListFrame l_f, MessageFrame m_f, User u_s, Contact c_n, Running r_n){ run = r_n; mf = m_f; us = u_s; cn = c_n; lf = l_f; m_f.addButtonListener(new SButtonListener()); m_f.addWinListener(new FrameListener()); timer = new Timer(500,new timerListener()); timer.start(); } public class FrameListener implements WindowListener{ @Override public void windowClosing(WindowEvent e) { timer.stop(); timer = null; mf.close(); lf.removeMFL(this)); } } } 

So this line

  lf.removeMFL(this)); 

sends a "FrameListener" by this, but I want to send a "MessageFrameListener"

+4
source share
3 answers

Use qualified this :

 MessageFrameListener.this 
+8
source

Using:

  lf.removeMFL (MessageFrameListener.this);
+1
source

Inside the inner class you can use

 MessageFrameListener.this; 

You can also add a method to the outer class.

 public MessageFrameListener getInstance() { return this; } 
+1
source

Source: https://habr.com/ru/post/1413394/


All Articles