Win a copy of Hands On Software Engineering with Python this week in the Jython/Python 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

awt!!!  RSS feed

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there was a question in applied reasoning about
select each of the code fratgments that would allow a newly created java.awtButton to generate ActionEvents.
A button.enableActionEvents();
B button.addActionListener(anActionListener);
D button.enalbeEvents(AWTEvent.ACTION_EVENT_MASK);
i am not able to understand what does this question means..
and why is the option B is a correct answer..

thanks in advance...
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can provide a component a actionlistener with implementing a listener , extend a adapter. when you implementing an listener you must override all methods defined in the Listeners interface.
When extending an adapter you can just provide code for the action you like to perform.
There is an alternitive to delegating a component's events. It is possible to subclass the component and override the method that recives events and dispach them to listeners.
To do this you must use enableEvents( AWTEvent.X_EVENT_MASK )
And provide code for processXEvents( XEvent ae ) wher eX can be Action , Window etc.
Se the code


A. button.enableActionEvents();
B. button.addActionListener(anActionListener);
D. button.enalbeEvents(AWTEvent.ACTION_EVENT_MASK);


A is not sufficient. You must pass the static variable for AWTEvent class for ActioEvent. Plus the correct way to do it isn't enableActionEvents(); but enableEvents( AWTEvent.ACTION_EVENT_MASK );
D First enableEvents is wrongly spelled. But you must altso provide code for public void processActionEvents( ActionEvent e ) to pass it to the listener. D is altso wrong.
B is right.
Hope this helps
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that true that in the delegation event model, the default events are enabled by default? It really is not necessary to invoke enableEvents()? Thanks
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mr Smith is right. You can altso override the processEvent method.

By using this tecnique you dont have to use processActionEvent , processKeyEvent and so on. You can us processEvent( AWTEvent evt ) instead. The event return an id. You can get this id by using the getId() method of the AWTEvent class. You can make comparation to se what event got executed.
 
Ranch Hand
Posts: 2373
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good explanation Mathias...
------------------
azaman
 
There's a way to do it better - find it. -Edison. A better tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!