🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Document Details

SprightlyAntigorite4512

Uploaded by SprightlyAntigorite4512

Tags

java programming AWT components user interface

Full Transcript

[9/6, 23:52] Yuvraj: Certainly! Here are the questions with answers and reasoning: 1. **Which method is used to set the visibility of a frame?** - A. `showFrame()` - B. `frameVisible()` - C. `setVisibility()` - D. `setVisible(true)` **Answer: D. `setVisible(true)`** - **Reasoning**: In...

[9/6, 23:52] Yuvraj: Certainly! Here are the questions with answers and reasoning: 1. **Which method is used to set the visibility of a frame?** - A. `showFrame()` - B. `frameVisible()` - C. `setVisibility()` - D. `setVisible(true)` **Answer: D. `setVisible(true)`** - **Reasoning**: In Swing, `setVisible(true)` is the standard method used to control the visibility of a frame or other components. The other options are not valid methods for setting visibility. 2. **Which package needs to be imported when writing the `JRadioButton` class?** - A. `java.awt.*` - B. `javax.swing.*` - C. `java.swing.*` - D. `javax.awt.*` **Answer: B. `javax.swing.*`** - **Reasoning**: `JRadioButton` is part of the Swing library, which is in the `javax.swing` package. The other packages listed are incorrect or non-existent. 3. **Which abstract class is the superclass of all menu-related classes?** - A. `MenuComponent` - B. `MenuItem` - C. `Menu` - D. `MenuBar` **Answer: A. `MenuComponent`** - **Reasoning**: `MenuComponent` is the abstract superclass for all menu-related classes in AWT, such as `Menu`, `MenuItem`, and `MenuBar`. It provides the foundational functionality for menu components. 4. **Which of the following is not an AWT class?** - A. `Button` - B. `CheckBox` - C. `RadioButton` - D. `TextField` **Answer: C. `RadioButton`** - **Reasoning**: `RadioButton` is not part of AWT; it is a Swing component. `Button`, `CheckBox`, and `TextField` are all part of AWT. 5. **Which are the alignment constants of a Label?** - A. `LEFT`, `CENTER`, `RIGHT` - B. `TOP`, `BOTTOM`, `CENTER` - C. `HORIZONTAL`, `VERTICAL` - D. `START`, `MIDDLE`, `END` **Answer: A. `LEFT`, `CENTER`, `RIGHT`** - **Reasoning**: `LEFT`, `CENTER`, and `RIGHT` are the alignment constants used for labels in AWT. The other options do not apply to label alignment. 6. **Which are the subclasses of the container class?** - A. `Window`, `Panel`, `ScrollPane` - B. `JFrame`, `JPanel`, `JScrollPane` - C. `Frame`, `Canvas`, `Dialog` - D. `Applet`, `Dialog`, `Window` **Answer: A. `Window`, `Panel`, `ScrollPane`** - **Reasoning**: `Window`, `Panel`, and `ScrollPane` are subclasses of the `Container` class. `JFrame`, `JPanel`, and `JScrollPane` are part of Swing and are not direct subclasses of AWT’s `Container`. 7. **Which AWT component is not editable?** - A. `TextField` - B. `TextArea` - C. `Label` - D. `Choice` **Answer: C. `Label`** - **Reasoning**: `Label` is a display-only component and cannot be edited. `TextField`, `TextArea`, and `Choice` are editable or interactive components. 8. **Which AWT control is used for multi-line text entry?** - A. `TextField` - B. `TextArea` - C. `Label` - D. `List` **Answer: B. `TextArea`** - **Reasoning**: `TextArea` is designed for multi-line text input. `TextField` is used for single-line input, `Label` is for display purposes, and `List` is used for selecting from a list of items. 9. **Which class can be used to represent a checkbox with a textual label that can appear in a menu?** - A. `Checkbox` - B. `CheckBoxMenuItem` - C. `JCheckBox` - D. `JCheckBoxMenuItem` **Answer: B. `CheckBoxMenuItem`** - **Reasoning**: `CheckBoxMenuItem` is specifically designed to be used within menus, providing a checkbox with a textual label. `JCheckBox` is a Swing component, and the other options are not suitable for menu usage. 10. **Which class creates a node in `JTree`?** - A. `DefaultMutableTreeNode` - B. `TreeNode` - C. `JTreeNode` - D. `MutableTreeNode` **Answer: A. `DefaultMutableTreeNode`** - **Reasoning**: `DefaultMutableTreeNode` is a class used to create nodes in a `JTree`. `TreeNode` is an interface, `JTreeNode` is not a valid class, and `MutableTreeNode` is an interface but not used directly for node creation. 11. **Which class defines the `setSize()` method?** - A. `Frame` - B. `Window` - C. `Component` - D. `Panel` **Answer: A. `Frame`** - **Reasoning**: The `setSize()` method is defined in `Component`, and it is inherited by `Frame`, which is a subclass of `Window` and ultimately `Component`. While technically correct that `setSize()` is in `Component`, `Frame` is a more specific and commonly referenced class for this method. 12. **Which class encapsulates a blank window upon which we can draw?** - A. `Canvas` - B. `Panel` - C. `Graphics` - D. `JPanel` **Answer: A. `Canvas`** - **Reasoning**: `Canvas` is used specifically for drawing graphics and provides a blank window. `Panel` and `JPanel` are used for arranging components but are not focused on drawing. `Graphics` is a class for drawing, not a container. 13. **Which class is on the top of the AWT event hierarchy?** - A. `AWTEvent` - B. `Event` - C. `ComponentEvent` - D. `ActionEvent` **Answer: A. `AWTEvent`** - **Reasoning**: `AWTEvent` is the top-level class in the AWT event hierarchy. All AWT events are derived from this class. The other options are subclasses or specific types of events. 14. **Which class is used to create a pop-up list of items from which the user may choose?** - A. `Choice` - B. `ComboBox` - C. `List` - D. `PopupMenu` **Answer: A. `Choice`** - **Reasoning**: `Choice` is used to create a pop-up list of items in AWT. `ComboBox` is a Swing component, `List` is used for multiple selections, and `PopupMenu` is for displaying context menus. 15. **Which class is used to get the dimension of an Applet?** - A. `Dimension` - B. `Size` - C. `Applet` - D. `Graphics` **Answer: A. `Dimension`** - **Reasoning**: `Dimension` is used to obtain the width and height of components or containers, including applets. `Size` is not a valid class in this context, and `Applet` or `Graphics` do not directly provide dimensions. 16. **Which class is used to represent a single line textbox with password character facility?** - A. `TextField` - B. `JPasswordField` - C. `PasswordField` - D. `TextArea` **Answer: B. `JPasswordField`** - **Reasoning**: `JPasswordField` is a Swing component specifically designed for single-line text input with password masking. `TextField` does not mask characters, and `TextArea` is for multi-line text. 17. **Which class provides many methods for graphics programming?** - A. `Graphics` - B. `Graphics2D` - C. `Drawable` - D. `Paint` **Answer: A. `Graphics`** - **Reasoning**: `Graphics` provides the fundamental methods for drawing and graphics programming in AWT. `Graphics2D` extends `Graphics` with additional features, but `Graphics` is the primary class for basic graphics operations. 18. **Which component cannot be added to a container?** - A. `JFrame` - B. `JPanel` - C. `JButton` - D. `JLabel` **Answer: A. `JFrame`** - **Reasoning**: `JFrame` is a top-level container and cannot be added to another container. The other components (`JPanel`, `JButton`, `JLabel`) are components that can be added to containers. 19. **Which component displays information in a hierarchical manner with a parent-child relationship? [9/6, 23:52] Yuvraj: It seems like I missed some questions. Let's address the remaining ones: **Which method is used to change the size and position of components?** - A. `void setBounds(int x, int y, int width, int height)` - B. `void setSize(int width, int height)` - C. `void setLocation(int x, int y)` - D. `void setPosition(int x, int y)` **Answer: A. `void setBounds(int x, int y, int width, int height)`** - **Reasoning**: The `setBounds(int x, int y, int width, int height)` method is used to specify the size and position of a component. It sets the component's bounds in a single call. **Which method is used to change the name of a menu item?** - A. `void setLabel(String newName)` - B. `void rename(String newName)` - C. `void setName(String newName)` - D. `void changeLabel(String newName)` **Answer: A. `void setLabel(String newName)`** - **Reasoning**: `setLabel(String newName)` is used to change the text label of a menu item. The other methods listed do not pertain to changing a menu item's label. **Which method is used to close a Swing frame?** - A. `setDefaultCloseOperation()` - B. `close()` - C. `dispose()` - D. `exit()` **Answer: A. `setDefaultCloseOperation()`** - **Reasoning**: `setDefaultCloseOperation()` specifies the operation that will happen by default when the user initiates a "close" on this frame. Commonly, you would use `JFrame.EXIT_ON_CLOSE` as a parameter to this method to terminate the application. **Which method is used to display a label on a checkbox?** - A. `String getLabel()` - B. `getText()` - C. `setText(String text)` - D. `getTextLabel()` **Answer: A. `String getLabel()`** - **Reasoning**: `getLabel()` is the method used to retrieve the label text of a checkbox. This is specific to AWT’s `Checkbox` component. **Which method is used to set a label for Button B?** - A. `B.setLabel(String s)` - B. `B.setText(String s)` - C. `B.setCaption(String s)` - D. `B.setTitle(String s)` **Answer: A. `B.setLabel(String s)`** - **Reasoning**: `setLabel(String s)` is the method used to set the label of a `Button` in AWT. `setText()` is used in Swing components like `JButton`. **Which method is used to set the dimensions of the window?** - A. `void setSize(int newWidth, int newHeight)` - B. `void resize(int width, int height)` - C. `void setDimensions(int width, int height)` - D. `void setWindowSize(int width, int height)` **Answer: A. `void setSize(int newWidth, int newHeight)`** - **Reasoning**: `setSize(int newWidth, int newHeight)` is the standard method for setting the dimensions of a window or component. **Which method is used to set the layout of the Applet?** - A. `setLayout()` - B. `setAppletLayout()` - C. `layout()` - D. `configureLayout()` **Answer: A. `setLayout()`** - **Reasoning**: `setLayout()` is used to specify the layout manager for the applet or any container. **Which method sets the size and position of a component?** - A. `setBounds()` - B. `setSize()` - C. `setLocation()` - D. `resize()` **Answer: A. `setBounds()`** - **Reasoning**: `setBounds()` sets both the size and position of a component in a single call, specifying x and y coordinates along with width and height. **Which method will cause a Frame to be displayed?** - A. `setVisible(true)` - B. `show()` - C. `display()` - D. `open()` **Answer: A. `setVisible(true)`** - **Reasoning**: `setVisible(true)` is used to make a `Frame` visible. `show()` was used in earlier AWT versions but is deprecated. **Which object can be constructed to show and select any number of choices in the visible window?** - A. `List` - B. `ComboBox` - C. `CheckBox` - D. `RadioButton` **Answer: A. `List`** - **Reasoning**: `List` allows for the selection of multiple items from a list of choices. `ComboBox` and `CheckBox` do not support multi-selection in the same way, and `RadioButton` supports single choice among many. [9/6, 23:52] Yuvraj: Certainly! Here are the questions with answers and reasoning: 1. **Which containers may have a MenuBar?** - A. `JFrame` - B. `JPanel` - C. `JApplet` - D. `Frame` **Answer: D. `Frame`** - **Reasoning**: In AWT, `Frame` is the container that can have a `MenuBar`. Swing's `JFrame` also supports a menu bar, but the question specifically pertains to AWT. 2. **Which control is not contained in the AWT package?** - A. `ScrollPane` - B. `Button` - C. `TextArea` - D. `Label` **Answer: A. `ScrollPane`** - **Reasoning**: `ScrollPane` is a Swing component and is part of `javax.swing`, not AWT. `Button`, `TextArea`, and `Label` are part of AWT. 3. **Which constructor creates a `TextArea` with 10 rows and 20 columns?** - A. `new TextArea(10, 20)` - B. `new TextArea(20, 10)` - C. `new TextArea(10)` - D. `new TextArea()` **Answer: A. `new TextArea(10, 20)`** - **Reasoning**: The `TextArea` constructor `new TextArea(10, 20)` correctly sets the number of rows and columns. 4. **Which is a control in Swing that combines a text field and a dropdown list?** - A. `JComboBox` - B. `JTextField` - C. `JList` - D. `JCheckBox` **Answer: A. `JComboBox`** - **Reasoning**: `JComboBox` is a Swing component that combines a text field and a dropdown list, allowing users to either type or select from a list. 5. **Which is the correct method for adding a button component into the North region of BorderLayout? Assume `b1` is a button object.** - A. `add(b1, BorderLayout.NORTH)` - B. `add(BorderLayout.NORTH, b1)` - C. `add(b1, "North")` - D. `setLayout(BorderLayout.NORTH)` **Answer: A. `add(b1, BorderLayout.NORTH)`** - **Reasoning**: `add(b1, BorderLayout.NORTH)` is the correct method to place the button in the North region of a `BorderLayout`. 6. **Which is the default layout manager for `JApplet`?** - A. `BorderLayout` - B. `FlowLayout` - C. `GridLayout` - D. `BoxLayout` **Answer: A. `BorderLayout`** - **Reasoning**: `JApplet` (and `Applet`) uses `BorderLayout` as its default layout manager. 7. **Which is the immediate superclass for `TextField`?** - A. `TextComponent` - B. `Component` - C. `Container` - D. `Object` **Answer: A. `TextComponent`** - **Reasoning**: `TextField` inherits from `TextComponent`, which is its immediate superclass. 8. **Which is a constructor of `JTabbedPane`?** - A. `new JTabbedPane()` - B. `new JTabbedPane(int tabPlacement)` - C. `new JTabbedPane(int tabPlacement, int tabLayoutPolicy)` - D. `Both option A and B` **Answer: D. `Both option A and B`** - **Reasoning**: `JTabbedPane` has multiple constructors including those with default settings and those specifying tab placement. 9. **Which is the correct constructor for `JProgressBar`?** - A. `new JProgressBar()` - B. `new JProgressBar(int min, int max)` - C. `new JProgressBar(int min, int max, int value)` - D. `All of the above` **Answer: D. `All of the above`** - **Reasoning**: `JProgressBar` has various constructors allowing for different initialization options, including specifying minimum, maximum, and initial values. 10. **Which is the correct constructor of `GridLayout`?** - A. `GridLayout(int numRows, int numCols)` - B. `GridLayout(int numRows, int numCols, int hgap, int vgap)` - C. `GridLayout()` - D. `GridLayout(int numCols, int numRows)` **Answer: A. `GridLayout(int numRows, int numCols)`** - **Reasoning**: `GridLayout(int numRows, int numCols)` is the correct constructor for specifying the number of rows and columns. 11. **Which is the immediate superclass of `Applet`?** - A. `Panel` - B. `Container` - C. `Component` - D. `Object` **Answer: A. `Panel`** - **Reasoning**: `Applet` inherits from `Panel`, which is its immediate superclass. 12. **Which method is used to count the number of items in the list?** - A. `getItemCount()` - B. `countItems()` - C. `size()` - D. `length()` **Answer: A. `getItemCount()`** - **Reasoning**: `getItemCount()` is used to obtain the number of items in a `List` component. 13. **Which is true about Swing?** - A. `Swing is a part of Java Foundation Classes (JFC).` - B. `Swing provides a richer set of GUI components compared to AWT.` - C. `Swing components are lightweight and written entirely in Java.` - D. `All the above` **Answer: D. `All the above`** - **Reasoning**: All listed statements are true about Swing: it is part of JFC, offers a richer set of components compared to AWT, and components are lightweight and written in Java. 14. **Which are various methods of `TextField` control from the following?** - A. `getText()`, `setText()`, `setEchoChar()` - B. `getValue()`, `setValue()`, `setChar()` - C. `retrieveText()`, `updateText()`, `hideChar()` - D. `fetchText()`, `alterText()`, `setMask()` **Answer: A. `getText()`, `setText()`, `setEchoChar()`** - **Reasoning**: `getText()`, `setText()`, and `setEchoChar()` are methods available in `TextField` for text handling and display, including password masking. 15. **Which layout arranges the components as a deck of cards such that only one component is visible at a time?** - A. `CardLayout` - B. `FlowLayout` - C. `BorderLayout` - D. `GridLayout` **Answer: A. `CardLayout`** - **Reasoning**: `CardLayout` arranges components in a stack, where only one component is visible at a time, resembling a deck of cards. 16. **Which layout should you use to organize the components of a container in a tabular form?** - A. `GridLayout` - B. `FlowLayout` - C. `BorderLayout` - D. `BoxLayout` **Answer: A. `GridLayout`** - **Reasoning**: `GridLayout` arranges components in a grid (tabular form) with a specified number of rows and columns. 17. **Which method executes only once?** - A. `init()` - B. `start()` - C. `stop()` - D. `paint()` **Answer: A. `init()`** - **Reasoning**: The `init()` method in applets is executed once when the applet is first loaded. 18. **Which method gets the text associated with a `Label` object `jlbl`?** - A. `jlbl.getText()` - B. `jlbl.retrieveText()` - C. `jlbl.getLabel()` - D. `jlbl.fetchText()` **Answer: A. `jlbl.getText()`** - **Reasoning**: `getText()` is the method used to retrieve the text from a `Label` component. 19. **Which method is used to add items to `JComboBox`?** - A. `addItem()` - B. `add()` - C. `insertItem()` - D. `appendItem()` **Answer: A. `addItem()`** - **Reasoning**: `addItem()` is used to add items to a `JComboBox`. 20. **Which method is used to add tabs to a `JTabbedPane`?** - A. `addTab()` - B. `insertTab()` - C. `add()` - D. `put [9/6, 23:52] Yuvraj: Certainly! Here are the questions with answers and reasoning: 1. **Which of the following are not Swing components?** - A. `JPanel` - B. `JFrame` - C. `Button` - D. `Label` **Answer: C. `Button` and D. `Label`** - **Reasoning**: `Button` and `Label` are AWT components, not Swing components. Swing equivalents are `JButton` and `JLabel`. 2. **Which of the following are passed as an argument to the `paint()` method?** - A. `A Graphics object` - B. `A Color object` - C. `A Dimension object` - D. `An Image object` **Answer: A. `A Graphics object`** - **Reasoning**: The `paint()` method in AWT and Swing receives a `Graphics` object as an argument to perform drawing operations. 3. **Which of the following are subclasses of the `Container` class?** - A. `ScrollPane` - B. `Vector` - C. `String` - D. `Panel` **Answer: A. `ScrollPane` and D. `Panel`** - **Reasoning**: `ScrollPane` and `Panel` are subclasses of `Container`. `Vector` and `String` are not related to container hierarchy. 4. **Which of the following are subclasses of `java.awt.Component`?** - A. `Container` - B. `Button` - C. `Frame` - D. `TextField` **Answer: A. `Container`** - **Reasoning**: `Container` is a direct subclass of `Component`. `Button`, `Frame`, and `TextField` are subclasses of `Container` or other subclasses of `Component`. 5. **Which of the following are true?** - A. `Panel extends Container.` - B. `Button extends Component.` - C. `Frame extends Container.` - D. `Label extends Container.` **Answer: A. `Panel extends Container.`** - **Reasoning**: `Panel` extends `Container`, whereas `Button`, `Frame`, and `Label` do not extend `Container` directly. 6. **Which of the following classes is derived from the `Container` class?** - A. `Panel` - B. `Button` - C. `TextField` - D. `Label` **Answer: A. `Panel`** - **Reasoning**: `Panel` is derived from `Container`. `Button`, `TextField`, and `Label` are components that are not directly derived from `Container`. 7. **Which of the following classes acts as a superclass in the class hierarchy?** - A. `Component` - B. `Container` - C. `Panel` - D. `Button` **Answer: A. `Component`** - **Reasoning**: `Component` is the root class in the AWT hierarchy from which all other components inherit. 8. **Which of the following components allow multiple selections?** - A. `List` - B. `ComboBox` - C. `CheckBox` - D. `RadioButton` **Answer: A. `List`** - **Reasoning**: `List` can be configured for multiple selections. `ComboBox`, `CheckBox`, and `RadioButton` do not inherently support multiple selections in the same way. 9. **Which of the following components does not have visible borders?** - A. `Panel` - B. `TextField` - C. `Button` - D. `Label` **Answer: A. `Panel`** - **Reasoning**: `Panel` does not have visible borders by default. Components like `TextField`, `Button`, and `Label` can have visible borders or backgrounds depending on their look and feel. 10. **Which of the following can contain a `MenuBar`?** - A. `Frame` - B. `Panel` - C. `Dialog` - D. `Applet` **Answer: A. `Frame`** - **Reasoning**: `Frame` can contain a `MenuBar`. Other components like `Panel`, `Dialog`, and `Applet` cannot contain a `MenuBar`. 11. **Which of the following controls does not support interaction with the user?** - A. `Label` - B. `TextField` - C. `Button` - D. `CheckBox` **Answer: A. `Label`** - **Reasoning**: `Label` is used to display text but does not support user interaction. `TextField`, `Button`, and `CheckBox` are interactive controls. 12. **Which of the following creates a `List` with 5 visible items and multiple selections enabled?** - A. `new List(5, true)` - B. `new List(5, false)` - C. `new List(true, 5)` - D. `new List(5)` **Answer: A. `new List(5, true)`** - **Reasoning**: The constructor `new List(5, true)` creates a `List` with 5 visible rows and enables multiple selections. 13. **Which of the following is not an AWT control?** - A. `ButtonGroup` - B. `TextArea` - C. `CheckBox` - D. `Choice` **Answer: A. `ButtonGroup`** - **Reasoning**: `ButtonGroup` is not an AWT control; it is used in Swing to group radio buttons. The other options are AWT controls. 14. **Which of the following is not a constructor of `JTree`?** - A. `JTree()` - B. `JTree(TreeModel model)` - C. `JTree(Object[] value)` - D. `JTree(int x)` **Answer: D. `JTree(int x)`** - **Reasoning**: `JTree(int x)` is not a valid constructor. Valid constructors include `JTree()`, `JTree(TreeModel model)`, and `JTree(Object[] value)`. 15. **Which of the following is not a Swing class?** - A. `JButton` - B. `JLabel` - C. `JFrame` - D. `Canvas` **Answer: D. `Canvas`** - **Reasoning**: `Canvas` is an AWT class, not a Swing class. `JButton`, `JLabel`, and `JFrame` are Swing classes. 16. **Which of the following is not an active control?** - A. `Button` - B. `TextField` - C. `Label` - D. `CheckBox` **Answer: C. `Label`** - **Reasoning**: `Label` is a passive control that does not accept user input. `Button`, `TextField`, and `CheckBox` are active controls. 17. **Which of the following is not an AWT component?** - A. `Applet` - B. `Button` - C. `TextField` - D. `JPanel` **Answer: D. `JPanel`** - **Reasoning**: `JPanel` is a Swing component, not an AWT component. `Applet`, `Button`, and `TextField` are AWT components. 18. **Which of the following is not true about Dialog Boxes?** - A. `Dialog boxes contain menu bars.` - B. `Dialog boxes are used for interaction.` - C. `Dialog boxes can display messages.` - D. `Dialog boxes can accept user input.` **Answer: A. `Dialog boxes contain menu bars.`** - **Reasoning**: Dialog boxes do not typically contain menu bars. They are used for user interactions and can display messages or accept input. 19. **Which of the following is not true about Swing Components?** - A. `Heavyweight components` - B. `Lightweight components` - C. `Part of Java Foundation Classes (JFC)` - D. `Provides a richer set of GUI components` **Answer: A. `Heavyweight components`** - **Reasoning**: Swing components are lightweight, meaning they are not tied to the native operating system’s windowing system like heavyweight components. 20. **Which of the following is not a valid alignment constant for `Label`?** - A. `LEFT` - B. `CENTER` - C. `RIGHT` - D. `MIDDLE` **Answer: D. `MIDDLE`** - **Reasoning**: Valid alignment constants for `Label` are `LEFT`, `CENTER`, and `RIGHT`. `MIDDLE` is not a valid alignment constant. 21. **Which of the following is not a valid constructor for `JCheckBox`?** - A. `JCheckBox(String text)` - B. `JCheckBox(String text, boolean selected)` - C. `JCheckBox(String text, boolean selected, CheckboxGroup group)` - D. `JCheckBox()` **Answer: C. `JCheckBox(String [9/6, 23:52] Yuvraj: Certainly, here is the completion of the list with answers and reasoning: 21. **Which of the following is not a valid constructor for `JCheckBox`?** - A. `JCheckBox(String text)` - B. `JCheckBox(String text, boolean selected)` - C. `JCheckBox(String text, boolean selected, CheckboxGroup group)` - D. `JCheckBox()` **Answer: C. `JCheckBox(String text, boolean selected, CheckboxGroup group)`** - **Reasoning**: The constructor `JCheckBox(String text, boolean selected, CheckboxGroup group)` is not valid for `JCheckBox`. This constructor resembles one for `Checkbox` in AWT, not `JCheckBox` in Swing. The valid constructors for `JCheckBox` include `JCheckBox(String text)`, `JCheckBox(String text, boolean selected)`, and `JCheckBox()`. 22. **Which of the following is not a valid style constant for `Font`?** - A. `BOLD` - B. `ITALIC` - C. `PLAIN` - D. `NORMAL` **Answer: D. `NORMAL`** - **Reasoning**: `NORMAL` is not a valid style constant for `Font`. The valid style constants are `BOLD`, `ITALIC`, and `PLAIN`. 23. **Which of the following is a passive AWT control?** - A. `Label` - B. `TextField` - C. `Button` - D. `CheckBox` **Answer: A. `Label`** - **Reasoning**: `Label` is a passive control that does not interact with the user. `TextField`, `Button`, and `CheckBox` are active controls that respond to user input. 24. **Which of the following is the immediate superclass of the `MenuComponent` class?** - A. `Object` - B. `Component` - C. `Container` - D. `MenuContainer` **Answer: D. `MenuContainer`** - **Reasoning**: `MenuComponent` is a direct subclass of `MenuContainer`. The other options are not its immediate superclass. 25. **Which of the following is true about AWT and Swing components?** - A. `AWT components create a process whereas Swing components create a thread.` - B. `AWT components and Swing components are independent of each other.` - C. `Swing components are lightweight and AWT components are heavyweight.` - D. `AWT components are used for modern GUI applications, while Swing is for legacy applications.` **Answer: C. `Swing components are lightweight and AWT components are heavyweight.`** - **Reasoning**: Swing components are considered lightweight because they are drawn entirely in Java and do not rely on native system resources. In contrast, AWT components are heavyweight as they rely on native system resources for their rendering. 26. **Which of the following is used to interpret and execute Java applet classes hosted by HTML?** - A. `Appletviewer` - B. `Java Web Start` - C. `Java Virtual Machine` - D. `JVM` **Answer: A. `Appletviewer`** - **Reasoning**: `Appletviewer` is a command-line utility used to run and test Java applets. Java Web Start and JVM are not specifically designed for applets. 27. **Which of the following layout managers need to create a `Panel`?** - A. `CardLayout` - B. `BorderLayout` - C. `FlowLayout` - D. `GridLayout` **Answer: A. `CardLayout`** - **Reasoning**: `CardLayout` is often used within a `Panel` to manage different components as cards. While other layout managers can also be used within a `Panel`, `CardLayout` frequently necessitates a `Panel`. 28. **Which of the following may a menu contain?** - A. `MenuItem` - B. `MenuBar` - C. `Separator` - D. `TextField` **Answer: A. `MenuItem`** - **Reasoning**: A `Menu` can contain `MenuItem`, `Separator`, and other sub- menus. `MenuBar` is not contained within a `Menu`; instead, it is set for a `Frame` or `Dialog`. 29. **Which of the following may contain a menu bar?** - A. `Frame` - B. `Dialog` - C. `Panel` - D. `Applet` **Answer: A. `Frame`** - **Reasoning**: A `Frame` can contain a menu bar. Other components like `Dialog`, `Panel`, and `Applet` do not contain menu bars. 30. **Which of the following methods is used to add a button “b” to the south of the applet using `BorderLayout`?** - A. `add(b, BorderLayout.SOUTH);` - B. `add(b, BorderLayout.NORTH);` - C. `add(b, BorderLayout.EAST);` - D. `add(b, BorderLayout.CENTER);` **Answer: A. `add(b, BorderLayout.SOUTH);`** - **Reasoning**: The `add(b, BorderLayout.SOUTH)` method adds a button `b` to the south position of the layout, which is a correct use of `BorderLayout`. 31. **Which of the following methods is used to change the label caption?** - A. `setText(String s)` - B. `setLabel(String s)` - C. `setCaption(String s)` - D. `updateLabel(String s)` **Answer: A. `setText(String s)`** - **Reasoning**: In Swing, `setText(String s)` is used to change the label caption. `setLabel(String s)` is used in AWT components like `Label`. The other methods are not valid for changing the label caption. [9/6, 23:52] Yuvraj: Here are the questions with logical answer options, answers, and explanations: 1. JPanel and Applet use ___________________ as their default layout. - A) BorderLayout - B) FlowLayout - C) GridLayout - D) CardLayout **Answer:** B) FlowLayout **Explanation:** Both `JPanel` and `Applet` use `FlowLayout` as their default layout, which arranges components in a left-to-right flow, much like lines of text in a paragraph. 2. Which are various AWT controls from the following? - A) Labels, Push buttons, Check boxes, Choice lists. - B) Labels, Sliders, Trees, Tables. - C) Lists, Trees, Tables, Sliders. - D) None of the above. **Answer:** A) Labels, Push buttons, Check boxes, Choice lists. **Explanation:** AWT controls include components like labels, push buttons, check boxes, and choice lists, which are basic GUI components for building user interfaces. 3. Which of the following component class cannot be added on an applet? - A) Menu - B) Label - C) Button - D) TextField **Answer:** A) Menu **Explanation:** The `Menu` class is part of the `MenuBar` class and cannot be added directly to an applet. It must be attached to a frame's menu bar. 4. A checkbox is a control that consists of a ____________. - A) Small box only - B) Label only - C) Combination of a small box and a Label - D) None of the above **Answer:** C) Combination of a small box and a Label **Explanation:** A checkbox typically consists of a small square box that can be checked or unchecked, accompanied by a label that describes the choice. 5. A Frame's _______________ designates the area of the frame excluding the title, menu bar, and the border. - A) ContentPane - B) BorderLayout - C) LayoutManager - D) Insets **Answer:** A) ContentPane **Explanation:** The `ContentPane` is the main container of a `Frame`, which holds all the components excluding the frame's decorations like the title, menu bar, and borders. 6. A GUI stands for _____________. - A) Graphical User Interface - B) Global User Interface - C) General User Interface - D) Guided User Interface **Answer:** A) Graphical User Interface **Explanation:** GUI stands for Graphical User Interface, which allows users to interact with electronic devices through graphical icons and visual indicators. 7. A JCheckBoxMenuItem is a subclass of ________. - A) JMenuItem - B) AbstractButton - C) JComponent - D) All of these **Answer:** D) All of these **Explanation:** `JCheckBoxMenuItem` is a subclass of `JMenuItem`, `AbstractButton`, and `JComponent`, combining functionalities of a menu item and a check box. 8. A label is a simple control which is used to display _______________ on the window. - A) Editable text - B) Non-editable text - C) Graphics - D) User input **Answer:** B) Non-editable text **Explanation:** A `Label` is a simple display area for a short text string or an image, which cannot be edited by the user. 9. A ScrollPane is _______________. - A) Component - B) Container - C) Layout Manager - D) Event Listener **Answer:** B) Container **Explanation:** A `ScrollPane` is a container that provides a scrollable view of a component, allowing users to see parts of a larger component that may not fit within the visible area. 10. A superclass of `TextField` and `TextArea` classes that is used to create single-line, multiline textfields respectively is _____. - A) TextComponent - B) TextControl - C) TextWidget - D) TextBox **Answer:** A) TextComponent **Explanation:** `TextComponent` is the superclass for `TextField` and `TextArea` classes, providing the common functionality for text input and editing components. 11. A _______ is a component that appears as a group of folders in a file cabinet. - A) JTabbedPane - B) JFileChooser - C) JPanel - D) JLayeredPane **Answer:** A) JTabbedPane **Explanation:** `JTabbedPane` allows you to group different components in a tabbed interface, similar to folders in a file cabinet. 12. A __________ automatically arranges the components added to a container. - A) BorderLayout - B) GridLayout - C) FlowLayout - D) Layout Manager **Answer:** D) Layout Manager **Explanation:** A `Layout Manager` is responsible for positioning and sizing components within a container according to a specific layout policy. 13. A ____________ is a passive AWT control which does not generate any event. - A) Label - B) Button - C) Checkbox - D) TextField **Answer:** A) Label **Explanation:** A `Label` is a passive component used to display text and does not generate any user interaction events. 14. A ____________________ component is a display area for a short string of text, image, or both. - A) JLabel - B) JTextField - C) JButton - D) JCheckBox **Answer:** A) JLabel **Explanation:** `JLabel` is used for displaying a short string of text, an image, or both, and does not allow user interaction. 15. All components on a Container can be removed by calling the following method: - A) clearAll() - B) removeAll() - C) deleteAll() - D) dispose() **Answer:** B) removeAll() **Explanation:** `removeAll()` is a method that removes all components from a container, effectively clearing its contents. 16. All Swing component classes are placed in: - A) java.awt - B) java.util - C) javax.swing - D) javax.awt **Answer:** C) javax.swing **Explanation:** Swing components are part of the `javax.swing` package, which provides a set of lightweight GUI components. 17. An Applet is ______________ of Panel. - A) subclass - B) superclass - C) sibling class - D) unrelated class **Answer:** A) subclass **Explanation:** An `Applet` is a subclass of `Panel`, meaning it inherits all the properties and methods of the `Panel` class. 18. Applet Container is used to prepare ________________ output window. - A) Graphical - B) Text-based - C) Both a and b - D) None of the above **Answer:** C) Both a and b **Explanation:** An `Applet` container can handle both graphical and text-based output, making it versatile for creating interactive applications. 19. The AppletViewer tool is available in which of the following folders of JDK? - A) bin - B) lib - C) src - D) docs **Answer:** A) bin **Explanation:** The `AppletViewer` tool, used for testing and running applets, is located in the `bin` folder of the JDK. [9/6, 23:52] Yuvraj: Here are the updated logical options, answers, and reasoning for each question: 1. **At the top of the AWT hierarchy is the** - a) Frame - b) Component - c) Object - d) Container **Answer:** b) Component **Reasoning:** In AWT, every graphical element is derived from the `Component` class. It is the base class for all AWT components (like buttons, checkboxes, text fields, etc.), making it the top of the AWT hierarchy. 2. **AWT classes are contained in the __________ package** - a) java.util - b) java.awt - c) java.io - d) javax.swing **Answer:** b) java.awt **Reasoning:** The `java.awt` package contains all the classes necessary for building graphical user interfaces (GUI) in Java, including components, layout managers, and events. 3. **AWT is used for creating a GUI in Java. AWT stands for** - a) Abstract Window Toolkit - b) Advanced Window Toolkit - c) Application Window Toolkit - d) Array Window Toolkit **Answer:** a) Abstract Window Toolkit **Reasoning:** AWT stands for "Abstract Window Toolkit." It is a part of Java's standard library for creating GUI applications, offering components like windows, buttons, and scrollbars. 4. **AWTEvent Class is defined in the following package** - a) java.util - b) java.awt - c) java.io - d) java.lang **Answer:** b) java.awt **Reasoning:** The `AWTEvent` class, which represents events such as mouse clicks or key presses, is part of the `java.awt` package, which is the core package for GUI programming in Java. 5. **A________ is a Component that represents a hierarchical view of data** - a) JList - b) JTree - c) JTable - d) JScrollPane **Answer:** b) JTree **Reasoning:** A `JTree` component in Swing is used to display data in a tree-like hierarchical structure, with nodes representing parent-child relationships. It's commonly used for file system explorers or menus with nested items. 6. **A __________ is a component that presents a rectangular area in which a component may be viewed** - a) JList - b) JScrollPane - c) JTable - d) JPanel **Answer:** b) JScrollPane **Reasoning:** A `JScrollPane` is used to provide a scrollable view of another component, often used when content is larger than the available display area. 7. **BorderLayout is divided into __________ regions** - a) Three - b) Four - c) Five - d) Six **Answer:** c) Five **Reasoning:** The `BorderLayout` divides the container into five regions: NORTH, SOUTH, EAST, WEST, and CENTER. This layout manager allows for organizing components in these five areas. 8. **BorderLayout class has __________ regions to add components to it** - a) Three - b) Four - c) Five - d) Six **Answer:** c) Five **Reasoning:** Components can be added to the five regions of a `BorderLayout`: NORTH, SOUTH, EAST, WEST, and CENTER. Each region can hold one component. 9. **By default, FlowLayout uses __________ justification** - a) Left - b) Right - c) Center - d) Top **Answer:** c) Center **Reasoning:** In a `FlowLayout`, components are arranged in a row, and the default alignment is centered within the row. 10. **By default, the page-up and page-down increment of a scrollbar is __________** - a) 5 - b) 10 - c) 15 - d) 20 **Answer:** b) 10 **Reasoning:** In Java's AWT, the default increment when you press Page Up or Page Down on a scrollbar is 10 units, which can be adjusted programmatically if needed. 11. **By default, the Frame has a __________** - a) No title bar - b) Title bar, borders, resizing corners - c) Only borders - d) Title bar only **Answer:** b) Title bar, borders, resizing corners **Reasoning:** A `Frame` in AWT comes with a title bar, borders, and resizing corners by default, allowing the user to resize, close, and move the window. 12. **By default, which layout manager is set on an applet?** - a) FlowLayout - b) BorderLayout - c) GridLayout - d) CardLayout **Answer:** a) FlowLayout **Reasoning:** The default layout manager for an applet is `FlowLayout`, which arranges components in a directional flow, like words on a page. 13. **By which method can you set or change the text in a Label?** - a) setText() - b) setLabel() - c) setName() - d) setValue() **Answer:** a) setText() **Reasoning:** The `setText()` method is used to change or set the text displayed in a `Label` component in AWT or Swing. 14. **Canvas is a __________** - a) Window - b) Component - c) Panel - d) Container **Answer:** b) Component **Reasoning:** `Canvas` is a lightweight component in AWT that can be used to draw custom graphics, making it a subclass of `Component`. 15. **Checkable menu items are created using an object of __________ class.** - a) Checkbox - b) CheckboxMenuItem - c) MenuItem - d) JCheckbox **Answer:** b) CheckboxMenuItem **Reasoning:** In AWT, `CheckboxMenuItem` is used to create a checkable menu item, which can be selected or deselected like a checkbox. Let me know if you'd like more answers and reasoning for the remaining questions. [9/6, 23:52] Yuvraj: Here’s the complete set of questions and answers in a more copy- friendly format: --- 1. **At the top of the AWT hierarchy is the** - a) Frame - b) Component - c) Object - d) Container **Answer:** b) Component **Reasoning:** In AWT, every graphical element is derived from the `Component` class. It is the base class for all AWT components (like buttons, checkboxes, text fields, etc.). 2. **AWT classes are contained in the __________ package** - a) java.util - b) java.awt - c) java.io - d) javax.swing **Answer:** b) java.awt **Reasoning:** The `java.awt` package contains all the classes for building graphical user interfaces (GUI) in Java. 3. **AWT is used for creating a GUI in Java. AWT stands for** - a) Abstract Window Toolkit - b) Advanced Window Toolkit - c) Application Window Toolkit - d) Array Window Toolkit **Answer:** a) Abstract Window Toolkit **Reasoning:** AWT stands for "Abstract Window Toolkit." 4. **AWTEvent Class is defined in the following package** - a) java.util - b) java.awt - c) java.io - d) java.lang **Answer:** b) java.awt **Reasoning:** The `AWTEvent` class represents events like mouse clicks and key presses. 5. **A________ is a Component that represents a hierarchical view of data** - a) JList - b) JTree - c) JTable - d) JScrollPane **Answer:** b) JTree **Reasoning:** `JTree` is used to display hierarchical data in Swing. 6. **A __________ is a component that presents a rectangular area in which a component may be viewed** - a) JList - b) JScrollPane - c) JTable - d) JPanel **Answer:** b) JScrollPane **Reasoning:** `JScrollPane` allows for scrolling content in a rectangular area. 7. **BorderLayout is divided into __________ regions** - a) Three - b) Four - c) Five - d) Six **Answer:** c) Five **Reasoning:** The `BorderLayout` divides a container into five regions: NORTH, SOUTH, EAST, WEST, and CENTER. 8. **BorderLayout class has __________ regions to add components to it** - a) Three - b) Four - c) Five - d) Six **Answer:** c) Five **Reasoning:** Components are added to the five regions: NORTH, SOUTH, EAST, WEST, and CENTER. 9. **By default, FlowLayout uses __________ justification** - a) Left - b) Right - c) Center - d) Top **Answer:** c) Center **Reasoning:** In `FlowLayout`, the default alignment is centered. 10. **By default, the page-up and page-down increment of a scrollbar is __________** - a) 5 - b) 10 - c) 15 - d) 20 **Answer:** b) 10 **Reasoning:** The default increment is 10 units. 11. **By default, the Frame has a __________** - a) No title bar - b) Title bar, borders, resizing corners - c) Only borders - d) Title bar only **Answer:** b) Title bar, borders, resizing corners **Reasoning:** `Frame` comes with these default features. 12. **By default, which layout manager is set on an applet?** - a) FlowLayout - b) BorderLayout - c) GridLayout - d) CardLayout **Answer:** a) FlowLayout **Reasoning:** The default layout manager for an applet is `FlowLayout`. 13. **By which method can you set or change the text in a Label?** - a) setText() - b) setLabel() - c) setName() - d) setValue() **Answer:** a) setText() **Reasoning:** The `setText()` method changes or sets the text in a label. 14. **Canvas is a __________** - a) Window - b) Component - c) Panel - d) Container **Answer:** b) Component **Reasoning:** `Canvas` is a lightweight component used to draw graphics. 15. **Checkable menu items are created using an object of __________ class.** - a) Checkbox - b) CheckboxMenuItem - c) MenuItem - d) JCheckbox **Answer:** b) CheckboxMenuItem **Reasoning:** `CheckboxMenuItem` is used to create checkable menu items. 16. **Choose the incorrect statement** - a) BorderLayout b = new BorderLayout(3,4); - b) BorderLayout has 5 regions - c) BorderLayout manages the layout of components - d) BorderLayout is the default layout for a Frame **Answer:** a) BorderLayout b = new BorderLayout(3,4); **Reasoning:** `BorderLayout` constructor doesn't take two integers. 17. **Combobox is a combination of __________** - a) TextField and Button - b) TextField and List - c) TextField and Dropdown List - d) TextArea and Dropdown List **Answer:** c) TextField and Dropdown List **Reasoning:** `JComboBox` combines a text field and a drop-down list. 18. **Components are added to which pane of Swing JApplet?** - a) RootPane - b) ContentPane - c) GlassPane - d) LayeredPane **Answer:** b) ContentPane **Reasoning:** Components are added to the `ContentPane` of a `JApplet`. 19. **Constructors of JSeparator are:** - a) JSeparator(int orientation) - b) JSeparator() - c) JSeparator(String label) - d) Both i and ii **Answer:** d) Both i and ii **Reasoning:** `JSeparator` has two constructors: one with no arguments, and one that specifies the orientation. 20. **Container is the subclass of?** - a) Component - b) Object - c) Frame - d) Panel **Answer:** a) Component **Reasoning:** `Container` is a subclass of `Component`. 21. **Controls not supported by AWT are:** - a) TabbedPane, Table - b) List, Checkbox - c) Label, Button - d) TextField, Menu **Answer:** a) TabbedPane, Table **Reasoning:** `TabbedPane` and `Table` are part of Swing, not AWT. 22. **Current text of label can be obtained using __________.** - a) getLabel() - b) getValue() - c) getText() - d) getName() **Answer:** c) getText() **Reasoning:** `getText()` retrieves the current text in a `Label`. 23. **Default layout manager for Frame is __________.** - a) FlowLayout - b) BorderLayout - c) GridLayout - d) CardLayout **Answer:** b) BorderLayout **Reasoning:** The default layout manager for a `Frame` is `BorderLayout`. 24. **Default layout manager for Panel is __________.** - a) FlowLayout - b) BorderLayout - c) GridLayout - d) CardLayout **Answer:** a) FlowLayout **Reasoning:** A `Panel` uses `FlowLayout` as its default layout. 25. **Default layout manager for Window is __________.** - a) FlowLayout - b) BorderLayout - c) GridLayout - d) CardLayout **Answer:** b) BorderLayout **Reasoning:** The default layout for a `Window` is `BorderLayout`. 26. **Default Layout of Frame is:** - a) FlowLayout - b) GridLayout - c) BorderLayout - d) CardLayout **Answer:** c) BorderLayout **Reasoning:** The default layout for a `Frame` is `BorderLayout`. 27. **Default orientation of progress bar is:** - a) Horizontal - b) Vertical - c) Circular - d) Diagonal **Answer:** a) Horizontal **Reasoning:** By default, a `JProgressBar` has a horizontal orientation. 28. **Double-buffering, tooltips, dockable toolbars, keyboard accelerators, custom cursors, etc., are new features of:** - a) AWT - b) Swing - c) SWT - d) JavaFX **Answer:** b) Swing ** [9/6, 23:52] Yuvraj: Here’s the next set of questions, answers, and explanations: --- 1. **FileDialog is which kind of dialog box?** - a) Modal - b) Non-modal - c) Modaltype - d) Any type **Answer:** c) Modaltype **Reasoning:** `FileDialog` is modal by default, meaning it blocks interaction with other windows until it is closed. 2. **FlowLayout arranges components from** - a) Top to Bottom - b) Right to Left - c) Left to Right - d) Bottom to Top **Answer:** c) Left to Right **Reasoning:** In `FlowLayout`, components are arranged horizontally from left to right. 3. **FlowLayout does not support this value of alignment** - a) FlowLayout.LEFT - b) FlowLayout.CENTER - c) FlowLayout.RIGHT - d) FlowLayout.BASELINE **Answer:** d) FlowLayout.BASELINE **Reasoning:** `FlowLayout` supports left, center, and right alignment but not baseline alignment. 4. **Font class is available in ___________** - a) java.util - b) java.awt - c) java.io - d) javax.swing **Answer:** b) java.awt **Reasoning:** The `Font` class, used to define fonts, is part of the `java.awt` package. 5. **For adding controls to a window, we use the following method** - a) addControl() - b) setControl() - c) add() - d) setComponent() **Answer:** c) add() **Reasoning:** The `add()` method is used to add components to containers like frames or panels. 6. **For using Swing controls, one must import the __________________________ package** - a) javax.awt.* - b) java.swing.* - c) import java.awt.* - d) import javax.swing.* **Answer:** d) import javax.swing.* **Reasoning:** Swing components reside in the `javax.swing` package. 7. **Frame is a standard window, which is a ____________________ of the Window class from the AWT hierarchy** - a) Parent class - b) Subclass - c) Interface - d) Object **Answer:** b) Subclass **Reasoning:** `Frame` is a subclass of the `Window` class. 8. **getContentPane() method belongs to which class?** - a) JApplet - b) JComponent - c) JFrame - d) JPanel **Answer:** a) JApplet **Reasoning:** The `getContentPane()` method is part of both `JApplet` and `JFrame` classes. 9. **getSelectedCheckbox() method belongs to which class?** - a) Checkbox - b) CheckboxGroup - c) JRadioButton - d) ButtonGroup **Answer:** b) CheckboxGroup **Reasoning:** `CheckboxGroup` is used to manage multiple checkboxes where only one can be selected at a time. 10. **How can the Checkbox class be used to create a radio button in AWT?** - a) By adding action listeners - b) By associating Checkbox objects with a CheckboxGroup - c) By using setSelected() method - d) By using setCheck() method **Answer:** b) By associating Checkbox objects with a CheckboxGroup **Reasoning:** To create a radio button-like behavior, multiple `Checkbox` objects are grouped using `CheckboxGroup`. 11. **How do you change the current layout managers for a container?** - a) Use the setLayout() method - b) Use the setManager() method - c) Use the setComponent() method - d) Use the changeLayout() method **Answer:** a) Use the setLayout() method **Reasoning:** The `setLayout()` method allows you to change the layout manager of a container. 12. **How many checkboxes can we check at a time?** - a) One - b) Two - c) None - d) Multiple **Answer:** d) Multiple **Reasoning:** In AWT, multiple checkboxes can be checked unless they are part of a `CheckboxGroup`. 13. **How to apply an image to a button?** - a) setImage() - b) setIcon() - c) setPicture() - d) Using ImageIcon **Answer:** d) Using ImageIcon **Reasoning:** `ImageIcon` is used to apply images to Swing components like buttons. 14. **How would you set the color of a graphics context called g to cyan?** - a) g.setColor(Color.cyan); - b) g.changeColor(Color.cyan); - c) g.setPaint(Color.cyan); - d) g.setCurrentColor(Color.cyan); **Answer:** a) g.setColor(Color.cyan); **Reasoning:** The `setColor()` method of `Graphics` is used to change the current drawing color. 15. **Identify the correct constructor of Font class?** - a) Font(String name, int fontstyle, int pointsize) - b) Font(int fontstyle, String name, int pointsize) - c) Font(String name, String style, int pointsize) - d) Font(String name, int pointsize, int fontstyle) **Answer:** a) Font(String name, int fontstyle, int pointsize) **Reasoning:** The correct constructor for `Font` is `Font(String name, int style, int size)`. 16. **Identify the wrong constructor of Checkbox** - a) Checkbox(String label) - b) Checkbox(String label, boolean state) - c) Checkbox(String label, boolean state, CheckboxGroup group) - d) None of the Above **Answer:** d) None of the Above **Reasoning:** All the provided constructors are valid for `Checkbox`. 17. **In an applet, which of the following tags is used for accepting user-defined parameters?** - a) Param - b) Parameter - c) Input - d) Var **Answer:** a) Param **Reasoning:** The `` tag is used in applets to accept parameters from HTML. 18. **In AWT, Checkbox class is used to create __________** - a) Checkboxes - b) Checkboxes and Radio buttons - c) Radio buttons - d) Text fields **Answer:** b) Checkboxes and Radio buttons **Reasoning:** `Checkbox` in AWT can be used for both checkboxes and radio buttons (when used with `CheckboxGroup`). 19. **In AWT, radio buttons are created using _______________** - a) Checkbox - b) RadioButton - c) CheckboxGroup - d) ButtonGroup **Answer:** c) CheckboxGroup **Reasoning:** `CheckboxGroup` ensures that only one checkbox in the group can be selected, thus creating radio button behavior. 20. **In FlowLayout manager, the default space between each component is** - a) 0 pixels - b) 5 pixels - c) 10 pixels - d) 15 pixels **Answer:** b) 5 pixels **Reasoning:** The default horizontal and vertical gap between components in `FlowLayout` is 5 pixels. 21. **In Graphics class, which method is used to set the graphics current color to the specified color?** - a) public abstract void setColor(Color c) - b) public void setCurrentColor(Color c) - c) public void setPaintColor(Color c) - d) public void setRGBColor(Color c) **Answer:** a) public abstract void setColor(Color c) **Reasoning:** The `setColor()` method of `Graphics` is used to specify the current drawing color. 22. **In how many ways can we define the scrollbar?** - a) Horizontal - b) Vertical - c) Both Horizontal and Vertical - d) All of the above **Answer:** d) All of the above **Reasoning:** Scrollbars can be defined as horizontal, vertical, or both. 23. **In Swing, buttons are subclasses of which class?** - a) JButton - b) AbstractButton - c) Button - d) Component **Answer:** b) AbstractButton **Reasoning:** All Swing button classes are subclasses of `AbstractButton`. 24. **In Swing, the content pane can be obtained via method ________** - a) getPanel() - b) getContentPane() - c) getContainer() - d) getFrame() **Answer:** b) getContentPane() **Reasoning:** `getContentPane()` retrieves the content pane of a Swing container like `JFrame`. 25. **In Swing, __________ is a component [9/6, 23:52] Yuvraj: It looks like the list was cut off at the last question. Here’s the continuation with any remaining items: --- 28. **Double-buffering, tooltips, dockable toolbars, keyboard accelerators, custom cursors, etc., are new features of:** - a) AWT - b) Swing - c) SWT - d) JavaFX **Answer:** b) Swing **Reasoning:** `Swing` introduced many new features like double-buffering, custom cursors, tooltips, and dockable toolbars, which were not available in AWT. 29. **Each menu is associated with a __________ list of menu items.** - a) Pop-up - b) Drop-down - c) Side-menu - d) Scrollable **Answer:** b) Drop-down **Reasoning:** A `Menu` in AWT or Swing typically displays a drop-down list of menu items when clicked. 30. **Every layout manager is an instance of __________.** - a) Layout - b) LayoutManager - c) LayoutEngine - d) ComponentLayout **Answer:** b) LayoutManager **Reasoning:** Every layout manager in Java (such as `FlowLayout`, `BorderLayout`, etc.) is an instance of the `LayoutManager` interface, which defines how components should be arranged. 31. **Executable applet is nothing but __________ file of applet.** - a).java - b).class - c).xml - d).exe **Answer:** b).class **Reasoning:** When an applet is compiled, it is turned into a `.class` file, which can then be executed by the Java virtual machine. --- Now the list is complete. Let me know if you need further adjustments! [9/6, 23:52] Yuvraj: Here’s the continuation from question 25: --- 25. **In Swing, __________ is a component that displays rows and columns of data.** - a) JTextArea - b) JList - c) JTable - d) JScrollPane **Answer:** c) JTable **Reasoning:** `JTable` is the Swing component that displays data in rows and columns, like a table. 26. **In Swing, tables are implemented by the ______________ class.** - a) JList - b) JTable - c) JScrollPane - d) TableModel **Answer:** b) JTable **Reasoning:** The `JTable` class implements tables in Swing, allowing for tabular data representation. 27. **Identify which is a valid constructor of the MenuItem class.** - a) MenuItem() - b) MenuItem(String label) - c) MenuItem(String label, boolean state) - d) MenuItem(int index) **Answer:** b) MenuItem(String label) **Reasoning:** The valid constructor `MenuItem(String label)` creates a menu item with a specific label. 28. **Items are added in JComboBox using the method……** - a) add() - b) insert() - c) addItem() - d) setItem() **Answer:** c) addItem() **Reasoning:** The `addItem()` method is used to add items to a `JComboBox` in Swing. 29. **JApplet class is derived from** - a) JPanel - b) JFrame - c) Applet - d) JComponent **Answer:** c) Applet **Reasoning:** `JApplet` is a subclass of the AWT `Applet` class, extended for use with Swing. 30. **Java supports input/output of data through the classes included in the _______ package.** - a) java.awt - b) java.io - c) java.util - d) javax.swing **Answer:** b) java.io **Reasoning:** The `java.io` package contains classes for handling input and output operations like reading from and writing to files. 31. **JCheckBox is a _______________________ Component.** - a) heavyweight - b) medium-weight - c) lightweight - d) abstract **Answer:** c) lightweight **Reasoning:** `JCheckBox` is a lightweight component in Swing, meaning it is drawn entirely in Java and does not rely on native system components. --- That concludes all the answers with reasoning from 25th onwards. Let me know if you need anything else! [9/6, 23:52] Yuvraj: Here are the answers and reasoning for the next set of questions: --- 1. **JRadioButton is a subclass of ________.** - a) JComponent - b) AbstractButton - c) JButton - d) ButtonGroup **Answer:** b) AbstractButton **Reasoning:** `JRadioButton` inherits from `AbstractButton`, which is the base class for all button types in Swing. 2. **JTabbedPane class is present in which package?** - a) java.awt - b) javax.swing - c) java.util - d) java.io **Answer:** b) javax.swing **Reasoning:** `JTabbedPane` is part of the Swing library, which resides in the `javax.swing` package. 3. **JTree class comes under which package?** - a) java.awt - b) javax.swing - c) java.util - d) java.io **Answer:** b) javax.swing **Reasoning:** The `JTree` class, used for displaying hierarchical data, is part of the `javax.swing` package. 4. **List can be created for multiple selections by using the following constructor.** - a) List() - b) List(int num) - c) List(int num, boolean multiselect) - d) List(boolean multiselect) **Answer:** c) List(int num, boolean multiselect) **Reasoning:** The `List` constructor with `num` and `multiselect` allows specifying the number of visible items and whether multiple selections are allowed. 5. **Model is the _________ of the MVC architecture.** - a) Topmost level - b) Middle level - c) Bottom most level - d) UI level **Answer:** c) Bottom most level **Reasoning:** In the MVC architecture, the `Model` represents the data and business logic, forming the lowest level of the architecture. 6. **Mouse click will always generate ________________ event?** - a) ActionEvent - b) MouseEvent - c) KeyEvent - d) ItemEvent **Answer:** b) MouseEvent **Reasoning:** A mouse click generates a `MouseEvent`, which captures all types of mouse actions like clicks, presses, and releases. 7. **MutableTreeNode extends the __________________ interface.** - a) Serializable - b) TreeNode - c) Cloneable - d) Iterable **Answer:** b) TreeNode **Reasoning:** `MutableTreeNode` extends the `TreeNode` interface, which is used for tree data structures. 8. **MVC Architecture is** - a) Model-View-Control - b) Model-Value-Controller - c) Model-View-Controller - d) Menu-View-Controller **Answer:** c) Model-View-Controller **Reasoning:** `MVC` stands for `Model-View-Controller`, a software design pattern used for developing user interfaces. 9. **Name the class used to represent a GUI application window, which is optionally resizable and can have a title bar, an icon, and menus.** - a) JPanel - b) JFrame - c) Frame - d) Dialog **Answer:** c) Frame **Reasoning:** `Frame` is a top-level window with a title bar, resizable options, and can have menus and icons. 10. **On which side is an applet always executed?** - a) Server-side - b) Client-side - c) Middleware - d) Proxy **Answer:** b) Client-side **Reasoning:** Applets run on the client side, within a web browser or applet viewer. 11. **Package of drawString() method is** - a) java.util - b) java.awt - c) java.io - d) javax.swing **Answer:** b) java.awt **Reasoning:** The `drawString()` method, used for drawing text on components, is part of the `Graphics` class in the `java.awt` package. 12. **Panel is defined as** - a) a container - b) an object - c) a component - d) All of the above **Answer:** d) All of the above **Reasoning:** A `Panel` can be seen as a container that holds components, is a subclass of `Component`, and is an object in Java. 13. **Panel is used for __________ components.** - a) Individual - b) Grouping - c) Single - d) Multiple **Answer:** b) Grouping **Reasoning:** A `Panel` is typically used to group multiple components together. 14. **Pluggable Look & Feel is the feature of** - a) AWT - b) Swing - c) JavaFX - d) SWT **Answer:** b) Swing **Reasoning:** Swing allows for pluggable Look and Feel, which means you can change the appearance of components without altering their functionality. 15. **Positions the components into five regions: east, west, north, south, center.** - a) FlowLayout - b) BorderLayout - c) GridLayout - d) CardLayout **Answer:** b) BorderLayout **Reasoning:** `BorderLayout` divides the container into five regions: east, west, north, south, and center. 16. **Program which executes applet is known as________.** - a) JavaExecutor - b) Browser - c) AppletRunner - d) AppletViewer **Answer:** d) AppletViewer **Reasoning:** `AppletViewer` is a program used to run and test applets independently of a browser. 17. **public class MenuBar extends ____________________.** - a) Object - b) MenuComponent - c) JMenuItem - d) Container **Answer:** b) MenuComponent **Reasoning:** `MenuBar` is a subclass of `MenuComponent`, which represents menu-related components. 18. **Scrollbar( ) creates a ______________ scroll bar by default.** - a) Horizontal - b) Vertical - c) Bidirectional - d) None of the above **Answer:** b) Vertical **Reasoning:** By default, the `Scrollbar` class creates a vertical scrollbar. 19. **Select the proper constructor of FileDialog.** - a) FileDialog() - b) FileDialog(Frame parent, String boxName) - c) FileDialog(String path) - d) FileDialog(Frame parent) **Answer:** b) FileDialog(Frame parent, String boxName) **Reasoning:** The correct constructor for `FileDialog` is `FileDialog(Frame parent, String title)`. 20. **Select the proper syntax to add a component in an applet.** - a) Component add(Component compObj) - b) Component addComponent(Component compObj) - c) add(Component compObj) - d) setComponent(Component compObj) **Answer:** c) add(Component compObj) **Reasoning:** The `add()` method is used to add components to a container in an applet. 21. **setBorder() method is used to set a border for ________.** - a) JPanel - b) JComponent - c) JLabel - d) JButton **Answer:** b) JComponent **Reasoning:** The `setBorder()` method is available for any class that extends `JComponent` in Swing. 22. **setMenuBar() method belongs to which class?** - a) Applet - b) Frame - c) Panel - d) Dialog **Answer:** b) Frame **Reasoning:** The `setMenuBar()` method is used to set a menu bar for a `Frame`. 23. **State true or false: i) AWT is an extended version of Swing ii) Paint( ) of Applet class cannot be overridden.** - a) i-true, ii-false - b) i-false, ii-true - c) i-true, ii-true - d) i-false, ii-false **Answer:** d) i-false, ii-false **Reasoning:** i) Swing is an extended version of AWT, not the other way around. ii) The `paint()` method of `Applet` can be overridden. 24. **Swing components are** - a) heavyweight and platform dependent - b) lightweight and platform independent - c) medium-weight and platform independent - d) heavyweight and platform independent **Answer:** b) lightweight and platform independent **Reasoning:** Swing components are lightweight and do not rely on native code, making them platform-independent. 25. **Swing is the set of ____________ that provides more powerful & flexible components compared to AWT.** - a) Interfaces - b) Libraries [9/6, 23:52] Yuvraj: Here are the answers from question 25 onward, continuing from the question on Swing: --- 26. **Swing is the set of ____________ that provides more powerful & flexible components compared to AWT.** - a) Interfaces - b) Libraries **Answer:** b) Libraries **Reasoning:** Swing is a set of libraries in Java that provides a more flexible and powerful GUI compared to AWT. 27. **Text field is usually called as** - a) edit control - b) button - c) list box - d) scroll bar **Answer:** a) edit control **Reasoning:** A `TextField` is commonly referred to as an edit control, where users can input or edit text. 28. **TextField class is used for __________.** - a) Multi-line text-entry area - b) Single-line text-entry area - c) Password field - d) Displaying images **Answer:** b) Single-line text-entry area **Reasoning:** The `TextField` class in Java is used to create a single-line text input area. 29. **The Applet class is in __________ package.** - a) java.util - b) java.awt - c) java.applet - d) javax.swing **Answer:** c) java.applet **Reasoning:** The `Applet` class is part of the `java.applet` package, used for creating applets in Java. 30. **The AWT container is an instance of the ___________ class which holds various components and other containers.** - a) Container - b) Window - c) Frame - d) Panel **Answer:** a) Container **Reasoning:** A `Container` is a class in AWT that can hold components and other containers. 31. **The CardLayout class defines the following constructors:** - a) CardLayout() - b) CardLayout(int horizontalGap, int verticalGap) - c) Both a and b **Answer:** c) Both a and b **Reasoning:** The `CardLayout` class has two constructors: a default constructor and one that takes horizontal and vertical gaps as parameters. 32. **The CardLayout class manages the components in such a manner that** - a) Only one component is visible at a time - b) All components are visible at once - c) It arranges components in a grid - d) It arranges components in a list **Answer:** a) Only one component is visible at a time **Reasoning:** `CardLayout` allows only one component to be visible at a time, like flipping through cards. --- This should conclude the questions and answers for this set. Let me know if you need further clarification! [9/7, 01:30] Ekrama V.P: Here are the first 15 questions with logical options, correct answers, and explanations: --- 1. **The concept of the menu bar can be implemented by using three Java classes—** - A. JMenu, JMenuBar, JMenuItem - B. Menu, MenuBar, MenuItem - C. MenuBar, Menu, ItemListener - D. Component, Container, Menu - **Answer: A. JMenu, JMenuBar, JMenuItem** - **Explanation:** In Swing, the menu bar is implemented using `JMenuBar`, and individual menus are represented by `JMenu`. Menu items are created with `JMenuItem`. --- 2. **The coordinate of the upper-left corner of a frame is ________.** - A. (100, 100) - B. (200, 200) - C. (0, 0) - D. (50, 50) - **Answer: C. (0, 0)** - **Explanation:** The coordinate (0, 0) represents the upper-left corner of a frame in most GUI frameworks, including Java Swing. --- 3. **The correct hierarchy for a panel is:** - A. Object → Component → Container → Panel - B. Component → Container → Panel - C. Container → Component → Panel - D. Panel → Container → Component - **Answer: B. Component → Container → Panel** - **Explanation:** In Java, the hierarchy follows this structure: `Component` is the base class, followed by `Container`, and then `Panel` as a specialized container. --- 4. **The default layout manager for the content pane of a Swing-based applet is:** - A. GridLayout - B. FlowLayout - C. BorderLayout - D. CardLayout - **Answer: C. BorderLayout** - **Explanation:** The default layout manager for the content pane in Swing is `BorderLayout`, which arranges components in five regions: north, south, east, west, and center. --- 5. **Which of the following specifies the advantages of Swing?** - A. Lightweight - B. Supports pluggable look and feel - C. Follows MVC architecture - D. All of the above - **Answer: D. All of the above** - **Explanation:** Swing is lightweight, supports a pluggable look and feel, and follows the MVC (Model View Controller) design pattern. --- 6. **The method `drawRect()` is used to display an:** - A. Filled rectangle - B. Empty rectangle - C. Outlined rectangle - D. Dotted rectangle - **Answer: C. Outlined rectangle** - **Explanation:** The `drawRect()` method draws an outlined rectangle, not a filled one. To fill the rectangle, the `fillRect()` method is used. --- 7. **The method `setLabel()` can be used with what type of object?** - A. Button - B. Label - C. TextField - D. MenuItem - **Answer: C. TextField** - **Explanation:** The `setLabel()` method is typically used with `TextField` objects to set their label or text. --- 8. **The method ______ gets the text of the button `jtb`.** - A. `jtb.getText()` - B. `jtb.getLabel()` - C. `jtb.getButtonText()` - D. `jtb.readText()` - **Answer: A. `jtb.getText()`** - **Explanation:** The `getText()` method is used to retrieve the text from a button in Swing. --- 9. **The method ______ places a menu `mu` into a menu bar `mb`.** - A. `mb.set(mu)` - B. `mb.insert(mu)` - C. `mb.add(mu)` - D. `mb.put(mu)` - **Answer: C. `mb.add(mu)`** - **Explanation:** To add a menu to a menu bar in Swing, the `add()` method is used. --- 10. **The method ______ sets the foreground color to yellow in `JFrame`.** - A. `f.setForeground(Color.YELLOW)` - B. `f.setBackground(Color.YELLOW)` - C. `f.setColor(Color.YELLOW)` - D. `f.setTextColor(Color.YELLOW)` - **Answer: A. `f.setForeground(Color.YELLOW)`** - **Explanation:** The `setForeground()` method sets the text color (foreground) of components, while `setBackground()` changes the background color. --- 11. **The method ______ creates an `IconImage` for file `c:\image\us.gif`.** - A. `new ImageIcon("c:\\image\\us.gif");` - B. `new Image("c:\\image\\us.gif");` - C. `new Icon("c:\\image\\us.gif");` - D. `new ImageIcon("c:/image/us.gif");` - **Answer: A. `new ImageIcon("c:\\image\\us.gif");`** - **Explanation:** The `ImageIcon` constructor takes the file path of the image. In Java, backslashes need to be escaped, hence `\\`. --- 12. **The method `____` gets the text (or caption) of the label `jlbl`.** - A. `jlbl.getCaption()` - B. `jlbl.getText()` - C. `jlbl.getLabel()` - D. `jlbl.readText()` - **Answer: B. `jlbl.getText()`** - **Explanation:** The `getText()` method is used to retrieve the text from a label in Swing. --- 13. **The `setBackground()` method is part of the following class in the `java.awt` package:** - A. Component - B. Container - C. JFrame - D. JComponent - **Answer: A. Component** - **Explanation:** The `setBackground()` method is part of the `Component` class, which is the superclass for most AWT components. --- 14. **The string parameter to the `JButton` constructor:** - A. Sets the button's action - B. Tells what text will appear on the button - C. Sets the button's size - D. Sets the button's color - **Answer: B. Tells what text will appear on the button** - **Explanation:** The string parameter in the `JButton` constructor specifies the text label that appears on the button. --- 15. **The Swing component class that is used to encapsulate a mutually exclusive set of buttons is:** - A. JButton - B. ButtonGroup - C. JCheckBox - D. JRadioButton - **Answer: B. ButtonGroup** - **Explanation:** `ButtonGroup` is used in Swing to create a group of mutually exclusive buttons, typically for radio buttons. --- Let me know if you'd like to continue with the rest! [9/7, 01:32] Ekrama V.P: Here are the remaining questions with logical options, correct answers, and explanations: --- 16. **The syntax for `drawRect()` method is:** - A. `drawRect(int width, int height)` - B. `drawRect(int top, int left, int width, int height)` - C. `drawRect(int x, int y, int width, int height)` - D. `drawRect(int startX, int startY)` - **Answer: C. `drawRect(int x, int y, int width, int height)`** - **Explanation:** The `drawRect()` method in Java takes four parameters: the x and y coordinates of the top-left corner, and the width and height of the rectangle. --- 17. **The `TextArea` controls create a ________.** - A. Single-line text - B. Multi-line text - C. Editable text - D. None of the above - **Answer: B. Multi-line text** - **Explanation:** `TextArea` in Java allows for multi-line text input, unlike `TextField`, which is used for single-line text. --- 18. **The various controls supported by AWT are:** - A. Button, TextField, Label - B. Checkbox, Choice, List - C. TextArea, Scrollbar, Canvas - D. All of these - **Answer: D. All of these** - **Explanation:** AWT (Abstract Window Toolkit) provides various controls like Button, TextField, Label, Checkbox, Choice, List, TextArea, Scrollbar, and Canvas. --- 19. **The various controls supported by Swing are:** - A. JButton, JTextField, JLabel - B. JCheckBox, JList, JScrollBar - C. JTable, JTextArea, JProgressBar - D. All of the above - **Answer: D. All of the above** - **Explanation:** Swing provides a rich set of components including buttons (`JButton`), text fields (`JTextField`), labels (`JLabel`), and more, like `JCheckBox`, `JList`, `JTable`, etc. --- 20. **The __________ arranges components in rows and columns and makes all components the same size.** - A. FlowLayout - B. GridLayout - C. BorderLayout - D. CardLayout - **Answer: B. GridLayout** - **Explanation:** `GridLayout` arranges components in a grid of equally sized cells in rows and columns. --- 21. **The ___________ interface is used to handle button events:** - A. ActionEvent - B. ActionListener - C. MouseListener - D. KeyListener - **Answer: B. ActionListener** - **Explanation:** The `ActionListener` interface is used to handle button click events in Java Swing or AWT. --- 22. **The __________ class is used to create radio buttons in AWT:** - A. JRadioButton - B. Checkbox - C. CheckboxGroup - D. ButtonGroup - **Answer: C. CheckboxGroup** - **Explanation:** In AWT, radio button functionality is implemented using `Checkbox` with a `CheckboxGroup`. --- 23. **The ___________________ can be used to enter or display a string:** - A. Button - B. Label - C. TextField - D. MenuItem - **Answer: C. TextField** - **Explanation:** `TextField` is used for entering or displaying a single line of text. --- 24. **These four methods are commonly used in the ________ class?** - 1) `public void add(Component c)` - 2) `public void setSize(int width, int height)` - 3) `public void setLayout(LayoutManager m)` - 4) `public void setVisible(boolean)` - A. JFrame - B. Component - C. JComponent - D. Container - **Answer: B. Component** - **Explanation:** These methods are part of the `Component` class, which is the superclass for most AWT and Swing components. --- 25. **To create a window with a title bar, which of the following classes is used?** - A. JPanel - B. Window - C. Frame - D. Label - **Answer: C. Frame** - **Explanation:** `Frame` is used to create a window with a title bar in AWT. --- 26. **To create a file dialog box, the __________ class is used:** - A. JFileChooser - B. Dialog - C. FileDialog - D. Frame - **Answer: C. FileDialog** - **Explanation:** `FileDialog` is a class in AWT used to create a dialog box for file selection. --- 27. **The method `drawRect()` is used to display an:** - A. Filled rectangle - B. Empty rectangle - C. Outlined rectangle - D. Solid rectangle - **Answer: C. Outlined rectangle** - **Explanation:** The `drawRect()` method in Java draws the outline of a rectangle. --- 28. **The method `setLabel()` can be used with what type of object?** - A. Button - B. Label - C. TextField - D. Menu - **Answer: C. TextField** - **Explanation:** The `setLabel()` method is typically used with a `TextField` to set the label or text in the field. --- 29. **The method `____` gets the text of the button `jtb`.** - A. `jtb.getText()` - B. `jtb.getLabel()` - C. `jtb.getName()` - D. `jtb.getValue()` - **Answer: A. `jtb.getText()`** - **Explanation:** The `getText()` method is used to retrieve the text displayed on a button. --- 30. **The method `mb.add(mu)` places a menu `mu` into a menu bar `mb`.** - **Answer: Correct, no modification needed.** - **Explanation:** The `add()` method is used to add a `JMenu` to a `JMenuBar`. --- These are the rest of the questions with logical options, answers, and explanations. Let me know if you need any further clarification! [9/7, 05:25] Ekrama V.P: Here are the remaining questions, with logical options, correct answers (kept as you provided), and explanations: --- 1. **To display text on the applet ______ method is used.** - A. displayText() - B. drawString() - C. showText() - D. writeText() - **Answer: B. drawString()** - **Explanation:** The `drawString()` method is used to draw text on the applet at a specified location. --- 2. **To draw a line in an applet, we use the following method:** - A. drawRect() - B. drawOval() - C. drawLine() - D. drawShape() - **Answer: C. drawLine()** - **Explanation:** The `drawLine()` method is used to draw a line between two points. --- 3. **To fetch the caption of a button, the ___________ method is used.** - A. getCaption() - B. getText() - C. getLabel() - D. getTitle() - **Answer: C. getLabel()** - **Explanation:** The `getLabel()` method is used to retrieve the text displayed on a button. --- 4. **To retrieve the current state of a checkbox, call ______________.** - A. isSelected() - B. getChecked() - C. getState() - D. isChecked() - **Answer: C. getState()** - **Explanation:** The `getState()` method is used to determine whether a checkbox is checked or not. --- 5. **To set the title of the frame window, the ___________ method is used.** - A. setWindowTitle(String) - B. setFrameTitle(String) - C. setTitle(String) - D. setCaption(String) - **Answer: C. setTitle(String)** - **Explanation:** The `setTitle()` method sets the title of the frame window. --- 6. **We can add menus to ____________________.** - A. Dialogs - B. Panels - C. Frames - D. Buttons - **Answer: C. Frames** - **Explanation:** Menus in Java are added to `Frame` objects. --- 7. **What are controls or components?** - A. UI elements for displaying text - B. Elements that allow users to interact with applications - C. Only input fields and buttons - D. Data containers for backend operations - **Answer: B. Controls or components allow users to interact with applications** - **Explanation:** Components such as buttons, checkboxes, and text fields enable user interaction with the application. --- 8. **What are the TextComponent classes?** - A. TextField, TextPane - B. TextBox, TextLabel - C. TextArea, TextEditor - D. TextField, TextArea - **Answer: D. TextField, TextArea** - **Explanation:** `TextField` is for single-line input, while `TextArea` is for multi-line input. --- 9. **What are the types of dialog boxes?** - A. System and User Dialogs - B. Modal and Modeless Dialogs - C. Single and Multi Dialogs - D. Interactive and Non-Interactive Dialogs - **Answer: B. Modal and Modeless Dialogbox** - **Explanation:** A modal dialog blocks user input to other windows, whereas a modeless dialog allows interaction with other windows. --- 10. **What are the variables defined in Dimension?** - A. width and length - B. width and depth - C. height and length - D. height and width - **Answer: D. height and width** - **Explanation:** The `Dimension` class holds the width and height of a component. --- 11. **What Checkbox method allows you to tell if a Checkbox is checked?** - A. isChecked() - B. getState() - C. isSelected() - D. checkStatus() - **Answer: B. getState()** - **Explanation:** The `getState()` method checks the status of a checkbox. --- 12. **What does the following line of code do? `TextField text = new TextField(10);`** - A. Creates a `TextField` object with 10 characters - B. Sets a default value of 10 - C. Sets the size of the `TextField` to 10px - D. Creates a `TextField` object that can hold 10 columns of text - **Answer: D. Creates a `TextField` object that can hold 10 columns of text.** - **Explanation:** The number 10 specifies the number of columns the `TextField` can hold. --- 13. **What is API?** - A. Application Provider Interface - B. Application Programming Interface - C. Application Process Interface - D. Advanced Programming Interface - **Answer: B. Application Programming Interface** - **Explanation:** API stands for Application Programming Interface, which allows software to communicate with other software. --- 14. **What is the default alignment of components using FlowLayout?** - A. FlowLayout.LEFT - B. FlowLayout.RIGHT - C. FlowLayout.CENTER - D. FlowLayout.TOP - **Answer: C. FlowLayout.CENTER** - **Explanation:** The default alignment for `FlowLayout` is centered. --- 15. **What is the default layout manager for panels and applets?** - A. BorderLayout - B. FlowLayout - C. GridLayout - D. CardLayout - **Answer: B. FlowLayout** - **Explanation:** Panels and applets use `FlowLayout` as the default layout manager. --- 16. **What is the default layout for a dialog?** - A. FlowLayout - B. GridLayout - C. BorderLayout - D. CardLayout - **Answer: C. BorderLayout** - **Explanation:** By default, dialogs in Java use `BorderLayout`. --- 17. **What is the difference between a TextArea and a TextField?** - A. TextField can hold multiple lines - B. TextArea can hold multiple lines of text - C. TextArea is single-line input - D. TextField handles multi-line input - **Answer: B. A TextArea can handle multiple lines of text** - **Explanation:** `TextArea` can handle multiple lines, while `TextField` is limited to one line of input. --- 18. **What is the minimum and maximum of JProgressBar?** - A. minimum 0, maximum 100 - B. minimum 10, maximum 200 - C. minimum 0, maximum 50 - D. minimum -50, maximum 50 - **Answer: A. minimum 0, maximum 100** - **Explanation:** The default range for `JProgressBar` is 0 to 100. --- 19. **What is the use of the following method in JDialog? `Container getContentPane()`** - A. Returns the parent container - B. Returns a Content Pane for the JDialog - C. Sets the content of the dialog - D. Removes content from the dialog - **Answer: B. This method returns a Content Pane for the JDialog** - **Explanation:** `getContentPane()` returns the content pane of the dialog for adding components. --- 20. **What is the use of the 3rd parameter in the constructor `Scrollbar(int, int, int, int, int)`?** - A. Start position - B. Maximum value - C. Thumbsize - D. Scroll speed - **Answer: C. Thumbsize** - **Explanation:** The third parameter in the `Scrollbar` constructor specifies the size of the scrollbar's thumb (the draggable part). --- 21. **What is the use of the second parameter in the constructor `Label(String, int)`?** - A. Sets the text color - B. Specifies alignment of the text in terms of pixel - C. Specifies font size - D. Sets background color - **Answer: B. Specifies the alignment of the text in label in terms of pixel** - **Explanation:** The second parameter sets the alignment of the label's text. --- 22. **What layout manager should you use so that every component occupies the same size in the container?** - A. FlowLayout - B. GridLayout - C. BorderLayout - D. CardLayout - **Answer: B. GridLayout** - **Explanation:** `GridLayout` makes all components the same size by dividing the container into a grid of equally sized cells. --- 23. **What letter precedes Swing component names that have a corresponding AWT component?** - A. S - B. C - C. J - D. W - **Answer: C. J** - **Explanation:** Swing components are prefixed with "J", such as `JButton`, `JLabel`, etc., to distinguish them from AWT components. --- 24. **What method is used to prevent a [9/7, 05:29] Ekrama V.P: Yes, it looks like the response was cut off towards the end. Let me continue with the remaining questions from where it left off: --- 24. **What method is used to prevent a user from changing the size of a `Frame()` object?** - A. setSize(false) - B. setFixedSize() - C. setResizable(false) - D. setBounds() - **Answer: C. setResizable(false)** - **Explanation:** The `setResizable(false)` method is used to prevent the user from resizing the frame. --- 25. **What methods are used to get and set the text label displayed by a `Button` object?** - A. getText() and setText() - B. getLabel() and setLabel() - C. getTitle() and setTitle() - D. getCaption() and setCaption() - **Answer: B. getLabel() and setLabel()** - **Explanation:** The `getLabel()` method retrieves the label's text, and `setLabel()` sets the text of the button. --- 26. **When a DialogBox is closed, which method gets called?** - A. close() - B. dispose() - C. hide() - D. end() - **Answer: B. dispose()** - **Explanation:** The `dispose()` method is called when a dialog box is closed to free up resources. --- 27. **When the layout manager is disabled, which method is used to determine the shape and position of a component?** - A. setSize() - B. setPosition() - C. setBounds() - D. setShape() - **Answer: C. setBounds** - **Explanation:** The `setBounds()` method is used to manually set the size and position of a component when the layout manager is disabled. --- 28. **When we invoke `repaint()` for a `java.awt.Component` object, the AWT invokes the method:** - A. paint() - B. update() - C. refresh() - D. draw() - **Answer: B. update()** - **Explanation:** The `update()` method is called when `repaint()` is invoked, and it subsequently calls the `paint()` method to redraw the component. --- Now, all the questions are fully answered! If you need further clarification or anything else, feel free to ask! [9/7, 12:25] Ekrama V.P: Here are the updated questions with logical options, followed by the answers and explanations: --- **253. Which of the following method is used to retrieve the icon of JButton?** A) getImage() B) getIcon() C) getPicture() D) getButtonIcon() **Answer:** B) getIcon() **Explanation:** The `getIcon()` method retrieves the icon associated with a `JButton` in Swing. --- **254. Which of the following methods are invoked by the AWT to support paint and repaint operations?** A) paint() B) repaint() C) update() D) draw() **Answer:** B) repaint() **Explanation:** The `repaint()` method is invoked by AWT to refresh the component. This method schedules a call to `paint()`. --- **255. Which of the following methods can be used to change the size of a java.awt.Component object?** A) setBounds() B) setSize() C) setHeight() D) setDimensions() **Answer:** B) setSize() **Explanation:** The `setSize()` method allows changing the size of a `Component`. --- **256. Which of the following methods can be used to remove a java.awt component object from display?** A) delete() B) destroy() C) remove() D) erase() **Answer:** C) remove() **Explanation:** The `remove()` method is used to remove a component from the display in AWT. --- **257. Which of the following statements about GUI components is wrong?** A) Swing is lightweight B) AWT is heavyweight C) The AWT classes are deprecated D) Swing supports pluggable look and feel **Answer:** C) The AWT classes are deprecated (Changed) **Explanation:** The AWT classes are not deprecated, though Swing is preferred due to its lightweight nature. --- **258. Which of the following statements is for placing the frame's upper-left corner to (200,100)?** A) frame.setBounds(200,100) B) frame.setPosition(200,100) C) frame.setLocation(200,100) D) frame.setCorner(200,100) **Answer:** C) frame.setLocation(200,100) **Explanation:** The `setLocation()` method sets the frame's position on the screen at the specified coordinates. --- **259. Which of the following swing components do not have an Icon parameter in its constructor?** A) JButton B) JLabel C) JCheckBox D) JTextField **Answer:** D) JTextField **Explanation:** `JTextField` is a text-based input component and doesn't support an `Icon` in its constructor. --- **260. Which of the following is the constructor of JTable?** A) JTable(Object data[][], Object colHeads[]) B) JTable(Object[][], String[]) C) JTable(String data[][], Object colNames[]) D) JTable(Object data[], Object[]) **Answer:** A) JTable(Object data[][], Object colHeads[]) **Explanation:** This constructor of `JTable` creates a table to display the given data and column headers. --- **261. Which method can be used to output a string in an applet?** A) draw() B) paintText() C) drawString() D) displayText() **Answer:** C) drawString() **Explanation:** The `drawString()` method draws a string at the specified location in an applet. --- **262. Which method of the Choice class returns a string containing the name of the selected item?** A) getSelected() B) getSelectedItem() C) getChoiceItem() D) getName() **Answer:** B) getSelectedItem() **Explanation:** `getSelectedItem()` retrieves the selected item from a `Choice` component in AWT. --- **263. Which of the following are subclasses of java.awt.Component?** A) Container classes B) Dialog classes C) Window classes D) LayoutManager classes **Answer:** A) Container classes **Explanation:** `Container` is a subclass of `Component`, which can hold other components like panels and frames. --- **264. Which of these components can be added to a frame?** A) JButton B) JLabel C) JPanel D) All of the Above **Answer:** D) All of the Above **Explanation:** All these components (`JButton`, `JLabel`, and `JPanel`) can be added to a `JFrame`. --- **265. Which of the following is not a component of Swing?** A) JButton B) JPanel C) JTextField D) List **Answer:** D) List **Explanation:** `List` is an AWT component, while `JList` is the Swing equivalent. --- **266. Which of these methods cannot be called on a JLabel object?** A) setText() B) setIcon() C) setBorder() D) setBorderLayout() **Answer:** D) setBorderLayout() **Explanation:** `JLabel` doesn’t use layout managers like `setBorderLayout()`. Layouts are used on containers. --- **267. Which of these methods can be used to obtain the reference to the container that generated a ContainerEvent?** A) getComponent() B) getSource() C) getContainer() D) getEventContainer() **Answer:** C) getContainer() **Explanation:** The `getContainer()` method returns the container that generated the `ContainerEvent`. --- **268. Which of these methods can be used to output a string in an applet?** A) printText() B) drawText() C) drawString() D) displayString() **Answer:** C) drawString() **Explanation:** The `drawString()` method is used to display text in a specified location within an applet. --- **269. Which of these methods cannot be called on a JLabel object?** A) setText() B) setIcon() C) setToolTipText() D) setBorderLayout() **Answer:** D) setBorderLayout() **Explanation:** `JLabel` doesn't handle layout managers like `BorderLayout`. --- **270. Which of these methods cannot be called on a TextArea?** A) appendText() B) insertText() C) String getItem(int index) D) replaceRange() **Answer:** C) String getItem(int index) (Changed) **Explanation:** `TextArea` handles text, not items. This method is invalid for a `TextArea`. --- **271. Which of these methods is used to set the window's dimensions?** A) setBounds() B) setSize() C) setDimensions() D) setHeightWidth() **Answer:** B) setSize() **Explanation:** The `setSize()` method sets the width and height of a window. --- **272. Which of these methods are used in CardLayout?** A) addLayout() B) addCard() C) add(String s, Component c) D) addCardLayout() **Answer:** C) add(String s, Component c) **Explanation:** This method is used in `CardLayout` to add a component with a name identifier. --- **273. Which of these packages is used for graphical user interfaces?** A) java.awt B) java.util C) java.io D) java.lang **Answer:** A) java.awt **Explanation:** `java.awt` is the package that provides GUI components. --- **274. Which of these packages contains all the classes and methods required for event handling in Java?** A) java.event B) java.awt.event C) javax.swing.event D) java.awt **Answer:** B) java.awt.event **Explanation:** `java.awt.event` handles event classes and listeners for GUI components. --- **275. Which one is the valid constructor of JCheckBox?** A) JCheckBox(String s) B) JCheckBox(String s, Icon i) C) JCheckBox(String s, Boolean state) D) All of the Above **Answer:** D) All of the Above **Explanation:** `JCheckBox` can have multiple constructors including text, icon, and state options. --- **276. Which method is used to set the visibility of the frame?** A) setVisible(true) B) showFrame() C) display() D) setDisplay(true) **Answer:** A) setVisible(true) **Explanation:** The `setVisible()` method controls the visibility of a frame. --- **277. Which package is used to import Swing components?** A) java.awt.swing B) javax.swing C) java.swing D) swing.components **Answer:** B) javax.swing **Explanation:** Swing components are part of the `javax.swing` package. --- **278. Which TextComponent method is used to set a TextComponent to the read-only state?** A) setEditable() B) setReadOnly() C) setUneditable() D) setVisible(false) **Answer:** A) setEditable() **Explanation:** The `setEditable()` method is used to make a `TextComponent` read- only. --- **279. Which type of button belongs to a group such that only one button in the group may be selected at one time?** A) JButton B) JCheckBox C) RadioButton D) CheckboxGroup **Answer:** D) CheckboxGroup (Changed) [9/7, 12:40] Ekrama V.P: Here are the questions with logical options and answers as per your instructions. If I found an invalid answer, I have mentioned it. --- **281. Why are swing components termed as lightweight?** A) They use native platform resources B) They are easier to code C) They do not depend on native platform D) They run faster **Answer:** C) They do not depend on native platform **Explanation:** Swing components are called lightweight because they are written entirely in Java and do not depend on the native operating system's graphical system. --- **282. Why do we use Applet?** A) To create dynamic content B) To run on web browsers C) Both A and B D) None of these **Answer:** C) Both A and B **Explanation:** Applets are used to create dynamic content that can be embedded in web browsers, allowing interaction over the web. --- **283. Window is the superclass of ____________.** A) Frame B) Panel C) TextField D) Applet **Answer:** A) Frame **Explanation:** In Java AWT, the `Window` class is the superclass of the `Frame` class, which represents a top-level window. --- **284. Window, Frame, and Dialog use ________ as their default layout.** A) FlowLayout B) BorderLayout C) GridLayout D) CardLayout **Answer:** B) BorderLayout **Explanation:** By default, `Window`, `Frame`, and `Dialog` use `BorderLayout`, which arranges components in five regions: north, south, east, west, and center. --- **285. You can construct a JTabbedPane using ____________.** A) new TabbedPane() B) new JTabbedPane() C) new TabPanel() D) new JPanel() **Answer:** B) new JTabbedPane() **Explanation:** The `JTabbedPane` constructor is used to create a tabbed pane where multiple panels can be added. --- **286. You can set the alignment of the string within the label by calling ________________________.** A) setText() B) setAlignment() C) setHorizontalAlignment() D) setStringAlign() **Answer:** C) setHorizontalAlignment() **Explanation:** `setHorizontalAlignment()` is the method used to set the horizontal align

Use Quizgecko on...
Browser
Browser