Q22.Assume the the class AcLis implements the ActionListener interface. The code fragment below constructs a button ande gives it four action listeners. When the button is pressed, which action listener is the first to get its actionPerformed() method invoked?
- U) g$ r( D) ~( E+ s7 ]8 o7 W 1. Button btn = new Button(“Hello”);7 j! p q8 D( p& {3 L) L% p7 Z# B
2. AcLis a1 = new AcLis();
2 v O, z i/ k" ]6 z5 [ a I+ M 3. AcLis a2 = new AcLis();
: v% q5 ^# a% w 4. AcLis a3 = new AcLis();, j2 T' `) Z4 N8 W& K' y
5. btn.addActionListener(a1);8 ]0 i2 D7 y7 ]+ n
6. btn.addActionListener(a2);' l T1 J! h/ o; I5 K
7. btn.addActionListener(a3);$ M, T, u: W7 F+ G+ F& `
8. btn.removeActionListener(a2);
7 P, e: f$ c+ X7 J 9. btn.removeActionListener(a3);- j& ]' @5 j( b, K" X
10. btn.addActionListener(a3);
* ~/ S; ^" h0 {% T5 o" u$ l5 L 11. btn.addActionListener(a2);
0 F( V7 t- m9 ?( ~: o5 R# j a. a1 gets its actionPerformed() method invoked first.4 l9 X1 v* ^0 @
b. a2 gets its actionPerformed() method invoked first.
3 ^9 N9 }* m4 u& M; ^$ Q c. a3 gets its actionPerformed() method invoked first.$ g# M6 j- ^4 h0 X5 z, e
d. It is impossible to know which listener will be first.& M5 ?$ q$ m* O, ~& }% e
Q23.Which statement or statements are true about the code listed below?
5 T0 Z Y: d0 A! I4 |! U$ f 1. public class MyTextArea extends TextArea {/ N+ t* @/ Y5 s4 p) T: }1 h5 y7 x/ n
2. public MyTextArea(int nrows, int ncols) {, z# m! Z% h# W; Z8 Y1 h- b( q
3. enableEvents(AWTEvent.TEXT_EVENT_MASK);1 y1 S0 u2 x* {
4. }3 [1 V- r8 B# ?9 t" E, Z
5. public void processTextEvent(TextEvent te) {
, {+ @& F! G, \) l8 F6 p c( x7 w- w4 k
6. System.out.println(“Processing a text event”); |