S
Sameer
Many times in GUI programming we need to write action listeners
with the help of an anonymous class.
How to refer to the parent frame from these anonymous classes if
we need a reference to it.
For example in showing a dialog from the anonymous class, we
need to pass a reference of parent component like:
public class GUI extends Frame {
private void createMenus() {
menuItemExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
void showMessageDialog(Component parentComponent,
Object message);
}
});
}
}
We can't use 'this' in this situation because it will refer to the
anonymous class.
Is there any wayout to pass refernce of the parent component to
the anonymous class?
-Sameer
with the help of an anonymous class.
How to refer to the parent frame from these anonymous classes if
we need a reference to it.
For example in showing a dialog from the anonymous class, we
need to pass a reference of parent component like:
public class GUI extends Frame {
private void createMenus() {
menuItemExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
void showMessageDialog(Component parentComponent,
Object message);
}
});
}
}
We can't use 'this' in this situation because it will refer to the
anonymous class.
Is there any wayout to pass refernce of the parent component to
the anonymous class?
-Sameer