Web Design and Development MCQs with Answers
Practice important Web Design and Development MCQs with answers and explanations.
Chapter: 10
Q161:
Which package contains the original GUI components in Java?
A. java.awt
B. java.swing
C. java.util
D. java.io
Correct Answer:
A
Chapter: 10
Q162:
What method is used to make a JFrame visible?
A. setSize
B. setVisible
C. setLayout
D. addComponent
Correct Answer:
B
Chapter: 10
Q163:
Which layout manager arranges components in rows and columns?
A. FlowLayout
B. GridLayout
C. BorderLayout
D. BoxLayout
Correct Answer:
B
Chapter: 10
Q164:
What does a BorderLayout divide the window into?
A. Four regions
B. Three regions
C. Five regions
D. Six regions
Correct Answer:
C
Chapter: 10
Q165:
Which of the following is a Light Weight Component in Swing?
A. JFrame
B. JButton
C. TextField
D. Container
Correct Answer:
B
Chapter: 10
Q166:
What is the purpose of the getContentPane() method in JFrame?
A. Get the top-level container
B. Get the component area
C. Get the layout manager
D. Get the window title
Correct Answer:
B
Chapter: 10
Q167:
How do you specify the layout manager for a Container?
A. setLayout( new FlowLayout() )
B. setSize(new FlowLayout())
C. setLayoutManager(new FlowLayout())
D. setComponents(new FlowLayout())
Correct Answer:
A
Chapter: 10
Q168:
Which layout manager is used to place components in a grid?
A. FlowLayout
B. GridLayout
C. BorderLayout
D. BoxLayout
Correct Answer:
B
Chapter: 10
Q169:
In BorderLayout, where does the CENTER component go?
A. At the top of the window
B. At the bottom of the window
C. In the center of the window
D. At the left of the window
Correct Answer:
C
Chapter: 10
Q170:
How do you add a JButton to a JPanel in Swing?
A. myPanel.add(button)
B. myPanel.addComponent(button)
C. myPanel.setComponent(button)
D. myPanel.insert(button)
Correct Answer:
A
Chapter: 10
Q171:
What is a JPanel used for in Java Swing?
A. To hold other components
B. To handle events
C. To manage layout of a window
D. To create a new window
Correct Answer:
A
Chapter: 11
Q172:
How do you create a JFrame instance in Java?
A. JFrame frame = new JFrame();
B. JFrame frame = new JFrame("Title");
C. JFrame frame = new JFrame("Title", true);
D. JFrame frame = JFrame();
Correct Answer:
A
Chapter: 11
Q173:
Which layout manager arranges components in a line by line basis?
A. FlowLayout
B. GridLayout
C. BorderLayout
D. CardLayout
Correct Answer:
A
Chapter: 11
Q174:
What method is used to set the size of a JFrame?
A. setSize
B. setDimensions
C. setBounds
D. setHeight
Correct Answer:
A
Chapter: 11
Q175:
What is the purpose of the Event Delegation Model in Java?
A. To process all events in one class
B. To delegate event processing to specific handlers
C. To handle events synchronously
D. To avoid using listeners
Correct Answer:
B
Chapter: 11
Q176:
Which package contains event listener interfaces for AWT components?
A. javax.swing.event
B. java.awt
C. java.swing
D. java.awt.event
Correct Answer:
D
Chapter: 11
Q177:
What does the ActionListener interface handle?
A. Mouse events
B. Window events
C. Action events
D. Key events
Correct Answer:
C
Chapter: 11
Q178:
What method must be implemented when a class implements ActionListener?
A. actionPerformed(ActionEvent e)
B. handleEvent(Event e)
C. processAction(ActionEvent e)
D. eventOccurred(ActionEvent e)
Correct Answer:
A
Chapter: 11
Q179:
Which class is used to create a button in Swing?
A. JButton
B. JButtonAction
C. Button
D. SwingButton
Correct Answer:
A
Chapter: 11
Q180:
What is the role of addActionListener() method in Swing?
A. To add a new button to the frame
B. To register an event handler with a button
C. To change the button’s text
D. To remove an event listener from a button
Correct Answer:
B