This set of MCQ(multiple choice questions) focuses on the Programming in Java Week 9 Solutions.
Course layout (Answers Link)
Answers COMING SOON! Kindly Wait!
Week 1: Overview of Object-Oriented Programming and Java
Programming Assignment
Week 2: Java Programming Elements
Programming Assignment
Week 3: Input-Output Handling in Java
Programming Assignment
Week 4: Encapsulation
Programming Assignment
Week 5: Inheritance
Programming Assignment
Week 6: Exception Handling
Programming Assignment
Week 7: Multithreaded Programming
Programming Assignment
Week 8: Java Applets and Servlets
Programming Assignment
Week 9: Java Swing and Abstract Windowing Toolkit
Programming Assignment
Week 10: Networking with Java
Week 11: Java Object Database Connectivity
Week 12: Interface and Packages for Software Development
NOTE: You can check your answer immediately by clicking show answer button. Programming in Java Week 9 Solutions” contains 10 questions.
Now, start attempting the quiz.
Programming in Java Week 9 Solutions
Q1. Which of the following Swing components inherently support the WindowListener interface?
a) Swing frames (JFrame)
b) Swing checkboxes (JCheckBox)
c) Swing dialogs (JDialog)
d) Swing combo boxes (JComboBox)
Answer: a)
Q2. Which class in Swing provides a graphical way to display images, icons, or custom graphics?
a) JImage
b) JLabel
c) JImageIcon
d) JDialog
Answer: b) JLabel
Q3. Which event listener interface is commonly used to handle user actions like button clicks in Swing?
a) ActionListener
b) MouseListener
c) KeyListener
d) WindowListener
Answer: a) ActionListener
Q4. What is/are the way(s) to create a Frame in Java Swing?
a) By creating the object of Frame class (association)
b) By extending Frame class (inheritance)
c) By importing a package named JFrame
d) By declaring a class with name JFrame
Answer: a), b)
Q5. Which method is used to add a component to a JPanel in Java Swing?
a) add()
b) addComponent()
c) addElement()
d) insertComponent()
Answer: a) add()
Q6. Which of the following(s) is/are interface(s) of java.awt package?
a) Button
b) Paint
c) Dialog
d) Shape
Answer: b), d)
Q7. Which AWT layout manger is often used to create a responsive grid of components that automatically adjusts to the container’s size?
a) BorderLayout
b) GridLayout
c) GridBagLayout
d) BoxLayout
Answer: c) GridBagLayout
Q8. Which Swing component is used for allowing users to select files and directories from the file system?
a) JFileChooser
b) JFileSelector
c) JFilePicker
d) JFileDialog
Answer: a) JFileChooser
Q9. What is the primary disadvantage of using AWT over Swing for GUI development?
a) AWT components are not well-suited for complex layouts.
b) AWT lacks support for event handling.
c) AWT components are heavyweight and platform-dependent.
d) AWT does not support graphics rendering.
Answer: c) AWT components are heavyweight and platform-dependent.
Q10. Which of the following is/are valid alignment option(s) for components in a FlowLayout?
a) LEFT
b) TOP
c) BOTTOM
d) LEADING
Answer: a), d)
Programming in Java Week 9 Solutions
Q1. Which of the following Listener(s) is/are supported by button Swing component?
a) Action Listener
b) Change Listener
c) Item Listener
d) Window Listener
Answer: a), b), c)
Q2. Which of the following is/are NOT interface(s) in javax.swing package?
a) MenuElement
b) BoxLayout
c) JComponent
d) Scrollable
Answer: b), c)
Q3. Which of the following statement(s) is/are false?
a) Swing component frame support Window Listner
b) Swing component combo box support Window Listner
c) Swing component check box support Window Listner
d) Swing component dialog support Window Listner
Answer: b), c)
Q4. Which package provides many event classes and Listener interfaces for event handling?
a) java.awt.activeevent
b) java.awt.event
c) java.awt.listener
d) none of these
Answer: b) java.awt.event
Q5. Select the correct information
a) JTextField cannot be used as a JLabel
b) JLabel cannot be used as a JTextField
c) Button grouped radio button cannot be used instead of JComboBox.
d) JPasswordField extends JLabel
Answer: b) JLabel cannot be used as a JTextField
Q6. Which of the following is/are incorrect regarding events in Java?
a) EventClass is super class of all the events
b) AdjustmentEvent will be notified if scroll bar is manipulated
c) All the classes and methods required for even handling in Java is in java.awt package.
d) getID() method can be used to determine the type of event.
Answer: a) EventClass is super class of all the events
Q7. Which of the following is/are interface(s) of java.awt package?
a) Button
b) Choice
c) Dialog
d) Paint
Answer: d) Paint
Q8. Which of the following displays components row-by-row in the order in which they were added to the JFrame?
a) CardLayout
b) FlowLayout
c) BorderLayout
d) GridLayout
Answer: b) FlowLayout
Q9. Which of the following statements are true?
a) Java AWT components are platform-dependent.
b) Java Swing components are platform-independent
c) MVC pattern is not supported by AWT
d) MVC pattern is supported by Swing
Answer: a), b), c), d)
Q10. Which of the following method is used to set a frame, say f with size 300 x 200 pixels?
JFrame f = new JFrame();
a) f.setsize(300, 200);
b) f.setSize(300, 200);
c) f.paint(300, 200);
d) f.setVisible(300, 200);
Answer: b) f.setSize(300, 200);
Previous Course – Programming in Java Week 9 Solutions
Q1. Select the correct statement(s) in the following.
a) JTextField cannot be used as an alternative to JLabel.
b) JLabel cannot be used as an alternative to JTextField.
c) Button grouped radio button can be used as an alternative to JComboBox.
d) The class JPasswordField extends the class JLabel.
Answer: b) JLabel cannot be used as an alternative to JTextField.
Q2. In Java AWT, TextArea and TextField are subclass of:
a) List
b) Label
c) TextComponent
d) TextComponent and Label, respectively
Answer: c) TextComponent
Q3. Analyze the following code.
import java.awt.*;
import javax.swing.*;
public class Test {
public static void main(String[ ] args) {
JFrame frame = new JFrame("My Frame");
frame.add(new JButton("Cancel"));
frame.add(new JButton("OK"));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
frame.setVisible(true);
}
}
Which button will be displayed(or can be seen by user)?
a) OK
b) Cancel
c) both
d) None
Answer: a) OK
Q4. In JLabel(Icon, int) method/constructor, the int argument specifies the horizontal alignment of the label’s contents within its drawing area.
Which of the following is/are not a valid constants for horizontal alignment?
a) RIGHT
b) LEADING
c) TRAILING
d) TOP
Answer: d) TOP
Q5. Which of the following is/are not related with keyboard event?
a) Class KeyEvent is used to notify if any key pressed occurs or not.
b) The KeyListener should be added either in init() or the main method.
c) RequestFocus should be added either in init() or the main method.
d) The class InputEvent should be imported explicity in the program.
Answer: d) The class InputEvent should be imported explicity in the program.
Q6. Which of the following Listener(s) is/are supported by button (Swing component)?
a) ActionListener
b) ChangeListener
c) ItemListener
d) WindowListener
Answer: d) WindowListener
Q7. Which of the following Listener Interface does not have an Adapter Class?
a) ActionListener
b) ChangeListener
c) ComponentListener
d) ItemListener
Answer: a), b), d)
Q8. To set a FlowLayout in a panel, say jp, which of the following method(s) that you can not use?
a) jp.setLayout (new FlowLayout());
b) jp.setLayout (new FlowLayout (FlowLayout.CENTER));
c) jp.setLayout (new FlowLayout (FlowLayout.center));
d) jp.setLayout (FlowLayout());
Answer: a), b)
Q9. Which of the following is/are interface(s) in javax.swing package?
a) MenuElement
b) BoxLayout
c) JComponent
d) Scrollable
Answer: a), d)
Q10. Which package provide many methods for graphics programming?
a) java.awt
b) java.Applet
c) java.Graphics
d) java.io
Answer: a)
>> Next- Programming in Java Week 8 Assignment Solutions
>> Next- Programming in Java Week 10 Assignment Solutions
DISCLAIMER: Use these answers only for the reference purpose. Quizermania doesn't claim these answers to be 100% correct. So, make sure you submit your assignments on the basis of your knowledge.
For discussion about any question, join the below comment section. And get the solution of your query. Also, try to share your thoughts about the topics covered in this particular quiz.