java - Multiple JLables into a single addMouseListener -
i got 3 jlable
s, , added functionality l3
of when clicked, set jlabel
text value store array (ans.get(0,0))
jlabel l1 = new jlabel("obtener x1"); jlabel l2 = new jlabel("obtener x2"); jlabel l3 = new jlabel("obtener x3"); l3.setbounds(30, 180, 100, 25); l3.addmouselistener(new mouselistener() { @override public void mouseclicked(mouseevent e) { l3.settext("x1 = "+ ans.get(0, 0)); } @override public void mouseentered(mouseevent e) { //mouseentered, mousepressed, mouserelease overriden methods....
the question here is, posible implementent rest of jlabel
s (l1
, l2
) single addmouselistener
(same mouselistener belonging jlabel
l3
) ?
create local variable mouselistener
, assign instance it. add mouselistener
each jlable
s.
jlabel l1 = new jlabel("obtener x1"); jlabel l2 = new jlabel("obtener x2"); jlabel l3 = new jlabel("obtener x3"); mouselistener ml = new mouselistener() {...} l1.addmouselistener(ml); l2.addmouselistener(ml); l3.addmouselistener(ml);
then each jlable
share same mouselistener
object.
Comments
Post a Comment