I'd like to use the new
operator to create an instance of JPanel
that implements ActionListener
and directly overrides the actionPerformed
method.
I tried
JPanel panel = new JPanel implements ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
// ...
}
};
but that doesn't work because of a syntax error.
Of course I could just define a new class like JPanelWithActionListener
and call this one with new
, but is there any way to do it in just one line?