Sanjivani Rural Education Society’s
SANJIVANI K. B. P. POLYTECHNIC
Department of Computer Technology
KOPARGAON – 423601, DIST: AHMEDNAGAR
2023-2024
Class Test: [Unit III-Event Handling] Date: / /2023
Name : Set: I
Roll No :
1. Which of the following is the top-level interface for handling events in Java
a) EventListener b) EventObject c) ActionEvent d) WindowEvent
2. Which method is invoked when an action is performed on a button
a) actionPerformed() b) itemStateChanged() c) mouseClicked() d) windowClosed()
3. Which package contains the event handling classes in Java?
a) java.io b) java.util c) java.awt.event d) java.net
4. Which interface should be implemented to handle keyboard events in Java?
a) MouseListener b) KeyListener c) ActionListener d) FocusListener
5. What does the addActionListener method do?
a) Adds a listener for mouse events b) Adds a listener for key events
c) Adds a listener for action events d) Adds a listener for focus events
6. Which of the following methods is used to handle mouse click events?
a) mouseClicked() b) mousePressed() c) mouseReleased() d) All of the above
7. What is the purpose of the WindowAdapter class?
a) To handle key events b) To provide default implementations for window events
c) To create window components d) To handle action events
8. Which event is generated when a component gains focus?
a) KeyEvent b) FocusEvent c) ActionEvent d) MouseEvent
9. Which method is invoked when a component is resized?
a) componentResized() b) componentMoved() c) componentHidden() d) componentShown()
10. Which event class is used to handle mouse motion events?
a) MouseEvent b) MouseMotionEvent c) MouseMotionListener d) MouseAdapter
11. What is the return type of the getSource() methodl in event handling?
a) Object b) String c) int d) Event
12. Which interface is used to handle events related to items in a component like checkboxes?
a) ItemListener b) ActionListener c) KeyListener d) WindowListener
13. What is the function of the dispatchEvent() method?
a) To generate an event b) To delegate event handling to another object c) To terminate event processing
d) To queue an event for later processing
14. Which of the following methods is part of the WindowListener interface?
a) windowOpened() b) windowClosed() c) windowClosing() d) All of the above
15. Which event occurs when a user presses and releases a key?
a) KeyPressed b) KeyReleased c) KeyTyped d) All of the above
16. Which class is used as a base class for all AWT events?
a) EventObject b) ActionEvent c) AWTEvent d) Event
17. What is the purpose of the EventQueue class in Java?
a) To hold all events b) To synchronize event handling
c) To manage the order of event processing d) To dispatch events to listeners
18. Which listener interface handles the movement of a window?
a) ComponentListener b) WindowListener c) MouseMotionListener d) ActionListener
19. Which of the following methods is used to remove an action listener from a button?
a) removeActionListener() b) deleteActionListener() c) unregisterActionListener()d) detachActionListener()
20. What does the isConsumed() method in an event object indicate?
a) Whether the event has been processed
b) Whether the event should be ignored
c) Whether the event is still in the queue
d) Whether the event source is null
21.Which class is the base class for all event classes in Java?
a) EventObject b) AWTEvent c) ComponentEvent d) ActionEvent
22. Which interface is used to handle action events in Java?
a) ActionListener b) MouseListener c) KeyListener d) WindowListener
23. Which method must be implemented when using the ActionListener interface?
a) actionPerformed() b) actionEvent() c) actionTriggered() d) performAction()
24. What is the purpose of the addActionListener method?
a) To register a component for mouse events b) To add a component to a container
c) To register an action listener with a component d) To remove an action listener from a component
25.Which of the following is a valid event type for the MouseListener interface?
a) mouseClicked b) keyPressed c) componentResized d) windowClosed
26.What is the purpose of the mouseReleased method in the MouseListener interface?
a) To handle mouse button presses b) To handle mouse movements
c) To handle mouse button releases d) To handle mouse clicks
27.Which interface is used to handle keyboard events in Java?
a) KeyListener b) KeyEvent c) KeyAdapter d) KeyEventListener
28.Which method in the WindowListener interface is called when a window is closed?
a) windowClosing b) windowClosed c) windowActivated d) windowDeactivated
29.What is the use of the ComponentAdapter class?
a) To handle mouse events b) To handle key events
c) To provide empty implementations of the ComponentListener methods d) To handle window events
30. In Java Swing, which class provides the JButton component?
a) javax.swing.JButton b) javax.swing.JButtonComponent c) java.awt.JButton d) javax.swing.AbstractButton
31.Which method is used to set the title of a JFrame?
a) setWindowTitle() b) setTitle() c) changeTitle() d) updateTitle()
32.What event does the windowStateChanged method handle?
a) When the window is resized b) When the window state changes (e.g., maximized or minimized)
c) When the window is moved d) When the window is activated
33.Which interface provides a method for handling focus events?
a) FocusListener b) FocusEvent c) FocusAdapter d) FocusHandler
34.How can you listen to a JTextField for user input?
a) Add a FocusListener to the JTextField b) Add an ActionListener to the JTextField
c) Add a MouseListener to the JTextField d) Add a WindowListener to the JTextField
35.Which method in the ActionEvent class retrieves the command string associated with the event?
a) getActionCommand() b) getCommand() c) retrieveCommand() d) getEventCommand()
36.Which method in the MouseAdapter class is used to handle mouse clicked events?
a) mouseClicked() b) mousePressed() c) mouseReleased() d) mouseEntered()
37.What is the default event handling model for Swing components?
a) Event delegation model b) Event broadcasting model c) Event handling model d) Event propagation model
38.Which class is used to create a graphical user interface window in Java Swing?
a) JFrame b) JPanel c) JWindow d) JFrameWindow
39.How do you handle changes in the size of a component in Java?
a) By implementing the ComponentListener interface b) By implementing the ContainerListener interface
c) By using a ComponentAdapter d) Both a) and c)
40.Which method in the ItemListener interface handles item state changes?
a) itemStateChanged() b) itemChanged() c) stateChanged() d) itemSelected()
41. Which class is used to create a menu item in Swing?
a) JMenuItem b) JMenu c) JMenuBar d) JMenuComponent
42.Which method in the WindowAdapter class is called when a window is minimized?
a) windowIconified() b) windowMinimized() c) windowClosed() d) windowDeiconified()
43.Which interface should be implemented to handle mouse drag events?
a) MouseMotionListener b) MouseDragListener c) MouseEventListener d) MouseInputListener
44.Which method in FocusListener is called when a component gains focus?
a) focusGained() b) focusAcquired() c) focusReceived() d) focusObtained()
45. Which class provides an implementation for the WindowListener interface in an adapter form?
a) WindowAdapter b) WindowHandler c) WindowListenerAdapter d) WindowEventAdapter
46.How do you register a MouseListener with a component?
a) component.addMouseListener(new MouseListenerImplementation());
b) component.addMouseListener(MouseListenerImplementation.getInstance());
c) component.registerMouseListener(new MouseListenerImplementation());
d) component.setMouseListener(new MouseListenerImplementation());
47.What does the windowOpened() method of WindowListener do?
a) It is called when a window is first opened b) It is called when a window is minimized
c) It is called when a window is closed d) It is called when a window is activated
48.Which event is generated when a component is resized?
a) ComponentEvent b) ResizeEvent c) SizeEvent d) ComponentResizedEvent
49. Which method in the MouseMotionListener interface is invoked when the mouse is dragged?
a) mouseDragged() b) mouseMoved() c) mousePressed() d) mouseReleased()
50.How can you listen for changes in the state of a checkbox in Swing?
a) Implement ItemListener and register it with the checkbox
b) Implement ActionListener and register it with the checkbox
c) Implement FocusListener and register it with the checkbox
d) Implement MouseListener and register it with the checkbox