Which Listener interfaces can you add to a TextArea object? a) TextListener b) ActionListener c) MouseMotionListener d) MouseListener e) ComponentListener The result is a),c),d),e) could you tell me why TextArea cannot add ActionListener?
The only method defined in TextListener is textValueChanged(). So unless you modify the text in the TextArea, no event occurs. Whereas in case of TextField, changing text value and hitting the Enter key produces two different events and they are in two different listener interfaces. Nothing is supposed to happen when you hit Enter key in a TextArea component.
Which Listener interfaces can you add to a TextArea object? a) TextListener b) ActionListener c) MouseMotionListener d) MouseListener e) ComponentListener The result is a),c),d),e) could you tell me why TextArea cannot add ActionListener? I am not very clear about c,d and e. does it mean that one can handle MouseEvents and ContainerEvent for a text area, like adding a button to it etc. and highlighting areas selected by mouse. I thought you never had to handle mouseEvents for TextAreas because the functionality is predefined.
I�ll try to clarify (or to confuse you more...) TextArea extends Component class, from which it inherits the following methods: addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener Besides this TextArea extends TextComponent class, from which it iherits addTextListener method. TextArea itself doesn�t define any new �addXXXListener� methods. BUT TextField class (which also extends TextComponent) does: addActionListener Both TextArea and TextField generate TextEvent but only TextField generates ActionEvent
Mohit, Seems to be some confusion here: The question asked about ComponentListener, not about ContainerListener. ComponentListener gets ComponentEvents, which are sent when the component in question is resized, or its visibility changes (gets uncovered perhaps) etc. This certainly makes sense for a TextArea. ContainerListeners are not specified for TextAreas, and make no sense, because a TextArea is not a Container and you cannot add buttons to it etc. The MouseListener and MouseMotionListeners are specified because you might reasonably want to know when the mouse moves over the TextArea or clicks on it. The basic text-editing capability of the component is built-in, that's true, and I assume it uses these listeners. But that doesn't mean you can't add more listeners of your own, even of the same kind, to add additional behavior. For the sake of example, you might create a TextArea that displays its text for reading, but when the mouse moves over it, it reformats the text for editing, for example by showing markup tags, much as happens when you post on JavaRanch. You would do this by adding your own Mouse listeners to those already there. The question originally asked was: why is ActionListener not included? I guess the answer is that ActionEvent is conceptually the class of events used to signal that the end-user has performed some component-specific GUI-operation like push the button or drag the slider or select the menu-item. And there is no such control-operation intended in the design of TextArea, except of course editing the text, which has its own kind of event and listener. So ActionEvent is not meaningful, or needed. (Sure hope somebody with more experience than I reads this and vets it).
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop