java - variables and methods and actionlisteners -
i have (partially pseudo)code
class { void b() { int d = 0; jbutton c = new jbutton(); c.addactionlistener(new actionlistener() { @override public void actionperformed(actionevent e) { d = 1; } }); } } however, doesn't work, eclipse suggested adding final identifier d, makes value impossible change. sorry if it's stupid question, it's hard form question google this... can't declare variable on lever higher method b.
you want move declaration of d outside of method.
class { int d = 0; method b() { jbutton c = new jbutton(); c.addactionlistener(new actionlistener() { public void actionperformed(actionevent e) { d = 1; } } } ..and format code.
Comments
Post a Comment