Skip to main content

Important Web Design and Development Short Questions

Chapter: 11
Question 1:
What is the purpose of the addActionListener method in Java Swing components?
Answer: The addActionListener method registers an event handler (listener) with a Swing component so that the handler can respond to events generated by that component, such as button clicks.
Chapter: 11
Question 2:
How does the JVM handle events in Java?
Answer: The JVM receives events generated by components, places them in an event queue, and processes them by dispatching them to the registered listeners. If no listeners are registered, the event is discarded.
Chapter: 11
Question 3:
In the Small Calculator example, how does the application determine which button was pressed?
Answer: The application uses the getSource() method on the ActionEvent object to determine which button generated the event, allowing it to perform the appropriate action (addition or multiplication).
Chapter: 11
Question 4:
What method must be overridden to handle events when using the ActionListener interface?
Answer: The actionPerformed() method must be overridden to handle events when using the ActionListener interface. This method defines what should happen in response to an action event.
Chapter: 11
Question 5:
Explain the purpose of initGUI() in the provided code examples.
Answer: The initGUI() method sets up the graphical user interface by creating and arranging components, setting their properties, and adding event listeners to handle user interactions.
Chapter: 11
Question 6:
What role do event objects play in event handling?
Answer: Event objects encapsulate information about an event, such as the type of event and the source of the event, allowing event handlers to respond appropriately to different types of events.
Chapter: 12
Question 7:
What are the two types of listener interfaces available for handling mouse events in Java?
Answer: The two types of listener interfaces for handling mouse events in Java are MouseMotionListener for mouse movement events and MouseListener for more specific mouse actions like clicks and presses.
Chapter: 12
Question 8:
What methods are defined in the MouseMotionListener interface?
Answer: The MouseMotionListener interface defines two methods: mouseDragged(MouseEvent me) for handling mouse dragging and mouseMoved(MouseEvent me) for handling mouse movement.
Chapter: 12
Question 9:
How does the MouseListener interface differ from MouseMotionListener?
Answer: The MouseListener interface handles specific mouse actions such as clicks, presses, and cursor entering or exiting a component, whereas MouseMotionListener handles events related to mouse movement.
Chapter: 12
Question 10:
In the EventsEx example, what is the purpose of the mouseDragged method?
Answer: The mouseDragged method in the EventsEx example updates a label with the coordinates of the mouse whenever it is dragged, showing the location where the dragging occurred.