[英]Java Interface in InputVerifier
I have this code: 我有以下代码:
public class Anagrafica implments ClientiInterface{
InputVerifier verifierAliquotaIva = new InputVerifier() {
public boolean verify(JComponent input) {
boolean verifica = true;
final JTextComponent source = (JTextComponent) input;
String text = source.getText();
if (text.length() != 0){
String codice = cliente.CercaCliente(text, this);
if (codice != null){
verifica = true;
}else{
JOptionPane.showMessageDialog(null, "Codice iva inesistente!");
tfDescrizioneIva.setText("");
verifica = false;
}
}else{
tfDescrizioneIva.setText("");
}
return verifica;
}
};
} }
This is an Clientiinterface. 这是一个Clientiinterface。 I saw that interface is incompatible within
InputVerifier
. 我看到该接口在
InputVerifier
不兼容。 How can I resolve this problem? 我该如何解决这个问题?
If I understood correctly of what you are trying to achieve, you must use the following: 如果我正确理解您要实现的目标,则必须使用以下方法:
public class MyInputVerifier implements InputVerifier { ... }
instead of this: 代替这个:
InputVerifier verifierAliquotaIva = new InputVerifier() { ... }
and then use new MyInputVerifier()
where needed. 然后在需要时使用
new MyInputVerifier()
。
More scientifically, an interface is only a skeleton, it has no implementation. 更科学地讲,接口只是一个框架,没有实现。 If you want custom code in a place where
InputVerifier
is required, create a class that implements it, and use an instance of your new class 如果您想在需要
InputVerifier
的地方放置自定义代码,请创建一个实现它的类,并使用新类的实例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.