awt - Java: How do I do a "onclick" for TextField? -
i want make text field clear text when clicks it. how can this?
on java.awt.textfield
can add mouselistener
so
textfield field = new textfield(); field.addmouselistener(new mouselistener() { public void mouseclicked(mouseevent e) { } public void mousepressed(mouseevent e) { } public void mousereleased(mouseevent e) { } public void mouseentered(mouseevent e) { } public void mouseexited(mouseevent e) { } });
the reason being java.awt.textfield
subclass of java.awt.textcomponent
(which, in turn, subclass of java.awt.component
). component
class has addmouselistener()
method.
alternatively, can replace mouselistener
java.awt.event.mouseadapter
has encapsulates of mouselistener
, mousewheellistener
, mousemotionlistener
methods.
from javadoc (of mouseadapter
):
an abstract adapter class receiving mouse events. methods in class empty. class exists convenience creating listener objects.
mouse events let track when mouse pressed, released, clicked, moved, dragged, when enters component, when exits , when mouse wheel moved.
Comments
Post a Comment