Unit 2: GUI and Event Handling - Subjective Questions

CSE406 — Advanced Java Programming • Practice Questions with Detailed Answers

20 questions

1

Define Swing in Java. Explain its main features and advantages over AWT.

2

Explain the purpose and structure of JFrame and JPanel in a Swing application.

3

Describe any five commonly used Swing components and explain their purposes.

4

Explain the concept of layout managers in Swing. Compare FlowLayout, BorderLayout, and GridLayout.

5

Explain the Color class in Java Swing. Describe how colors can be created and applied to components.

6

Explain the Font class and describe the significance of font name, style, and size in GUI programming.

7

Describe the role of the Graphics class in Swing. Explain the use of paintComponent() in a custom panel.

8

Write and explain a Java Swing program that creates a window containing a label, a text field, and a button.

9

Explain the event delegation model in Java. Identify the roles of an event source, event object, and event listener.

10

Distinguish between an event source and an event object with suitable examples.

11

Describe the important event listener interfaces used in Swing and state the purpose of each.

12

Explain the process of registering and handling an event in Swing. Illustrate it using ActionListener.

13

Explain mouse events in Swing. Describe the methods of MouseListener and MouseMotionListener.

14

Write a Java Swing program that displays the coordinates of the mouse pointer when it is clicked on a panel.

15

Explain key events in Java Swing. Differentiate among keyPressed, keyReleased, and keyTyped.

16

Write and explain a Swing program that responds to keyboard events by displaying the pressed key.

17

What is an anonymous class listener? Explain its use in event handling with an example.

18

Explain listener adapter classes. Why are they useful when handling mouse or window events?

19

Compare implementing a listener interface, extending an adapter class, and using a lambda expression for Swing event handling.

20

Design a Swing GUI for a simple calculator and explain the roles of its components, layout manager, and event handlers.