0% found this document useful (0 votes)
12 views9 pages

Ajp Answers

Uploaded by

akhileshgawade10
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)
12 views9 pages

Ajp Answers

Uploaded by

akhileshgawade10
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/ 9

1. Which class is the top-level window in Java Swing?

A) JFrame

B) JPanel

C) JWindow

D) JComponent

Answer: A) JFrame

2. Which of the following is used to create a button in


Java Swing?

A) JButton

B) JTextField

C) JPasswordField

D) JRadioButton

Answer: A) JButton

3. In which package is Swing included?

A) java.util

B) java.awt

C) javax.swing

D) java.io

Answer: C) javax.swing

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

A) setVisible()

B) show()

C) setDisplay()

D) setFrame()
Answer: A) setVisible()

5. Which layout manager arranges components in a row,


either horizontally or vertically?

A) BorderLayout

B) FlowLayout

C) GridLayout

D) BoxLayout

Answer: D) BoxLayout

6. What is the default layout for a JFrame?

A) FlowLayout

B) GridLayout

C) BorderLayout

D) BoxLayout

Answer: C) BorderLayout

7. Which method is used to add a component to a


container in Swing?

A) put()

B) add()

C) insert()

D) attach()

Answer: B) add()

8. Which component is used for accepting user input in


the form of text?

A) JLabel

B) JTextField
C) JButton

D) JPanel

Answer: B) JTextField

9. Which class provides a prompt for the user to select


files in Java Swing?

A) JFileChooser

B) FileDialog

C) JDialog

D) JColorChooser

Answer: A) JFileChooser

10. How can you create a pop-up dialog box in Swing?

A) JOptionPane

B) JPopupMenu

C) JDialogBox

D) JPopupBox

Answer: A) JOptionPane

11. What does dispose() method do in a JFrame?

A) Closes the JFrame but keeps the application running

B) Closes the JFrame and terminates the program

C) Minimizes the JFrame

D) Sets the JFrame as invisible

Answer: A) Closes the JFrame but keeps the application running

12. Which of the following is not a Swing component?

A) JPanel
B) JTable

C) JTextArea

D) List

Answer: D) List

13. Which method is used to set the title of a JFrame?

A) setTitle()

B) setText()

C) setHeader()

D) setName()

Answer: A) setTitle()

14. Which method is used to set the background color of


a component in Swing?

A) setBackground()

B) setColor()

C) setFill()

D) setBgColor()

Answer: A) setBackground()

15. What is the correct sequence of events in the Event


Delegation Model?

A) Event Source -> Event Listener -> Event Object

B) Event Listener -> Event Source -> Event Object

C) Event Object -> Event Listener -> Event Source

D) Event Source -> Event Object -> Event Listener

Answer: D) Event Source -> Event Object -> Event Listener


16. Which of the following is used to create a text area
in Swing?

A) JTextArea

B) JLabel

C) JList

D) JTextField

Answer: A) JTextArea

17. Which method is used to add an ActionListener to a


JButton?

A) addButtonListener()

B) addActionListener()

C) setListener()

D) buttonAction()

Answer: B) addActionListener()

18. Which Swing component allows users to choose from


a list of items?

A) JComboBox

B) JList

C) JTable

D) JPanel

Answer: A) JComboBox

19. Which method is used to create a tool tip in Swing


components?

A) setToolTipText()

B) setTipText()
C) createToolTip()

D) setText()

Answer: A) setToolTipText()

20. Which event occurs when a JButton is clicked?

A) ActionEvent

B) FocusEvent

C) KeyEvent

D) MouseEvent

Answer: A) ActionEvent

21. What does the pack() method do in Swing?

A) Adjusts the frame size to fit its components

B) Maximizes the frame

C) Minimizes the frame

D) Centers the frame on the screen

Answer: A) Adjusts the frame size to fit its components

22. Which method is used to close a JFrame when the


user clicks the close button?

A) setDefaultCloseOperation()

B) dispose()

C) closeWindow()

D) hide()

Answer: A) setDefaultCloseOperation()

23. Which of the following is true about GridLayout?

A) It arranges components in a grid of equal-sized cells


B) It arranges components in rows and columns but with varying sizes

C) It is a single row layout

D) It arranges components randomly

Answer: A) It arranges components in a grid of equal-sized cells

24. Which component is used to create menus in Swing?

A) JMenu

B) JPopupMenu

C) JMenuBar

D) JToolBar

Answer: A) JMenu

25. Which of the following is a key benefit of using


Swing over AWT?

A) Swing components are platform-dependent

B) Swing components are lightweight

C) Swing components are faster than AWT

D) Swing doesn't use Model-View-Controller

Answer: B) Swing components are lightweight

26. Which class is used for creating labels in Java Swing?

A) JLabel

B) JTextField

C) JButton

D) JPanel

Answer: A) JLabel
27. Which method is called when a user clicks a JButton?

A) actionPerformed()

B) buttonClicked()

C) mouseClicked()

D) keyPressed()

Answer: A) actionPerformed()

28. What is the purpose of the revalidate() method in


Swing?

A) It updates the component hierarchy when a component is added or


removed

B) It repaints the entire component

C) It removes all components from the container

D) It sets the layout to default

Answer: A) It updates the component hierarchy when a


component is added or removed

29. Which layout manager allows components to be


arranged in five regions: North, South, East, West, and
Center?

A) BorderLayout

B) FlowLayout

C) GridBagLayout

D) BoxLayout

Answer: A) BorderLayout

30. Which method is used to set the preferred size of a


component?

A) setPreferredSize()
B) setSize()

C) setDimensions()

D) setLayoutSize()

Answer: A) setPreferredSize()

You might also like