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..
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
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
posted 17 years ago
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.