我有一个问题,只是出于好奇,这是如何指定的参考参数的方法,并确保该参数必须实现一个接口如何指定参考方法参数实现接口
如ActionListener的方法处理事件 时,当你添加一个ActionListener使用addActionListener方法(ARG)方法 ARG必须是一个实现ActionListener接口 对象的引用的GUI组件的actionPerformed,这就是我的问题 addActionListener方法,方法,如何确保其ARG实现ActionListener接口
JTextField textField = new JTextField();//creating new text field
TextFieldHandler textFiledHandler = new TextFieldHandler();//object of the handler
textField.addActionListener(textFieldHandler);//here's my question
add(textField);
//creating a nested class
private class TextFieldHandler implements ActionListener {
@Override
public void actionPerformed (ActionEvent event) {
//do something here
}//end actionPerformed
}//end class TextFieldHandler