Unit Iv Java
Unit Iv Java
MCQs
AWT Controls
1. What does AWT stand for in Java?
a) Abstract Window Toolkit
b) Advanced Window Toolkit
c) Abstract Widget Toolkit
d) Advanced Widget Toolkit
Answer: a
2. Which class is the root of the AWT class hierarchy?
a) Component
b) Container
c) Object
d) Window
Answer: a
3. Which AWT component is used to display a short text string?
a) Label
b) Button
c) TextField
d) TextArea
Answer: a
4. Which method is used to set the text of a Button in AWT?
a) setLabel()
b) setText()
c) setButtonText()
d) setValue()
Answer: a
5. What is the purpose of a CheckboxGroup in AWT?
a) To group multiple checkboxes together
b) To allow only one checkbox to be selected at a time
c) To disable all checkboxes in a group
d) To align checkboxes horizontally
Answer: b
6. Which AWT component allows the user to select one item from a
drop-down list?
a) Choice
b) List
c) TextField
d) Checkbox
Answer: a
7. What is the difference between a List and a Choice in AWT?
a) List allows multiple selections; Choice allows only one selection
b) Choice allows multiple selections; List allows only one selection
c) Both allow multiple selections
d) Both allow only one selection
Answer: a
8. Which AWT container is used to group components together?
a) Panel
b) Frame
c) Window
d) Canvas
Answer: a
9. What is the primary purpose of a ScrollPane in AWT?
a) To add scrolling functionality to components
b) To group multiple components
c) To resize components dynamically
d) To display menus
Answer: a
10.Which class is used to create a top-level window in AWT?
a) Frame
b) Panel
c) Container
d) Window
Answer: a
11.Which layout manager arranges components in a single row or
column?
a) FlowLayout
b) BorderLayout
c) GridLayout
d) BoxLayout
Answer: d
12.Which layout manager divides the container into five regions?
a) GridLayout
b) BorderLayout
c) CardLayout
d) FlowLayout
Answer: b
13.Which method is used to set the background color of a component?
a) setBackground()
b) setColor()
c) setBGColor()
d) setStyle()
Answer: a
14.Which AWT class is used to handle fonts?
a) Font
b) Text
c) Label
d) Graphics
Answer: a
Event Handling
15.Which package contains classes for event handling in Java?
a) java.util
b) java.awt.event
c) java.event
d) java.swing
Answer: b
16.What is an event in Java?
a) An object that describes a state change in a source
b) A method to handle user input
c) A thread for GUI updates
d) None of the above
Answer: a
17.Which interface must be implemented to handle ActionEvents?
a) ActionListener
b) EventListener
c) ActionEventHandler
d) ActionHandler
Answer: a
18.What is the Event Delegation Model (EDM)?
a) A design pattern for managing events
b) A model where events are delegated to listeners
c) A way to handle threads in AWT
d) A model for managing layout
Answer: b
19.Which method is used to register a listener for an event?
a) addEvent()
b) addListener()
c) addActionListener()
d) handleEvent()
Answer: c
20.Which adapter class is used to handle mouse events?
a) MouseAdapter
b) MouseListener
c) MouseEvent
d) MouseHandler
Answer: a
21.What is the purpose of an adapter class in event handling?
a) To provide default implementations for listener interfaces
b) To handle multiple events simultaneously
c) To simplify layout management
d) To create custom events
Answer: a
22.Which method is called when a key is typed?
a) keyPressed()
b) keyReleased()
c) keyTyped()
d) None of the above
Answer: c
23.Which event is triggered when a Button is clicked?
a) ActionEvent
b) MouseEvent
c) KeyEvent
d) WindowEvent
Answer: a
24.Inner classes in event handling are used for:
a) Encapsulation of event handling code
b) Managing threads
c) Handling multiple layouts
d) None of the above
Answer: a
25.Which method is used to handle a window closing event?
a) windowClosed()
b) windowClosing()
c) closeWindow()
d) endWindow()
Answer: b
5-Mark Questions
1. Explain the AWT class hierarchy with a diagram.
2. Write a program to create a simple GUI with a Label and a Button.
3. What is the role of layout managers in AWT? Explain with examples.
4. Describe the Event Delegation Model (EDM) in Java.
5. Write a program to demonstrate the use of a CheckboxGroup in
AWT.
10-Mark Questions
1. Write a program to create a Frame with a Menu and MenuItems.
Explain the code.
2. Explain the process of handling mouse events in Java. Write a
program to demonstrate mouseClicked and mouseMoved events.
3. Describe the working of adapter classes with an example.
4. Write a program to demonstrate the use of inner classes for handling
ActionEvents in AWT.
5. Discuss the various layout managers in AWT with examples of how
they arrange components.