0% found this document useful (0 votes)
13 views5 pages

Unit V Java

JAVA CONCEPTS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views5 pages

Unit V Java

JAVA CONCEPTS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

UNIT V

MCQs

Swing Basics

1. What is Swing in Java?


a) A framework for creating console applications
b) A GUI toolkit for creating window-based applications
c) A database management tool
d) A thread management library
Answer: b

2. Which package contains the Swing classes?


a) java.awt
b) javax.swing
c) java.swing
d) javax.awt
Answer: b

3. What is the base class for all Swing components?


a) JComponent
b) Component
c) Container
d) Object
Answer: a

4. Which of the following is not a top-level container in Swing?


a) JFrame
b) JPanel
c) JWindow
d) JDialog
Answer: b

5. Which method is used to make a JFrame visible?


a) show()
b) setVisible()
c) display()
d) setShow()
Answer: b

6. What is the default layout manager for a JFrame?


a) FlowLayout
b) BorderLayout
c) GridLayout
d) BoxLayout
Answer: b

7. Which component is used to create a button in Swing?


a) JButton
b) JToggleButton
c) JRadioButton
d) JCheckBox
Answer: a

8. What is the main difference between a JCheckBox and a JRadioButton?


a) JCheckBox allows multiple selections; JRadioButton allows only one selection in a group
b) JRadioButton allows multiple selections; JCheckBox allows only one selection
c) Both are identical
d) JCheckBox is used for text input
Answer: a

9. Which component is used to create a drop-down list in Swing?


a) JList
b) JComboBox
c) JTextField
d) JTextArea
Answer: b

10. Which Swing component is used to create a scrollable area?


a) JScrollPane
b) JViewport
c) JScrollBar
d) JPanel
Answer: a

Swing Components

11. Which method is used to set the text of a JLabel?


a) setText()
b) setLabel()
c) setContent()
d) setValue()
Answer: a

12. What is the purpose of a JTextField?


a) To display a list of items
b) To allow single-line text input
c) To allow multi-line text input
d) To display a scrollable text area
Answer: b

13. Which component allows multi-line text input?


a) JTextField
b) JTextArea
c) JLabel
d) JEditorPane
Answer: b
14. Which method is used to add items to a JList?
a) addItem()
b) addElement()
c) setListData()
d) add()
Answer: c

15. What is the purpose of a JPanel in Swing?


a) To create a top-level window
b) To group components together
c) To display text
d) To handle events
Answer: b

16. Which component is used to create a toggle button in Swing?


a) JButton
b) JToggleButton
c) JCheckBox
d) JRadioButton
Answer: b

17. What is the default layout manager for a JPanel?


a) FlowLayout
b) BorderLayout
c) GridLayout
d) BoxLayout
Answer: a

18. Which method is used to add components to a JFrame?


a) addComponent()
b) add()
c) append()
d) insert()
Answer: b

19. Which component is used for a scrollable text area?


a) JTextArea with JScrollPane
b) JTextField
c) JLabel
d) JComboBox
Answer: a

20. Which class is used to create a modal dialog box in Swing?


a) JDialog
b) JFrame
c) JOptionPane
d) JPanel
Answer: a
Swing Features

21. What is the role of a content pane in Swing?


a) To manage the layout of components
b) To handle events
c) To display menus
d) To act as the main container for components
Answer: d

22. Which method is used to set the size of a JFrame?


a) setDimensions()
b) setBounds()
c) setSize()
d) setLayout()
Answer: c

23. Which method is used to close a JFrame?


a) dispose()
b) close()
c) exit()
d) terminate()
Answer: a

24. What is the purpose of a JScrollBar?


a) To create a scrollable text area
b) To add scrolling functionality to components
c) To create a standalone scrollbar
d) To manage scroll events
Answer: c

25. Which Swing component allows users to select multiple items from a list?
a) JList
b) JComboBox
c) JTextArea
d) JCheckBox
Answer: a

5-Mark Questions

1. Explain the Swing hierarchy with a diagram.

2. Write a program to create a simple GUI with a JLabel and a JButton.

3. What are the differences between AWT and Swing?

4. Describe the purpose and usage of JScrollPane in Swing.

5. Write a program to demonstrate the use of JCheckBox and JRadioButton in Swing.

10-Mark Questions
1. Write a program to create a JFrame with JTextField, JTextArea, and JButton. Implement an
ActionListener to display the text entered in JTextField into JTextArea.

2. Explain the purpose and features of top-level containers in Swing. Provide examples for
JFrame, JDialog, and JWindow.

3. Write a program to create a JComboBox and JList. Display the selected item from
JComboBox into JList.

4. Discuss the purpose of JPanel and layout managers in Swing. Write a program to
demonstrate the use of JPanel with BorderLayout.

5. Write a program to create a scrollable JTextArea using JScrollPane. Explain the code.

You might also like