Reputation: 2025
I need to implement an action listener with a custom constructor so that I can pass parameter to it.
class CustomActionListener implements ActionListener{
@Override
public ActionListener(int u){
}
@Override
public void actionPerformed(ActionEvent arg0) {
}
}
but It seems I can't override constructors.How do I do it?
Upvotes: 0
Views: 3143
Reputation: 1231
You just need to call super class constructor before anything else. Sounds simple to me if that's what you mean:
public class CustomActionListener implements ActionListener{
private int u;
public CustomActionListener(int u) {
super();
this.u = u;
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
Upvotes: 1
Reputation: 8653
ActionListener is an interface, there is no constructor in it.
More over you can not override constructors. In extended class constructor, you need to call super constructor if no default constructor is there in super class.
Upvotes: 4