0% found this document useful (0 votes)
2 views

AJP UNIT 3

Uploaded by

vp867131
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

AJP UNIT 3

Uploaded by

vp867131
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Chapter 3

Event Handling

Each Question carries 1 Marks

Q1. Which package is required for an adapter classes?

A) java.awt.event B) java.lang C) java.util D) java.swing

Q2. An adapter class provides an empty implementation of all methods in an .

A) inheritance B) class C) Class ,Object D) event listener interface

Q3. Which one of the following is adapter class?

A) WindowAdapter B) KeyAdapter C) MouseAdapter D) All the above

Q4. class have the KeyListerner interface.

A) KeyListernerAdapter B) KeyAdapter C) Adapter D) None

Q5. Write correct word at blank spaces. f.addWindowListener(new { public void


windowClosing(WindowEvent e) { System.exit(0); }

A) } and ); B) WindowAdapter() and });


C) KeyAdapter() and }); D) Window and ;

Q6. Identify the correct adapter name and event name.


public class MyFocusListener extends
{
public void focusGained( fe)
{
Button button = (Button) fe.getSource();
label.setText(button.getLabel());
}
}
A) Focusevent, Focusadapter B) FocusAdapter, Event
C) FocusAdapter, FocusEvent D)
Adapter,FocusEvent

Q7. Adapter classes are an class for receiving various events.

A) Abstract B) Inner C) Inline D) Inherited

Q8. Adapter classes are used to create objects.


A) Class B) Method C) Package D) Listener

Q9. Identify the class which is not an adapter class?

A) KeyAdapter B) FocusAdapter
C) ItemAdapter D)
MouseMotionAdapter

Q10. Adapter classes are used to the process of event handling.

A) solve B) simplify C) avoid D) create

Q11. An adapter class provides an implementation of all methods in an event listener


interface.

A) pluggable B) simple C) empty D) Interface

Q12. Which of the following method does not belongs to WindowListerner interface?

A) windowActivated B) windowClosed
C) windowClosing D) windowReactivated

Q13. Which of the following method is invoked when a window is changed from a normal to
aminimized state?

A) windowActivated() B) windowClosed()
C) windowClosing() D) windowIconified()

Q14. What is adapter class for component listener interface?

A) Component B) ComponentAdapter
C) ComponentListenerAdapter D) None

Q15. Whether adapter classes use the methods of event classes?

A) Yes B) No C) Sometimes D) Depends on


some requirement

Q16. Which of these methods is defined in MouseMotionAdapter class?

A) mouseDragged() B) mousePressed() C) mouseReleased() D)


mouseClicked()

Q17. If an adapter class is inherited , there is no need of implementing all the methods of
listenerinterfaces .

A) Sometimes B) Never C) always D) None

Q18. Adapter class makes programmers task easier .


A) Sometime B) True C) False D)
Never

Q19. In an adapter class program, if it contains 5 methods, how many methods are to be
overriden?

A) 1 B) 2 C) 4 D) 5

Q20. Which is the abstract adapter class for receiving keyboard focus events.

A) FocusListener B) FocusAdapter C) AdapterFocus D)


AdapterListerner

Q21. Following are the integer constants which does not belong to ComponentEvent class .

A) COMPONENT_HIDDEN B)
COMPONENT_ICONIFIED C) COMPONENT_MOVED
D)COMPONENT_SHOWN

Q22. A class which adapts methods of another class by giving different names to essentially
the samemethods is called as

A) Inner Class B) Simple Class C) Adapter Class D)


Inherited Class

Q23. If a class MyWindowAdapter extends WindowAdapter and implements the


windowClosing()method. How to register this class?

A) this.addWindowListener(new MyWindowAdapter());

B) this.addWindow(new MyWindowAdapter());

C)this.addWindowAdapter(new MyWindowAdapter());

D) this.addWindowWindow(new MyWindowAdapter());

Q24. MouseWheelEvent defines integer constants.

A) WHEEL_BLOCK_SCROLL,WHEEL_UNIT_SCROLL B)
BLOCK_SCROLL,UNIT_SCROLL C)WHEEL_SCROLL,BLOCK_SCROLL
D) WHEEL_PAGE_SCROLL,WHEEL_TRACK_SCROLL

Q25. To handle any events of mouse, you must implement following interfaces.

A) MouseListener, MouseMotionListener, MouseWheelListener


B) MouseListener, MouseWheelListener
C) MouseMotionListener, MouseWheelListener D) MouseListener

Q26. Identify the correct adapter name and event name.


class MyWindowAdapter extends
{
public void windowClosing( e) { System.exit(0);
}
}
A) Window, WindowEvent B) WindowAdapter,
Window C) WindowAdapter, WindowEvent D)
Adapter,Event

Q27. In case of we can implement only required methods of any interface.

A) interface B) package C) adapter classes D) event classes

Q28. Following four methods belongs to which class? 1) public void add(Component c) 2)
public voidsetSize(int width,int height) 3) public void setLayout(LayoutManager m) 4)
public void setVisible(boolean)

A) Graphics class B) Component class C) Both A & B D)


None of the above

Q29. Following methods belongs to which class? 1) public void add(Component c) 2) public
void setSize(int width,int height) 3) public void setLayout(LayoutManager m) 4) public void
setVisible(boolean)

A) Graphics class B) Component class C) Both A & B D) None of


the above

Q30. Which of these are methods of MouseListener Interface?

A) mouseDragged() B) MouseMotionListener() C) MouseClick() D)


MousePressed()

Q31. Which method is used to close a swing frame

A) WINDOW_CLOSING B) WindowEvent(Window src, int type,


Window other) C)windowClosing(WindowEvent we) D)
setDefaultCloseOperation()

Q32. Which are the not types of key events-

A) KEY_PRESSED B) KEY_DOUBLE C) KEY_RELEASED D)


KEY_TYPED

Q33. is the super class of all event classes.

A) Event B) Object C) EventObject D) EventClass

Q34. Which of this interface is defines a method adjustmentValueChanged( ) ?

A) ComponentListener B)
ContainerListener C) ItemStateListener D)
AdjustmentListener
Q35. Which of these interfaces define a method keyPressed()?

A) MouseMotion Listener B) MouseListener


C) KeyBoardListener D) KeyListener

Q36. From following options which of these is method of MouseMotionListener Interface

A) mouseMoved() B) MouseMotionListener()
C) MouseClick() D) MousePressed()

Q37. Fill in the blank: MouseMotionListener interface defines methods

A) one B) two C) three D)


four

Q38. Assuming we have a class which implements the ActionListener interface, which
method shouldbe used to register this with a Button? ;

A) addListener(*) B) addActionListener(*);
C) addButtonListener(*); D) setListener(*);

Q39. windowGainedFocus() and windowLostFocus() methods are belongs to interface

A) WindowInterface B) WindowFocused
Interface C) WindowFocusListener D)
WindowAction Interface

Q40. Fill in the blank: MouseListener interface define… methods

A) 2 B) 5 C) 7 D) 4

Q41. KEY_TYPED Event generated when....

A) key pressed or released B) only when character is


generated C) only key pressed D) only key
released

Q42. Which of these methods are used to register a Window listener?

A) windowListener() B) addListener()
C) addWindowListener() D)
eventWindowListener()

Q43. Which of these methods are used to register a mouse motion listener?

A) addMouse() B)
addMouseListener() C) addMouseMotionListner() D)
eventMouseMotionListener()

Q44. What is a listener in context to event handling?


A) A listener is a variable that is notified when an event occurs.

B) A listener is a object that is notified when an event occurs.

C) A listener is a method that is notified when an event occurs.

D) None of thementioned.

Q45. The KeyEvent class methods-

A) getKeyCode ( ) B) geyKeyTyped( ) C) getKeyChar ( ) D) both a and c

Q46. Which of these are methods of TextListener Interface?

A) textChange() B) textModified()
C) textValueChanged() D)
textValueModified()

Q47. If no valid character is available then geyKeyChar( ) returns-

A) VK_UNDEFINED B)
CHAR_UNDEFINED C) VK_CONTROL
D) CHAR_ERROR

Q48. Which of these are methods of KeyListener Interface?

A) keyPressed() B) keyReleased() C) keyTyped() D) All of


this

Q49. KeyEvent is a subclass of-

A) InputEvent B) TextEvent C) ItemEvent D)


MouseEvent

Q50. Which source generates adjustment events?

A) Button B) List C) Scroll bar D) Text


components

Q51. getPoint( ) , method to obtain ...................................

A) x - co-ordinates of the mouse. B) y- co-ordinates of the mouse.


C) both x and y co-ordinates of themouse. D) The total number of
click count.

Q52. The following statement return- Point getPoint( )

A) to obtain the coordinates of the mouse. B) returns Point int that


contains the Y C) returns Point objectthat contains the X D) to obtain the
coordinates of the key
Q53. The, int getClickCount( ) method returns-

A) number of mouse clicks for widgets.

B) number of mouse clicks for graphical user interface.

C) numberof mouse clicks for this event.

D) number of mouse clicks from application started.

Q54. The interface handles item event.

A) ActionListener B) ItemListener C) ItemHandler D)


WindowListener

Q55. Which method not use to obtain the coordinates of the mouse-

A) Point getLocationOnScreen( ) B) int getKeyCode( )


C) int getXOnScreen( ) D) int
getYOnScreen( )

Q56. Which of these method are used to register a keyboard event Listener ?

A) KeyListener() B) addKeyListener()
C) RegisterKeyListener() D) addKeyBoard()

Q57. The TextEvent generated by-

A) text fields and text areas when characters are entered.

B) text fields and text areas when mouse entered.

C) text fields and text areas when mouse clicked

D) text fields and text areas when keyboardpress.

Q58. Which is the correct general form of method of the ActionListener interface?

A) void ActionPerformed(ActionEvent ae) B) void


ActionPerformed(Actionevent ae) C) void actionPerformed(ActionEvent ae)
D) void ActionPerformed(actionEvent ae)

Q59. The TextEvent Constructor- TextEvent(Object src, int type) Here type means-

A) The type of text B) The type of object passed.


C) The type of event. D) The type of source
generatedevents.

Q60. windowDeiconified() is method of interface


A) WindowListener Interface B) Window
Interface C) Window Conified Interface D) Action
Interface

Q61. windowIconified() is method of interface

A) WindowListener Interface B) Window


Interface C) WindowConified Interface D) Action
Interface

Q62. The Following steps are required to perform 1) Implement the Listener interface and
overrides itsmethods 2) Register the component with the Listener

A) Exception Handling B) String Handling C) Event Handling D) Listener


Handling

Q63. Consider following three statement 1) ActionListener Interace defines one method to
receive action event 2) ItemListener Interface defines one method to recognize when the state
of item change.. 3)MouseListener interface defines mouseMoved() method

A) Statement 1 and 2 are true B) Only first statement is true


C) Only second statement is true D) Allstatements
are true

Q64. The WindowEvent class, WINDOW_ICONIFIED, integer constants meaning-

A) Showing a window for the first time.

B) The window which contains the focus owner.

C) Reducing thewindow from to minimized.

D) Restoring the window to its original size.

Q65. ItemEvent constructor- ItemEvent(ItemSelectable src, int type, Object entry, int state)
Here srcmeans......

A) The specific item that generated the item event is passed

B) The type of object C) a reference to thecomponent that


generated event D) The current state of that item.

Q66. Which of the following are true? A. The event-inheritance model has replaced the
event- delegation model. B. The event-inheritance model is more efficient than the event-
delegation model. C. Theevent-delegation model uses event listeners to define the methods of
event-handling classes. D. The event-delegation model uses the handleEvent( ) method to
support event handling.
A) Statement 1 is true B) Statement 2 is true
C) Statement 3 is true D) Statement 4 is
true

Q67. WindowEvent is a subclass of .

A) ComponentEvent B) TextEvent C) InputEvent


D) Window

Q68. getWindow ( ) method returns

A) int value of window B) Location of window


C) void value D) Window
object

Q69. Which of the following are true? A) The MouseListener interface defines methods for
handling mouse clicks. B) The MouseMotionListener interface defines methods for handling
mouse clicks. C) The MouseClickListener interface defines methods for handling mouse
clicks. D) The ActionListener interfacedefines methods for handling the clicking of a button.

A) Only Statement A is true B) Only Statement D is true


C) Statement A and D are true D) Statement Band D are
true

Q70. WindowEvent class methods are-

A) getOppositeWindow() B) getNewState()
C) getOldState() D) All of above

Q71. Match the correct pairs- a. getKeyLocation() i. Set the keyCode value to indicate a
physical key.
b. getKeyCode() ii. Returns the character associated with the key in this event. c.
getKeyChar() iii. Returnsthe location of the key that originated this key event. d.
setKeyCode(int keyCode) iv. Returns the integer keyCode associated with the key in this
event.

A) d-i, c-ii, a-iii, b-iv B) d-ii, c-i, a-iii,


b-iv C) d-i, c-ii, a-iv, b-iii D) d-iv, c-ii, a-iii,
b-i

Q72. Which of the following statements is true?

A) keyTyped() is method of KeyListerner Interface

B) keyTyped() is method of MouseListener Interface

C)keyTyped() is method of ActionListener Interface

D) keyTyped() is method of KeyBoardListener Interface


Q73. Which of the following option is true?

A) keyReleased() is method of KeyListerner Interface

B) keyReleased() is method of MouseListener Interface

C) keyReleased() is method of ActionListener Interface

D) keyReleased() is method of KeyBoardListener Interface

Q74. Select correct general form of Mouse Entered method of Mouse Listener interface.

A) void mouseEntered(mouseEvent me) B) void MouseEntered(mouseEvent


me) C) void MouseEntered(MouseEvent me) D) void mouseEntered(MouseEvent
me)
Q75. Consider following code segment-
1. public void mouseClicked(MouseEvent event){
2. setBackground(Color.blue);
3.int x = event.getX();
4.int y = event.getY();
5.int c = getClickCount( );
6. }
Which statement is true?

A) There are syntax errors on line no. 1 B) There are syntax errors on line
no. 2 C) There are syntax errors on line no . 4 D) There are syntax errors on line no.
5
Q76. Consider following code segment-
public void mousePressed(MouseEvent event)
{
System.out.println(event.getPoint());
}
Following code segement output is-

A) Print value of x and y co-ordinates B) Print value of x co-


ordinates C) Print value of y co-ordinates D)Print value of event object.
Q77. Consider following code segment-
1. public void mouseClicked(MouseEvent event) {
2. // Line 2
3. }

Following code segment, identify statement to print co-ordinates –

A) int p = getLocationOnScreen( ); B) Point p =


getLocationOnScreen( ); C) int x,y = getLocationOnScreen( ); D)
None of above
Q78. Write the correct code at blank space:
public class extends Frame implementsWindowListener
{
WindowExample()
{
addWindowListener(this);
setSize(400,400);
setLayout(null);
setVisible(true);
}
public static void main(String[] args)
{
new WindowExample();
}
A) addWindowListener B) WindowExample
C) Window D)
WindowListener

Q79. Which top-level class provides methods to add and remove keyboard and mouse event
listeners-

A) Object B) ActionEvent C) EventObject D)


Component

Q80. The translatePoint( ) method-

A) changes the location of the event. B) changes x co-ordinates of the


event. C) changes y co-ordinatesof the event. D) returns the translate
co-ordinates.

Q81. How many method define in FocusListener interface

A) one B) two C) four D)


seven

Q82. How many method define in ContainerListener interface.

A) seven B) two C) five D) one

Q83. ItemEvent constructor- ItemEvent(ItemSelectable src, int type, Object entry, int state)
Here entrymeans......

A) The specific item that generated the item event is passed

B) The type of object

C) a reference to the component that generated event


D) The current state of that item.

Q84. The example of user interface elements that implement the ItemSelectable interface-

A) Choices and TextBox B) TextBox and Lists


C) Lists and choices D) Lists and canvas

Q85. Consider the following code segment. Insert correct code at blank space.

checkbox. (new ItemListener()

public void (ItemEvent ie)

if (checkbox.getState() == true)

JOptionPane.showMessageDialog(null, "checkbox is checked");

else

JOptionPane.showMessageDialog(null, "checkbox is unchecked");

});

A) itemStateChanged, addItem B) ItemListener,


itemChanged C) StateChanged, addItem D)
addItemListener, itemStateChanged

Q86. 1. import java.awt.*;


2. import java.awt.event.*;
3. public class ItemEx1 implements ItemListener {
4. Frame jf;
5. Checkbox chk1, chk2;
6. Label label1;
7. ItemEx1() {
8. jf= new Frame("Checkbox");
9. chk1= new Checkbox("Happy");
10. chk2 = new Checkbox("Sad");
11. label1 = new Label();
12. jf.add(chk1);
13.jf.add(chk2);
14. chk1.addItemListener(this);
15. chk2.addItemListener(this);
16. jf.setLayout(new FlowLayout());
17. jf.setSize(220,150);
18. jf.setVisible(true);
19. }
20. // Line no 20
21. Checkbox ch =(Checkbox) ie.getItemSelectable();
22. if(ch.getState()==true) {
23. label1.setText(ch.getLabel()+ " is checked");
24. jf.add(label1);
25. jf.setVisible(true);
26 }
27 else {
28 label1.setText(ch.getLabel()+ " is unchecked");
29 jf.add(label1);
30 jf.setVisible(true);
31 }
32 }
33 public static void main(String... ar) {
34 newItemEx1();
35 }
36 }
Identify correct code at line no 20

A) public void itemModified(ItemEvent ie) {

B) public void itemStateSelectable(ItemEvent ie) {

C) public void itemChange(ItemEvent ie) {

D) public void itemStateChanged(ItemEvent ie) {

Q87. 1. public void itemStateChanged(ItemEvent ie) {

2. Checkbox ch = (Checkbox)ie.setItemSelectable();
3. if(ch.getState()==true) {

4. label1.setText(ch.getLabel()+ " is checked");


5. jf.add(label1);

6. jf.setVisible(true);

7 .}

Which statement is true ?

A) There are syntax errors on line no. 1

B) There are syntax errors on line no. 2

C) There are syntax errors on line no. 4

D) There are syntax errors on line no. 6

Q88. 1. public void itemStateChanged(ItemEvent ie ) {

2. JCheckBox cb = (JCheckBox) ie.getItem( );

3.int state ie.getStateChange( );

4. // Line no 4

5. System.out.println(cb.getText( ) + "selected");

6. else

7.System.out.println(cb.getText( ) + "cleared");

8. }

Identify correct code at line no 4


A) if (state == ItemEvent.Change) B) if (state ==
ItemEvent.Modified) C) if (state == ItemEvent.SELECTED) D) if (state ==
ItemEvent.getText)

Q89. Interface MouseMotionListener belongs to package.

A) java.listener B) java.util.event C) java.awt.event D)


java.motion

Q90. A source is an that generates an event .

A) class B) interface C) object D) variable

Q91. KeyEvent Constructor- KeyEvent(Component src, int type, long when, int modifiers, int
code, charch) Here when means-
A) a reference to the component that generated the event. B) The type of event
occured. C) virtual key codes D) The system time at which the key
was pressed.

Q92. MouseEvent Constructor- MouseEvent(Component src, in type, long when, int


modifiers, int x, int y, int clicks, boolean triggersPopup) Here x and y means-

A) co-ordinates of the mouse passed B) The click count


C) Reference to the component D) The systemtime at which the
mouse event occured.

Q93. windowClosing() is method of interface

A) WindowListener Interface B) Window


Interface C) WindowConified Interface D) Action
Interface

Q94. windowDeactivated() is method of interface

A) WindowListener Interface B) Window


Interface C) WindowConified Interface D)
Action Interface

Q95. mouseEntered() is method of interface .

A) Mouse Interface B) MouseMotionListener Interface


C) MouseEntered Interface D) MouseListenerInterface

Q96. Which of the following statements are true? 1) The MouseMotionListener interface
defines methods for handling mouse clicks. 2) The ActionListener interface defines methods
for handling the clicking of a button. 3) The MouseClickListener interface defines methods
for handling mouse clicks. 4) TheMouseListener interface defines methods for handling
mouse dragged

A) Statement 1 and 3 are true B) Only first statement is


true C) Only second statement is true D) Allstatements
are true

Q97. Which of the following statements are false 1)windowlistener define seven method
2)mouseMotionListerne define 2 method 3) ActionListener Interace defines three method to
receive actionevent 4)KeyListener Interface define Three method

A) Statement 1 is false B) Statement 2 is false


C) Statement 3 is false D)
Statement 4 is false
Q98. Consider following two statement 1) Implement the Listener interface and overrides its
methods isrequired to perform in event handling. 2) ActionListener Interace defines one
method to receive action event

A) Only first statement is true B) Only second


statement is true C) Both statements are true D) Both
statements are False

Q99. The WindowEvent class, WINDOW_DEICONIFIED, integer constants meaning-

A) Reducing the window to an icon on the desktop

B) The window which contains the focus owner.

C)Showing a window for the first time.

D) Restoring the window to its original size.

Q100. WindowEvent Constructor- WindowEvent(Window src, int type, Window other, int
fromState, inttoState) Here fromState means-

A) the new state of the window B) prior state of the


window. C) opposite window when a focus or activation event occurs.

D) reference to the object that generated this event.

You might also like