NPTEL Programming In Java Week 9 Assignment Answers 2024
1. What is the parent class of all AWT components?
a. java.awt.Panel
b. java.awt.Component
c. java.awt.Container
d. java.awt.Frame
Answer :- b
Explanation:java.awt.Component
is the superclass for all AWT components like Button, Label, TextField, etc. Every AWT component inherits from this class.
2. Which event is generated when a user clicks a button in AWT?
a. MouseEvent
b. ActionListener
c. KeyEvent
d. WindowEvent
Answer :- b
Explanation:
When a user clicks a button, an ActionEvent
is generated. This event is handled by implementing the ActionListener
interface.
3. Which of the following architecture does the Swing framework use?
a. MVC
b. MVP
c. Layered architecture
d. Master-Slave architecture
Answer :- a
Explanation:
Swing follows the Model-View-Controller (MVC) architecture, which separates data (Model), UI (View), and user interaction (Controller).
4. A _________ is the basic class for all SWING UI components?
a. Container
b. JComponent
c. Component
d. Jbox
Answer :- b
Explanation:JComponent
is the base class for all Swing components like JButton
, JLabel
, JTextField
, etc.
5. Which event is generated when a window is resized in AWT?
a. WindowEvent
b. ComponentEvent
c. ResizeEvent
d. ContainerEvent
Answer :- b
Explanation:
Resizing a window triggers a ComponentEvent
, since the window is treated as a component and resizing changes its properties.
6. Which method is used to remove a component from a container in AWT?
a. remove()
b. deleteComponent()
c. removeComponent()
d. destroy()
Answer :- a
Explanation:remove()
is a method in the Container
class that removes a component from a container.
7. What is true about the following code.
a. Both “OK” and “Cancel” button is added, but only “Cancel” button is visble.
b. Only “OK” button is added and visible, “Cancel” button is not added.
c. Only “Cancel” button will be added and visible, “OK” button is not added.
d. Code throws an ERROR.
Answer :- a
Explanation:
If a layout like BorderLayout
is used, and multiple components are added in the same region (e.g., BorderLayout.SOUTH
), the last added component (like “Cancel”) will replace the earlier one (like “OK”).
8. Which of the following function is used to generate the application’s top-level window?
a. JPanel
b. JFrame
c. JCombo
d. JBox
Answer :- b
Explanation:JFrame
is the top-level window class in Swing used to create the main window of an application.
9. In Java, what is the primary purpose of a layout manager?
a. To manage memory allocation
b. To arrange GUI components within a container
c. To handle exception handling
d. To control database connections
Answer :- b
Explanation:
A layout manager is used to automatically position and size components within a container according to a specific layout policy.
10. Which layout manager divides the container into five regions: North, South, East, West, and Center?
a. Border Layout
b. Grid Layout
c. Flow Layout
d. Card Layout
Answer :- a
Explanation:BorderLayout
divides the container into five regions. You can add components to any of these five: NORTH, SOUTH, EAST, WEST, CENTER.