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?
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 .
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
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.