Constructors in Inner classes (implementing Interfaces)
Posted
by thepandaatemyface
on Stack Overflow
See other posts from Stack Overflow
or by thepandaatemyface
Published on 2010-06-15T12:36:35Z
Indexed on
2010/06/15
12:52 UTC
Read the original article
Hit count: 156
Hi,
How would I go about writing a constructor for an inner class which is implementing an interface? I know I could make a whole new class, but I figure there's got to be a way to do something along the line of this:
JButton b = new JButton(new AbstractAction() {
public AbstractAction() {
super("This is a button");
}
public void actionPerformed(ActionEvent e) {
System.out.println("button clicked");
}
});
When I enter this it doesn't recognize the AbstractAction method as a constructor (compiler asks for return type). Anyone have an idea?
Thanks
© Stack Overflow or respective owner