Home Tuitions

chapter-Java GUI Programming Using Swing-II

Important MCQ-Based Questions on Informatics Practices (IP) class 11 chapter-Java GUI Programming Using Swing-II

This page consists of Important MCQ-Based Questions on Informatics Practices (IP) class 11 chapter-Java GUI Programming Using Swing-II all the questions are uploaded for practice with detailed explanations of every question. To check the solution, click on the answer. 

Find below Important MCQ-Based Questions on Informatics Practices (IP) class 11 chapter-Java GUI Programming Using Swing-II

Important Questions for Informatics Practices (IP) class 11 chapter-Java GUI Programming Using Swing-II set-1

Informatics Practices - MCQ on Java GUI Programming Using Swing-II

Class XI

Q.1 Character displayed in place of text being entered is known as

a) toolTip.

b) Echo character.

c) password.

d) Action event.

Answer:

(b) Echo character.

Explanation- Password field displays encrypted text known as echo character(echoChar). The default echoChar is dot.

Q.2 A Label control displays text that

a) cannot be changed or edited.

b) can be changed.

c) can be changed but not edited.

d) can be changed and edited.

Answer:

(a)cannot be changed or edited.

Explanation- A Label control displays text that the user cannot directly change or edit. The actual text displayed in a label is controlled by its text property.

Q.3 Foreground property of a component sets the

a) background color of the label..

b) specify the type of border that will surround the component.

c) Foreground color for the component.

d) Font for the text.

Answer:

(c)foreground color for the component.

Explanation: Foreground property sets the foreground color for the component, i.e., the text of the font will now appear in this color.

Q.4 To set the image towards the leading edge of the label we need to set

a) horizontalTextPosition.

b) horizontalAlignment.

c) iconTextGap.

d) verticalAlignment.

Answer:

(b)horizontalAlignment.

Explanation: The image can be set towards the leading edge of the label using horizontalAlignment. This property controls the horizontal placement of label contents within the label.

Q.5 The command used to remove the specified window from the screen, the method used is

a) <windowname>.dispose().

b) actionPerformed().

c) <window>setVisible().

d) <windoewname>.JFrame().

Answer:

(a)<windowname>.dispose().

Explanation: The <windowname>.dispose() method removes the specified window from the screen as well as from memory.

Q.6. Control that has a small text editor to get input from user is

a) slider.

b) check box.

c) text field.

d) password field.

Answer:

(c)text field.

Explanation- Text field control is a small text editor that provides all the basic text-editing facilities.

Q.7. Most common event that is fired from a text field is

a) window event.

b) action performed.

c) focus event.

d) action event.

Answer:

(d) action event.

Explanation- JTextField objects fire Action Events any time key is pressed, indicating that the user is finished with the field.

Q.8. The default echoChar is

a) comma(,).

b) curly bracket{}.

c) dot(.).

d) blank.

Answer:

(c)dot(.).

Explanation- The character that is displayed in place of text being entered is known as echoChar. The default echoChar is a dot(.).

Q.9. The role of nextFocusableComponent is to

a) occur when an object receives focus.

b) Occurs when an object loses focus.

c) receive user input.

d) specify the component that should receive the focus next when tab is pressed.

Answer:

(d) specify the component that should receive the focus next when tab is pressed.

Explanation- nextFocusableComponent specifies the component that should receive the focus next when tab is pressed.

Q.10. Bar representing a range of numbers and having a knob is called a

a) slider.

b) scrollbar.

c) titlebar.

d) menubar.

Answer:

(b) scrollbar.

Explanation- A scrollbar is a bar representing a range of numbers and having a scrollable knob also called thumb.

Q.11. Method used to obtain password is

a) setPassword().

b) JPasswordField.

c) echoChar.

d) getPassword().

Answer:

(d) getPassword().

Explanation- To obtain password from a password field, getPassword() method is used.

Q.12. A class that provides a component that displays multiple lines of text and optionally allows the user to edit the text is

a) JTextfield.

b) Editor pane.

c) JTextArea.

d) label.

Answer:

(c) JTextArea.

Explanation- The JTextArea class provides a component that displays multiple lines of text and optionally allows the user to edit the text. If you need to obtain only one line of input from the user, you should use a text field.

Q.13. If you want the text area to display its text using multiple fonts or other styles, you should use

a) editor pane .

b) label.

c) textfield.

d) textarea.

Answer:

(a)editor pane.

Explanation- The JEditorPane class is the foundation for Swing's styled text components and provides a mechanism through which we can add support for custom text formats.

Q.14. A JTextArea mainly fires

a) Action Events.

b) PropertyChange events.

c) Button Events.

d) Focus Events.

Answer:

(b) PropertyChange events.

Explanation- A JTextArea mainly fires PropertyChange events when lineWrap, wrapStyleWord or tabSize properties are changed.

Q.15. int getMaximum( ) method returns

a) value of block incremented.

b) orientation of scrollbar.

c) maximum value of scrollbar.

d) current value.

Answer:

(c) maximum value of scrollbar.

Explanation- int getMaximum() method returns the maximum value of scrollbar.

Q.16. Method use to enable and disable components such as JButton is

a) enable ()

b) setEnabled(boolean b)

c) isEnabled()

d) disable ()

Answer:

(b) setEnabled (boolean b)

Explanation- setEnabled (boolean b), enables or disables this component, depending on the value of the parameter b. An enabled component can respond to user input and generate events. Components are enabled initially by default.

Q.17. An object can receive focus only if it is

a) visible.

b) enabled.

c) disable.

d) enabled and visible.

Answer:

(d) enabled and visible.

Explanation- The enabled property allows object to respond to user-generated events and visible property determines whether an object is visible on the screen.

Q.18. We can give focus to an object by using

a) focus_gained().

b) focus_lost().

c) requestFocus().

d) repeatfocus().

Answer:

(c) requestFocus().

Explanation- We can give focus to an object by using the requestFocus() method on the object.

Q.19. The method that returns the current value of the scrollbar is

a) setValue().

b) getValue().

c) getcurrentvalue().

d) setCurrentvalue().

Answer:

(b) getValue().

Explanation- The getValue() method returns the current value of the scrollbar.

Q.20. Focus is the ability to obtain

a) input from user.

b) output from user.

c) Data from system.

d) password.

Answer:

(a) input from user.

Explanation- Focus is the ability to receive user input through mouse or keyboard.

Q.21. JButton, JCheckBox are

a) Interactive Displays.

b) Containers.

c) Abstract Window Toolkit.

d) Basic Controls.

Answer:

(c) Basic Controls.

Explanation- Basic Swing Controls are simple components that are used primarily to get input from the user.

Q.22. Common event handler for state change in radio button is

a) inputMethodTextChanged.

b) majorTickSpacing.

c) minorTickSpacing.

d) ChangeOccured.

Answer:

(d)ChangeOccured.

Explanation- To add a common event handler, we add event, i.e., ChangedOccured in Handlers for ItemStateChanged dialog that appears when ellipsis is clicked in ItemStateChanged event.

Q.23. Method that sets the slider’s current value and positions is

a) setValue().

b) getValue().

c) setenabled.

d) setVisible().

Answer:

(a) setValue().

Explanation- setValue method sets the slider’s current value and positions the slider’s knob at the new value.

Q.24. Button that replaces the text between starting and ending position is

a) Append button.

b) Replace button.

c) Insert button.

d) Radio button.

Answer:

(b)Replace button.

Explanation- Replace button replaces the text between positions given in Spos text field and Epos text field.

Q.25. Event that is fired when the user selects an item from a menu is

a) MenuEvent.

b) CommandEvent.

c) ActionEvent.

d) UserActionEvent.

Answer:

(c) ActionEvent.

Explanation- An action event occurs, whenever an action is performed by the user.

Q.26. Event handler used for verification and validation updates is

a) stateChanged().

b) ItemStateChanged().

c) requestFocus().

d) focusLost event handler.

Answer:

(d)focusLost event handler.

Explanation- A focusLost event handler is primarily used for verification and validation updates or for reversing or changing conditions that are set up in the object’s focus Gained event handler.

Q.27. ActionListener is

a) a class.

b) an interface.

c) an instance variable.

d) A method.

Answer:

(b)an interface.

Explanation- ActionListener is an interface that contains the single method.

Q.28. The string parameter to the JButton method tells

a) which region to put the button in.

b) the color of the button.

c) what text will appear on the button.

d) what should happen when the button is pressed.

Answer:

(c) what text will appear on the button.

Explanation- String getText() method returns the text displayed by the button.

Q.29. Method call that would make the window myWindow show up on the screen is

a) myWindow.setVisible(true);

b) myWindow.show();

c) myWindow.display();

d) myWindow.showWindow(true);

Answer:

(a) myWindow.setVisible(true);

Explanation- setVisible( boolean ) controls whether a Component and its children are displayed on the screen. myWindow.setVisible(true) method wiould make myWindow visible on the screen.

Q.30 Scrollbar fires an event of

a) Action Event type.

b) PropertyChange Event type.

c) Adjustment event type.

d) MouseMotion Event type.

Answer:

(c) Adjustment event type.

Explanation- The scrollbar fires an event of Adjustment event type, which is fired when a user drags or moves the knob/thumb of the scrollbar.

Q.31. By default a Slider represents a range

a) 10-99.

b) 0-99.

c) 10-100.

d) 0-100.

Answer:

(d) 0-100.

Explanation- By default a slider represents a range 0-100 with no spacing for major or minor ticks.

Q.32. Method that returns the number of values between major ticks is

a) int getMajorTickSpacing().

b) int getMaximum().

c) int getValue().

d) Void setValue(int).

Answer:

(a) int getMajorTickSpacing().

Explanation-This method returns the number of values between major ticks, i.e., the distance measured in values, between each major tick mark.

Q. 33. The property which allows the object to respond to user-generated events is

a) request focus().

b) display property.

c) enabled property.

d) Visible property.

Answer:

(c) enabled property.

Explanation- The enabled property allows the object to respond to user-generated events such as keyboard and mouse events.

Q.34. A Field that can take input without showing it on screen is

a) getPassword.

b) Password Field.

c) Text Field.

d) EchoChar field.

Answer:

(b)Password Field.

Explanation- A Password Field can take input without showing it on screen. In place of text entered, it shows character as specified by its echoChar property.

Q. 35. Java Class that implement text field is

a) JPasswordField.

b) JTextArea.

c) JTextField.

d) JScrollBar.

Answer:

(c) JtextField.

Explanation- JTextField implements a text field.

Q.36. A component that displays an icon, but that doesn’t react to user clicks

a) label.

b) frame.

c) field.

d) Icon.

Answer:

(a)label.

Explanation- With the JLabel class, you can display unselectable text and images. If you need to create a component that displays a string, an image, or both, you can do so by using or extending JLabel.

Q.37. Method use to specify the default button for a top-level container such as a JFrame or JDialog is

a) ListSelectionModel.

b) setDefaultJMenuBar.

c) setDefaultButton.

d) ComponentEvent.

Answer:

(c)setDefaultButton.

Explanation- JRootPane's setDefaultButton method is used to specify the default button for a top-level container.

Q. 38. Method use to enable and disable components such as JButton is

a) setEnabled.

b) enable.

c) enableInputMethods.

d) setVisible.

Answer:

(a) setEnabled

Explanation- setEnabled method enables or disables component, depending on the value of the parameter. An enabled component can respond to user input and generate events. Components are enabled initially by default.

Q.39. Object to create a group of buttons in which only one button at a time can be selected is

a) Radio Button.

b) Check Box.

c) Button.

d) ButtonGroup.

Answer:

(d) ButtonGroup.

Explanation- Creating a set of buttons with the same ButtonGroup object means that turning "on" one of those buttons turns off all other buttons in the group.

Q. 40. Method that sets the value of the radio button is

a) setSelected()

b) getSelected().

c) setValue().

d) getValue().

Answer:

(a) setSelected()

Explanation- This method sets the value of the radio button. This method takes a boolean value either true or false. If you pass true value then the radio button will be selected otherwise the radio button is not selected.

Q.41. A rectangular box where the user can enter data in single line is

a) TextArea.

b) TextField.

c) Label.

d) Event Handler.

Answer:

(b) TextField.

Explanation- Text Field allows the user to enter a single line of text. It acts as a single line text editor.

Q.42. Control is transferred to the actionPerformed method when

a) Checkbox is clicked.

b) Radiobutton is clicked.

c) Actionbutton is clicked.

d) Actionlistener button is clicked.

Answer:

(d) Actionlistener button is clicked.

Explanation- When a actionlistener button is clicked, control is transferred to the actionPerformed method.

Q.43. Component that can be used to enter or display a string is a

a) label.

b) button.

c) radio button.

d) text area.

Answer:

(d) text area.

Explanation- If we need a component that displays or allows entry of more than one line, a JTextArea can be used.

Q.44. A group of usual circular GUI components that allow for only one in the group to be selected is

a) Jcombox.

b) JRadioButton.

c) Jcheckbox.

d) text field.

Answer:

(b)JRadioButton.

Explanation- The JRadioButton class implements a group of buttons in which only one button at a time can be selected.

Q. 45. A component that enables the user to choose a single value or multiple values is

a) a text field.

b) a combo box.

c) a list.

d) a label.

Answer:

(c) a list.

Explanation- A list is a component that performs basically the same function as a combo box, but it enables the user to choose a single value or multiple values.

Q. 46. A boolean gui component that is either selected or deselected is

a) Jcheckbox.

b) JRadioButton.

c) Jcombox.

d) class JCheckbox.

Answer:

(a) Jcheckbox.

Explanation- A check box is a control with a rectangular area that can be checked or unchecked. A check box is created through JCheckBox component.

Q.47. public String getText()

a) sets the label text.

b) sets the label alignment.

c) returns the label text.

d) constructs a label that displays the text.

Answer:

(c) returns the label text.

Explanation- This method returns the text displayed by the label. It would return the value of text property.

Q.48. Method that sets the label alignment to left, center, or right is

a) public void setHorizontal TextPosition(int alignment).

b) void setVerticalTextPosition().

c) void setText(String).

d) string getText().

Answer:

(a) public void setHorizontal TextPosition (int alignment).

Explanation- This method set or get where in the label its contents should be placed horizontally. With Left, Center, Right alignment.

Q. 49. Method to check if a JCheckbox is selected without using an event is

a) selected();

b) wasSelected();

c) isSelected();

d) couldBeSelected();

Ans. c) isSelected();

Explanation- This method returns the state of the check box. Returns true if the check box is selected, false if it’s not.

Q. 50. JCheckBox use

a) ActionListener.

b) ItemListener.

c) FormListener.

d) ContainerEvent.

Answer:

(b) ItemListener.

Explanation- A check Box fires many events but most commonly responded event is Item Event. An item event is handled through Item Listener.

Q. 51. To make lines of text in a JTextArea automatically start a new line when the end of the component is reached, we use

a) setWordWrap(true);.

b) setNewLine(true);.

c) setNewword(true);.

d) setLineWrap(true);.

Answer:

(d) setLineWrap(true);

Explanation- This method sets line to be wrapped if they are too long to fit within the allocated width.

Q. 52. To make sure words are kept together when a new line is created, use

a) setLineWrap(true);.

b) setWordWrap(true);.

c) setNewLine(true);.

d) setWords(String);.

Answer:

(b) setWordWrap(true);.

Explanation- setWordWrap(true) method sets to true if the multiline edit control automatically wraps words to the beginning of the next line when necessary.

Q. 53. To stop people from changing the text inside, we can use

a) setForeground(false);.

b) isEditable();.

c) setEditable(false);.

d) setChangeable(false);.

Answer:

(c) setEditable(false);.

Explanation- The user cannot edit the text if set editable property is set false.

Q. 54. We can set the text inside the JTextArea using

a) setWords(String);.

b) setString(String);.

c) String getText();..

d) setText(String);.

Answer:

(d) setText(String);.

Explanation- Sets the text displayed by the text area to String value specified in parenthsis.

Q.55. We have a String as an argument to

a) define the size.

b) define the style.

c) define the label.

d) select all of the buttons.

Answer:

(c) define the label.

Explanation- String as an argument displays the text by the label to String value specified in parenthesis.

Q.56. The int passed as an argument during instantiation is for telling

a) the LayoutManager what size to make the box.

b) the System how many characters are allowed in the box.

c) the Label how far away to be.

d) The frame where box will be placed.

Answer:

(a) the LayoutManager what size to make the box.

Explanation- The int passed as an argument during instantiation tells the LayoutManager what size to make the box.

Q.57. For comparing Strings in an if statement, we must use

a) = =.

b) compareTo().

c) setEnabled(false).

d) sameAs().

Answer:

(b)compareTo().

Explanation- Compares values and returns an int which tells if the values compare is less than, equal, or greater than.

Q.58. The String passed as an argument during the instantiation of a JButton is for

a) the text displayed as a label beside the button.

b) the text displayed above the button.

c) the text displayed away from button.

d) the text displayed on the button.

Answer:

(d) the text displayed on the button.

Explanation- When instantiating a JButton string argument is passed to display text on the JButton.

Q.59. An Event Listener is

a) extended by the class.

b) implemented by the class.

c) copied by the class.

d) removed by the class.

Answer:

(b) implemented by the class.

Explanation- The EventListener interface can be implemented by any class to register for event notifications at Events.

Q.60. From the event, if we want to find which button was pressed, use

a) e.getSource();

b) e.whichSource();

c) e.whatSource();

d) e.JButton();.

Answer:

(a) e.getSource();

Explanation- The getSource method is used to obtain the source of an action event.

Q. 61. The constant value of CENTER in the setHorizontalAlignment() command is

a) 23.

b) 100.

c) 1.

d) 0.

Answer:

(d)0.

Explanation- The text is aligned to the centre by using one of the constant field values which is 0 in case of center alignment.

Q.62. We can set the size of the Scroll pane using

a) setSize(intx, inty).

b) setPreferredSize(Dimension).

c) setSize(Dimension).

d) setSize(x,y).

Answer:

(b) setPreferredSize(Dimension).

Explanation- Set the preferred size of the receiving component.

Q.63. To change a JButton's label use

a) getText method.

b) setLabel meyhod.

c) setText method.

d) getValue method.

Answer:

(c) setText method.

Explanation- setText(String) method sets the label of the button.

Q.64. To detect a state change on JCheckBox

a) add an ItemListener.

b) add PropertyChange Events.

c) use Action listener.

d) use Adjustment Listener.

Answer:

(a) add an ItemListener.

Explanation- A JCheckBox is a component that has two states: selected or unselected. The user can change the state of a check box by clicking on it. We can attach an ItemListener to monitor events. The ItemEvent itself has the information: call getStateChange and compare the result to ItemEvent

Q.65. Representation of a range of numbers and having a scrollable knob is known as

a) slider.

b) scrollbar.

c) scale.

d) indicator.

Answer:

(b) scrollbar.

Explanation- A scroll bar is a bar representing a range of numbers and having a scrollable knob.

Q.66. User clicking on a button, generates

a) An Event.

b) A Button object.

c) A Container.

d) A Listener.

Answer:

(a) An Event.

Explanation- Whenever we click a mouse button, move the mouse or type on the computer keyboard, we are generating what is referred to as an event.

Q. 67. Method that sets the Unit Increment property with the given value is

a) setValue(int val).

b) Int getValue().

c) setUnitIncrement(int UnitIncrement).

d) setUnitValue(int).

Answer:

(c) setUnitIncrement(int UnitIncrement).

Explanation- setUnitIncrement(int UnitIncrement)method is used by JScrollBar component that sets the unit increment property with the given value.

Q. 68. Property that specifies the component that should receive the focus next when tab is pressed is

a) FocusVisualStyle.

b) Focus() method.

c) focusableposition.

d) nextFocusableComponent.

Answer:

(d) nextFocusaleComponent.

Explanation- JCheckBox offers nextFocusableComponent property that specifies the component that should receive the next focus when tab is pressed.

Q. 69. Radio Button is created through

a) ARadio Button component.

b) BRadio Button component.

c) JRadio Button component.

d) Sradio Button component.

Answer:

(c) JRadio Button component.

Explanation- In Java Swing, radio button can be created through JRadioButton component class.

Q.70. Panel can be given Titled border property using

a) OutLine border.

b) Border Customizer.

c) Border Types.

d) setBorder().

Answer:

(b) Border Customizer.

Explanation- We can give panel a titled border by clicking at ellipsis in its border property and then selecting Titled border from Border Customizer.

Q.71. Property that specifies shortcut key to a button is

a) buttonGroup.

b) Tooltip Text.

c) Key enabled.

d) mnemonic.

Answer:

(d)mnemonic.

Explanation- A mnemonic property specifies the shortcut key or the access key for the radio button that can be combined with Alt to select the button during runtime.

Q.72. The control that offer a labelled value scale is

a) a ScrollBar.

b) a text field.

c) a SLider.

d) a ruler.

Answer:

(c) a Slider.

Explanation- Slider includes a labeled value scale which offers immediate value feedback to the user.

Q.73. When user modifies slider property, JSlider triggers

a) Property Change.

b) Change Event.

c) Action Event.

d) Event Listener.

Answer:

(b) Change Event.

Explanation- JSlider triggers a ChangeEvent whenever the user modifies any of its properties for which a stateChanged() method is required.

Q.74. A method that returns the current value of the scrollbar is

a) getValue().

b) setVlaue().

c) checkValue().

d) currentValue().

Answer:

(a) getValue().

Explanation- The getValue() method returns the current value of the scrollbar.

Q.75. Method that can be used to find whether the checkbox is selected or not is

a) selected(true).

b) isEnabled().

c) isSelected().

d) isVisible().

Answer:

(c) isSelected().

Explanation- By using isSelected() method we can find out whether the chechbox is selected or not. If this method returns true, it means the checkbox is selected otherwise not selected.

Q.76. Property of Text Area that determines the occurrence of line wrapping is

a) wrapStyleWord.

b) toolTipText.

c) LineWrap.

d) Append.

Answer:

(a) wrapStyleWord.

Explanation- wrapStyleWord determines where line wrapping occurs. If true, the component attempts to wrap only at word boundaries.

Q. 77. For simple output, we use

a) Text Area.

b) Check Box.

c) Label.

d) Radio Button.

Answer:

(c) Label.

Explanation- In order to provide information to user, we use label that displays text that the user cannot directly change or edit.

Q. 78. Methods that simple return the value of the specific attribute is

a) Return method.

b) Setter method.

c) Value method.

d) Getter method.

Answer:

(d) Getter method.

Explanation- Getter method begins with word get followed by the name of property. The getter methods simply return the value of the specific attribute or property.

Q. 79. Mutator methods are also known as

a) Getter methods.

b) Setter methods.

c) Alignment method.

d) Image methods.

Answer:

(b) Setter method.

Explanation- Setter methods are mutator methods that change the value of a specific attribute or property of a component object to a specific value.

Q. 80. Method that must be implemented in a listener for button is

a) paint().

b) windowClosing().

c) addActionListener().

d) actionPerformed().

Answer:

(d) actionPerformed().

Explanation- When the button is clicked, a call is made to the actionPerformed() method defined in the class of the listener object. An ActionEvent object is passed as a parameter to it actionPerformed().

Q.81. Method used to change the font setting of any text is

a) font().

b) setFont().

c) changefont().

d) replace().

Answer:

(b)setFont().

Explanation- setFont() method can be used to set or change the font setting of any text.

Q.82. JTextField is derived from

a) JText.

b) JField.

c) JTextComponent.

d) JComponent.

Answer:

(c) JTextComponent.

Explanation- All the swing components (JPanel, JLabel, JTextField, etc.) are derived from JComponent, and JComponent has following useful properties:

toolTipText

background

font

visible

opaque

Q.83. The class of Swing labels is

a) Jlabel.

b) Label.

c) SLable.

d) Label.

Answer:

(a) Jlabel.

Explanation- A label is an object of the class Jlabel.

Q.84. Heading that must be implemented in a class that implements the ActionListener interface

a) ActionPerformed().

b) Action Event.

c) Event Listener.

d) StateChanged().

Answer:

(a) ActionPerformed().

Explanation- When the action event occurs, that object's actionPerformed method is invoked which implements ActionListener interface.

Q.85. A text field generate an action event

a) when the field has focus and the enter key is hit.

b) for every character that is typed into the field.

c) whenever the frame has focus and the enter key is hit.

d) when the text field looses focus.

Answer:

(a) when the field has focus and the enter key is hit.

Explanation- A TextField generates an ActionEvent when the user enters text and presses enter.

Q.86. The default vertical text position is

a) SwingConstants.Left.

b) SwingConstants.Right.

c) SwingConstants.Center.

d) SwingConstants.Align.

Answer:

(c)SwingConstants.Center.

Explanation- Vertical Text position specifies the vertical position of the text relative to the icon. The default position is center.

Q. 87. The default horizontal alignment is

a) Leading.

b) Center.

c) Right.

d) Trailing.

Answer:

(d) Trailing.

Explanation- Horizontal alignment specifies how the icon and text are placed horizontally on a button; default alignment is trailing.

Q.88. Class that creates button that toggles between “on” and “off” is

a) Radio Button.

b) JCheckBox.

c) JButton.

d) JCombo Box.

Answer:

(b) JCheckBox.

Explanation – JCheckBox class creates button that toggles between “on” and “off”.

Q. 89. Attributes associated with windows is

a) Title.

b) color.

c) weight.

d) method.

Answer:

(a) Title.

Explanation- Windows can be created using a Frame object; the class Frame provides various methods to control attributes of a window like title, width and height.

Q.90. When a class implements an interface,

a) It must redefine each constant from the interface.

b) It must declare and provide a method body for each method in the interface.

c) It must declare a variable for each constant in the interface.

d) It must include a private method for each method in the interface.

Answer:

(b) It must declare and provide a method body for each method in the interface.

Explanation- When a class implements an interface it must declare and provide a method body for each method in the interface. All of the methods declared in an interface are implicitly abstract.

Q. 91. Action event is sent to

a) actionPerformed.

b) MouseEvent.

c) WindowEvent.

d) action listener.

Answer:

(d) action listener.

Explanation- We implement an action listener to define what should be done when an user performs certain operation.

Q.92. To get focus for a window

a) implement a WindowFocusListener.

b) implement a PropertyChangeListener.

c) implement a focus listener.

d) add focus window().

Answer:

(a) implement a WindowFocusListener.

Explanation- Focus events are fired whenever a component gains or loses the keyboard focus. To get focus for a window, implement a WindowFocusListener instance.

Q.93. To put a border around a JComponent, use its

a) setBorder method.

b) drawBorder().

c) push Border method.

d) visibleBorder method.

Answer:

(a) setBorder method.

Explanation- Every JComponent can have one or more borders. To put a border around a JComponent, we use its setBorder method.

Q. 94. A container that can hold a group of components so that they can be displayed on a frame is

a) label.

b) panel.

c) frame.

d) desktopPane.

Answer:

(b) panel.

Explanation- A panel is a type of container that is designed to hold a group of components so that they can be displayed on a frame.

Q.95. An independent subwindow meant to carry temporary notice apart from the main Swing Application Window is

a) Derived window.

b) Sub window.

c) Dialog window.

d) Inner window.

Answer:

(c) Dialog window

Explanation- A Dialog window is an independent subwindow meant to carry temporary notice apart from the main Swing Application Window.

Q.96. A simple Push Button is created through

a) LButton class.

b) Simple button.

c) Enable button.

d) JButton class.

Answer:

(d) JButton class.

Explanation- Push Button are created through JButton class of Swing API. We can control the look and fell of the button.

Q.97. To assign a keyboard access key to a command button, we need to set

a) mnemonic property.

b) action command.

c) text.

d) tooltip Text

Answer:

(a) mnemonic property.

Explanation- To assign a keyboard access key to a command button, we need to set the mnemonic property of the button by simply typing the key in the box in front of mnemonic property in Properties window.

Q.98. The most common event of push buttons is

a) Item Event.

b) Action Event.

c) Key Event.

d) Mouse Event.

Answer:

(b) Action Event.

Explanation- The most common event of push buttons (JButton) is Action Event, which is handled by ActionPerformed () method of event listener ActionListener.

Q.99. Like an ordinary text field, a password field fires an

a) Exit event.

b) Entry event.

c) action event.

d) Key event.

Answer:

(c) action event.

Explanation- An action event occurs, whenever an action is performed by the user.

Q.100. By default, spacing for major and minor tick marks is

a) 1.

b) 0.

c) 100.

d) 50.

Answer:

(b) 0.

Explanation- By default, spacing for major and minor tick marks is zero. To see tick marks, we must explicitly set the spacing for either major or minor tick marks (or both) to a non-zero value and call the setPaintTicks(true) method.