Passing arguments with a method in it. Java -


could please explain approach of passing such argument addactionlistener method is? understand button variable of jbutton type created , event listener defined. it's not clear me addactionlistener argument, namely actionperformed method definition in it. can ready such approach? thanks.

jbutton button = new jbutton("new button"); button.addactionlistener(new actionlistener() {     public void actionperformed(actionevent arg0) {         system.out.println("hello");     } }); 

what happening here addactionlistener takes object implements actionlistener parameter.

you creating anonymous class implements actionlistener interface , within defining method actionperformed required actionlistener interface.

this anonymous class gets instantiated object , object passed addactionlistener method.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -