我有一个实现ActionListener的SaveFile类。其中的方法采用字符串参数compleName。如何在该类的actionPerformed方法中使completeName可访问。
谢谢
class SaveFile implements ActionListener {
public void uploadToDatabase(String completeName){
}
public void actionPerformed(ActionEvent e) {
// I want to access completeName here
}
}
}
最佳答案
只是将其用作类中的变量
class SaveFile implements ActionListener {
private string completeName;
public void uploadToDatabase(String compName){
//code...
this.completeName = compName;
}
public void actionPerformed(ActionEvent e) {
System.out.println(completeName);
}
}
}