Ank
Ank

Reputation: 6270

Access variable in actionPerformed

I have a class SaveFile implementing ActionListener. The method in it takes a string argument compleName. How do I make completeName be accessable in actionPerformed method in that class.

Thanks

 class SaveFile implements ActionListener {
        public void uploadToDatabase(String completeName){

        }

        public void actionPerformed(ActionEvent e) {    
            // I want to access completeName here
        }
   }
}

Upvotes: 0

Views: 1685

Answers (2)

Platinum Azure
Platinum Azure

Reputation: 46193

Simply ensure you store completeName as an instance variable.

class SaveFile implements ActionListener {
        private String completeName;

        public void uploadToDatabase(String completeName){
            // do other things
            this.completeName = completeName;
        }

        public void actionPerformed(ActionEvent e) {    
            // use this.completeName to get that value
        }
   }
}

Upvotes: 2

Xavier Guzman
Xavier Guzman

Reputation: 460

just use it as a variable inside your class

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);
        }
   }
}

Upvotes: 3

Related Questions