Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

About AWTEvent!

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
text area generate text event .It also generates action event on hitting the enter key.
So I think that only answers a , b,c,d & e are correct. Some body please clarify.
Anand.
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic