Home Tuitions

chapter-Java GUI Programming Using Swing-I

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

This page consists of Important MCQ-Based Questions on Informatics Practices (IP) class 11 chapter-Java GUI Programming Using Swing-I 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-I

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

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

Class XI

Q.1 Interface that uses graphics along with text to interact with user is

a) Graphical User Interface.

b) Graphical User Interaction.

c) Graphics Uniform Interface.

d) Graphical User Instance.

Answer:

(a) Graphical User Interface.

Explanation- A Graphical User Interface is an interface that uses graphics along with text to interact with user.

Q.2 Method that responds to an event is

a) an action.

b) firing an event.

c) an event handler.

d) a listener.

Answer:

(c)an event handler.

Explanation- An event handler receives and handles events when a button is clicked or key is pressed.

Q.3 The Layout manager where components are given their preferred size is

a) GridLayout.

b) FlowLayout.

c) BoxLayout.

d) BorderLayout.

Answer:

(b)FlowLayout.

Explanation: FlowLayout arranges components in a container like words on a page. If the container is not wide enough to display all of the components, the components wrap around to a new line.

Q.3 A component that lets the user pick a colour is

a) color chooser.

b) combo box.

c) list box.

d) color pick.

Answer:

(a)color chooser.

Explanation: The JColorChooser class provides users with a palette of colours to choose from. A color chooser is a component that can be placed anywhere within the program GUI.

Q.4 Acomponent that displays an icon, but that doesn’t react to user clicks is

a) textbox.

b) label.

c) list.

d) table.

Answer:

(b)label.

Explanation: With the JLabel class, we can display unselectable text and images.

Q.5. Portion of screen that serves as a smaller screen within the screen is called

a) Menu.

b) Button.

c) Frame.

d) Window.

Answer:

(d)Window.

Explanation- A window is a rectangular portion of the display on a computer monitor that presents its contents (e.g., the contents of a directory, a text file or an image) seemingly independently of the rest of the screen.

Q.6. A container that looks like a frame, but that appears within a real frame is known as

a) internal frame.

b) mainframe

c) externalframe.

d) internalwindow.

Answer:

(a) internal frame.

Explanation- With the JInternalFrame class we can display a JFrame-like window within another window.

Q.7. Changing the state of an object is called an

a) Event.

b) Event handler.

c) Action listener.

d) Source.

Answer:

(a)Event.

Explanation- Events represent all activity that goes on between the user and the application.

Q.8. A container that lets the user determine how two components share a limited amount of space

a) Editor pane.

b) Text pane.

c) Split pane.

d) Scroll pane.

Ans. c) Split pane.

Explanation- A JSplitPane displays two components, either side by side or one on top of the other. By dragging the divider that appears between the components, the user can specify how much of the split pane's total area goes to each component.

Q.9. AWT stands for

a) Atomic Weight Toolkit.

b) Abstract Window Toolkit.

c) Applet Wise Toolkit.

d) Absolute Window Toolkit.

Answer:

(b) Abstract Window Toolkit.

Explanation- Abstract Window Toolkit is a basic GUI toolkit of Java platform. Swing internally borrows functionality from AWT.

Q.10. An object that generates an event is called a

a) Event Listener.

b) Listener Interface.

c) Source.

d) Applet.

Answer:

(c) Source.

Explanation- It is the GUI component that generates the event, e.g., a button etc.

Q.11. Default layout for a ContentPane in JFC is

a) GridLayout.

b) FlowLayout.

c) BoxLayout.

d) BorderLayout.

Answer:

(d) BorderLayout.

Explanation- BorderLayout arranges components along the edges or the middle of their containers.

Q.12. Method of the Component class used to set the position and size of a component is

a) setBounds.

b) setLocation.

c) setSize.

d) setPosition.

Answer:

(a)setBounds.

Explanation- Used to set the absolute size and location of a Component.

Q.13. A component that looks like a button and that, when pressed, brings up a menu of items for the user to choose fromis

a) Uneditable combo box.

b) Editable combo box.

c) Interactive Display.

d) Pop Up menu.

Answer:

(a) Uneditable combo box.

Explanation- Uneditable combo box display a list from which users can select one item.

Q.14. Method use to add a menu bar to a top-level container such as a JFrame is

a) getJMenuBar

b) setJMenuBar

c) update

d) setLayout

Answer:

(b) setJMenuBar

Explanation- Sets the menubar for this frame.

Q.15. Method use to enable and disable components such as JButtons 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.16. The default alignment of buttons in Flow Layout is

a) LEFT.

b) CENTER.

c) RIGHT.

d) The alignment must be defined when using the FlowLayout Manager.

Answer:

(a) LEFT.

Explanation- In FlowLayout Manager, the first component added appears to the left and subsequent components flow in from the right.

Q.17. Default Layout Manager for the Applet class in Java is

a) BorderLayout.

b) GridLayout.

c) CardLayout.

d) FlowLayout.

Answer:

(d) FlowLayout.

Explanation- Default Layout Manager works like a typical word processor from Left to Right. The order in which the components are added determines their order in the container.

Q.18. A self contained graphic entity that can be customized is

a) Swing component.

b) Swing container.

c) Java Applets.

d) Java Foundation Classes.

Answer:

(a) Swing component.

Explanation- A Swing component is a self-contained graphic entity that can be customized and inserted into applications. Example: Jlabel, Jbutton etc.

Q.19. Containers that have some predefined specific role are

a) Basic Controls.

b) General Purpose Containers.

c) Special Purpose Containers.

d) Interactive Displays

Answer:

(c) Special Purpose Containers.

Explanation- Special Purpose Containers are intermediate containers that play specific roles in the UI.

Q.20. 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.21. Layout Manager that places components in a grid of equally sized cells is

a) GridBagLayout.

b) GridLayout.

c) BoxLayout.

d) AbsoluteLayout.

Answer:

(b)GridLayout.

Explanation- GridLayout places components in a grid of equally sized cells, adding them to the grid from left to right and top to bottom. Each region of the grid will have the same size.

Q.22. Mouse Motion Events occurs when

a) an item is selected.

b) any component gains or losses focus.

c) key is pressed on the keyboard.

d) mouse moves over a component.

Answer:

(d)mouse moves over a component.

Explanation- Mouse motion events occur when a mouse is moved over a component. To handle a Mouse motion event the mouse motion listener interface must be implemented.

Q.23. Anything that is visible or tangible is

a) a method.

b) a class.

c) an object.

d) an instance.

Answer:

(c)an object.

Explanation- An object is an identifiable entity with some characteristics.

Q.24. Property that sets a string to identify the command associated with buttons is

a) actionCommand.

b) enabled.

c) Mnemonic.

d) text.

Answer:

(a) actionCommand.

Explanation- actionCommand sets string that would identify the command associated with button.

Q.25. Swing components that do not rely on native GUI are referred to as

a) lightweight components.

b) heavyweight components.

c) GUI components.

d) non-GUI components.

Answer:

(a)lightweight components.

Explanation- A lightweight component directly implements the look-and-feel of the component in Java rather than delegating the look-and-feel to a native peer. Lightweight components can be more efficient at utilizing system resource and they can be transparent

Q.26. A construct that defines objects of the same type is called a

a) a class.

b) an object.

c) a method.

d) a data field.

Answer:

(a)a class.

Explanation- A Class represents a set of similar objects.

Q.27. An object is an instance of a

a) program.

b) class.

c) method.

d) data.

Answer:

(b) class.

Explanation- Once a class is available; we can create many objects that have the same structure and behaviour. If we create two objects they are instances of the same class.

Q.28. A method that is associated with an individual object is called

a) a static method.

b) a class method.

c) an instance method.

d) an object method.

Answer:

(c) an instance method.

Explanation- An instance method is a method which is associated with one object and uses the instance variables of that object.

Q.29. An object-oriented programming language is

a) C.

b) ADA.

c) Pascal.

d) Java.

Answer:

(d) Java.

Explanation- Object Oriented Programming or OOP is the technique to create programs based on the real world. Java is a object oriented programming language.

Q.30. Java is both compiled and

a) interpreted.

b) run.

c) transferred.

d) accessed.

Answer:

(a) interpreted.

Explanation- At first, the Java source code (in .java files) is compiled into Bytecode. When the Java application is started, the Bytecode is interpreted by the Java Virtual Machine.

Q.31. Every statement in Java ends with a

a) a semicolon (;).

b) a comma (,).

c) a period (.).

d) an asterisk (*).

Answer:

(a) a semicolon (;).

Explanation-Every complete Java statement ends with a semicolon.

Q. 32. Java compiler translates Java source code into

a) java bytecode.

b) machine code.

c) assembly code.

d) another high-level language code.

Answer:

(a) java bytecode.

Explanation- Java compiler compiles the Java source code files (*.java) into binaries files (*.class). Java bytecode is the form of instructions that the Java virtual machine executes.

Q.33. Every letter in a Java keyword is in

a) uppercase.

b) underline.

c) lowercase.

d) bold.

Answer:

(c) lowercase.

Explanation- Keywords are in lowercase and reserved. Lowercase is used for variable and method names.

Q. 34. To draw graphics, it is better to declare a class that extends

a) Jlabel.

b) Jbutton.

c) JPanel.

d) JComponent.

Answer:

(c) JPanel.

Explanation- JLabel and JButton are specifically designed with particular features for labels and buttons. They are not appropriate for custom drawing. The problem with JComponent is that you have to write the code to paint the background color if we wish to set a background in the canvas. A simple setBackground (Color) method will not set a background color in a JComponent.

Q.35. Pressing a button generates a

a) ItemEvent.

b) MouseEvent.

c) MouseMotionEvent.

d) ContainerEvent

Answer:

(d) ContainerEvent.

Explanation- The ContainerEvent class extends from the ComponentEvent class. This is a low-level event which is generated when container's contents changes because of addition or removal of a components.

Q.36. Clicking the closing button on the upper-right corner of a frame generates a(n)

a) ItemEvent.

b) WindowEvent.

c) MouseMotionEvent.

d) ComponentEvent.

Answer:

(b)WindowEvent.

Explanation- Frames generate events belonging to the class WindowEvent. The event handler for that event is responsible for closing the window.

Q. 37. The component that processes the listener is called

a) source object.

b) adapter object.

c) listener object.

d) adaptee object.

Answer:

(c) listener object.

Explanation- The event listener object contains listener methods for various types of events.

Q.38. Each event class has a corresponding

a) listener interface.

b) listener object.

c) source object.

d) multiple listeners.

Answer:

(a) listener interface.

Explanation- Java defines an event listener interface for each of the event types it defines.

Q. 38. To be a listener for ActionEvent, an object must be an instance of

a) ActionEvent.

b) ActionListener.

c) EventObject.

d) WindowListener.

Answer:

(b) ActionListener.

Explanation- The ActionListener interface must be implemented to capture an ActionEvent. This interface provides processAction () method which is called when the ActionEvent for which the ActionListener is registered occurs.

Q.39. Every event object has the

a) getActionCommand ().

b) getSource ().

c) getKeyChar().

d) getTimeStamp().

Answer:

(b) getSource().

Explanation- Every event object is a subclass of EventObject, which contains the getSource() method.

Q.40. Clicking a JRadioButton generates

a) ActionEvent.

b) ComponentEvent.

c) ContainerEvent.

d) Window Event.

Answer:

(a) Action Event.

Explanation- A check box generates one item event and one action event per click. Swing supports radio buttons with the JRadioButton.

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

a) label.

b) button.

c) radio button.

d) text field.

Answer:

(d) text field.

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

Q.42. Items that can be added into a JComboBox is/are

a) 0.

b) 1.

c) 2.

d) Unlimited.

Answer:

(d)Unlimited.

Explanation- An editable JComboBox allows the user to add unlimited number of items.

Q. 43. 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. 44. A support class that provides default implementations for all the methods in the listener interface is

a) a listener adapter.

b) a convenience listener adapter.

c) an adapter.

d) an event adapter.

Answer:

(b) a convenience listener adapter.

Explanation- Convenience adapters are support classes that provide default implementations for all the methods in the listener interface.

Q.45. To use no layout manager in a container c, use

a) c.setLayout().

b) c.setLayout(new NullLayout()).

c) c.setLayout(null).

d) c.setLayout(NullLayout).

Answer:

(c) c.setLayout(null).

Explanation- By setting a container's layout property to null, we make the container use no layout manager.

Q.46. A Swing layout manager that arranges components in a row or a column is

a) FlowLayout.

b) BorderLayout.

c) GridLayout.

d) BoxLayout.

Answer:

(d) BoxLayout.

Explanation- BoxLayout allows multiple components to be arranged either vertically or horizontally, but not both.

Q. 47. A Swing layout manager that put a flexible spring around a component is

a) BorderLayout.

b) SpringLayout.

c) GridLayout.

d) BoxLayout.

Answer:

(b) SpringLayout.

Explanation- The spring may compress or expand to place the components in desired locations.

Q. 48. A MenuItem object can generate

a) ActionEvent.

b) ItemEvent.

c) ComponentEvent.

d) ContainerEvent.

Answer:

(a) ActionEvent.

Explanation- MenuItem objects that generate action events when clicked and therefore have addActionListener methods.

Q. 49. A JPopupMenu is a subclass of

a) JMenuItem.

b) AbstractButton.

c) JComponent.

d) JMenu.

Answer:

(c) JComponent.

Explanation- To create a popup menu, use JPopupMenu which is a subclass of JComponent.

Q. 50. A LayoutManager which enables components to be placed exactly where one wants to place them is done using

a) NullLayout.

b) AbsoluteLayout.

c) SpringLayout.

d) BoxLayout.

Answer:

(b) AbsoluteLayout.

Explanation- AbsoluteLayout is a layout manager that enables components to be placed exactly where one want them in the form and resize them using their selection borders.

Q. 51. Events that occur when an item is selected on Jbutton is

a) Action Events.

b) Window Events.

c) Item Events.

d) Key Events.

Answer:

(c) Item Events.

Explanation- Item Events occur when an item is select6ed or deselected on components like Jbutton, JCheckBox, etc.

Q. 52. Event handler can be defined using

a) palette.

b) events.

c) ellipsis.

d) property.

Answer:

(d) property.

Explanation- Event handler can be defined using property sheet, click the value of the desired event in the list.

Q.53. By default content panes use

a) BorderLayout.

b) SpringLayout.

c) FlowLayout.

d) BoxLayout.

Answer:

(a) BorderLayout.

Explanation- By default, content panes use BorderLayout. Components are placed in five possible positions.

Q.54. When components are required to be displayed in compact row at their natural size, we can use

a) GridLayout.

b) GridBagLayout.

c) CardLayout.

d) SpringLayout.

Answer:

(d) SpringLayout.

Explanation- When we need to display a few components in a compact row at their natural size, SpringLayout can be used.

Q.55. Object’s Behaviour is implemented through

a) variables.

b) data items.

c) methods.

d) objects.

Answer:

(c)methods.

Explanation- Behaviour of the objects is implemented through functions called as methods.

Q. 56. OOP stands for:

a) Observable Object Programming.

b) Object Observed Procedures.

c) Object Oriented Programming.

d) Object Overloading Practices.

Answer:

(c) Object Oriented Programming.

Explanation- OOP is a computer science term which is used to describe a computer application that is composed of multiple objects which are connected to each other.

Q.57. JComponent is the parent of almost all Swing components. It is a direct subclass of

a) java.awt.Frame.

b) java.awt.Container.

c) java.lang.Object.

d) SwingUtilities.

Answer:

(b) java.awt.Container.

Explanation- Jcomponent is mostly derived from Java.awt.Window.

Q.58. Respectively, Heavyweight and Lightweight components can (with a few exceptions) be grouped as

a) Swing and AWT components.

b) Frames and Panels.

c) AWT and Swing components.

d) Panels and Frames.

Answer:

(a) AWT and Swing components.

Explanation- Swing components are referred to as lightweights while AWT components are referred to as heavyweights. The difference between lightweight and heavyweight components is z-order: the notion of depth or layering. Each heavyweight component occupies its own z-order layer. All lightweight components are contained inside heavyweight components and maintain their own layering scheme defined by Swing.

Q. 59. JRootPane is used to manage:

a) component layering.

b) painting and rendering of components.

c) a container for a content pane, layered pane, menu bar and glass pane.

d) model and view.

Answer:

(c)a container for a content pane, layered pane, menu bar and glass pane.

Explanation- JRootPane is used to manage a container for a content pane, layered pane, menu bar and glass pane. A JRootPane object is made up of a glassPane, a contentPane and an optional menu bar.

Q.60. When a program is written to respond to the button clicks, menu selections, and other actions of the user, it is called as

a) Event-driven programming.

b) Action-driven programming.

c) User-driven programming.

d) Mouse-driven programming

Answer:

(a) Event-driven programming.

Explanation- Event-driven programming is a flexible way to allow programs to respond to many different inputs or events.

Q.61. The three software parts of a GUI program are:

a) Windows, Buttons, Mice.

b) GUI Components, Graphics, Code.

c) GUI Components, Event Listeners, Application Code.

d) Frames, Code, Events.

Answer:

(c) GUI Components, Event Listeners, Application Code.

Explanation- GUI program consists of three types of software:

Graphical Components that make up the Graphical User Interface.

Listener methods that receive the events and respond to them.

Application methods that do useful work for the user.

Q.62. One component that nearly all GUI programs will have is

a) Window.

b) Mouse.

c) Monitor.

d) Button.

Answer:

(b) Mouse.

Explanation- Graphical User Interface makes use of mouse which is user friendly. The mouse can be used to select (copy), and extend-select text, paste text from other terminals or applications, and also bring up control menus, as well as select (and move) other GUI components.

Q.63. A container object in GUI programming is

a) another name for an array or vector.

b) any class that is made up of other classes.

c) a primitive variable that contains the actual data.

d) a GUI component that has other GUI components placed inside of it.

Answer:

(d) a GUI component that has other GUI components placed inside of it.

Explanation- A container is a component that stores other components and arranges them inside the container according to a Layout manager.

Q.64. 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. 65. The name for a method that respond to events is

a) A container method.

b) A snoop method.

c) A listener method.

d) An application method

Answer:

(c) A listener method.

Explanation- Listener methods are a kind of call back; they are triggered when a form is submitted or a link is clicked.

Q. 66. The base class of all Swing classes is

a) Object.

b) Component.

c) Swing.

d) JComponent.

Answer:

(d) JComponent.

Explanation- The JComponent class provides the base class for both standard and custom components that use the Swing architecture.

Q. 67. Many Swing class names start with

a) A.

b) B.

c) J.

d) S.

e)

Answer:

(c) J.

Explanation- Many of the Swing classes representing windows, lists, buttons etc live in the javax.swing package and subpackages. The names of most Swing classes start with the letter J: JFrame, JPanel, JButton, JList etc. In general, if we are looking for the class that represents some visual component in Swing, its name will start with J.

Q.68. All real world objects have

a) identity, state and behavior.

b) state and behavior.

c) size and weight.

d) existence.

Answer:

(b) state and behavior.

Explanation- Real-world objects share two characteristics: They all have state and behavior. Bicycles have state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes).

Q.69. A class is a

a) section of computer memory containing objects.

b) section of the hard disk reserved for object oriented programs.

c) section of an object that contains the variables.

d) description of a kind of object.

Answer:

(d)description of a kind of object.

Explanation- A class is the blueprint from which individual objects are created.

Q.70. An area on the screen that has nice borders and various buttons along the top border is

a) A window.

b) A screen.

c) A frame.

d) A box.

Answer:

(c) A frame.

Explanation- Frame is a Window with controls on it such as optional resizing buttons, an icon, a menubar and a title.

Q.71. Name of the Swing class that is used for frames is

a) Window.

b) JFrame.

c) Frame.

d) SwingFrame.

Answer:

(b) JFrame.

Explanation- JFrame is a java swing public class which is a top level container class.

Q.72. An object that waits for and responds to an event from a GUI component is a

a) event listener.

b) GUI listener.

c) collection class.

d) click listener.

Answer:

(a) event listener.

Explanation- Any object can be notified of an event by registering as an event listener on the appropriate event source.

Q.73. An event object

a) is an object that listens for mouse clicks.

b) is a list of all the events that have happened in the system.

c) represents one specific event, such as a mouse click.

d) is what program does in response to an event.

Answer:

(c) represents one specific event, such as a mouse click.

Explanation- The Event object represents the state of an event, such as the element in which the event occurred, the state of the keyboard keys, the location of the mouse, and the state of the mouse buttons.

Q.74. Method of a JFrame object used to register a window listener with it is

a) addWindowListener().

b) register().

c) setListener().

d) ignoreEvent().

Answer:

(a) addWindowListener().

Explanation- addWindowListener(), adds the specified window listener to receive window events from the window.

Q. 75. Panes which provide the ability to switch betwen various Panels are

a) ShiftPane.

b) AltPane.

c) TabPane.

d) ControlPane.

Answer:

(c) TabPane.

Explanation- TabPanes provide the ability to switch betwen various panels. various panels can be added to a top level container using tabbed panes.

Q. 76. The Java software that determines how the components of a container are

a) Display Manager.

b) Component Manager.

c) Stage Manager.

d) Layout Manager.

Answer:

(d) Layout Manager.

Explanation- Java applets use layout managers to arrange display components, e.g. buttons, text fields, lists, etc.

Q. 76. Manager that displays components row-by-row, in the order in which they were added to the Frame is

a) CardLayout.

b) FlowLayout.

c) GridLayout.

d) BorderLayout.

Answer:

(b) FlowLayout.

Explanation- FlowLayout is the default layout manager for every JPanel. It simply lays out components in a single row, starting a new row if its container is not sufficiently wide.

Q. 77. 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.78. Method that will immediately stop a program is

a) System.gc().

b) System.exit( 0 ).

c) System.setErr().

d) return().

Answer:

(b) System.exit( 0 ).

Explanation- The code System.exit(0, blindly terminates the application.

Q.79. JTextField is derived from

a) JText.

b) JField.

c) JTextComponent.

d) JComponent.

Answer:

(c) JTextComponent.

Explanation-

Q.80. 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.81. FlowLayout() put components into the content frame by

a) starting at the top, then left to right in each row.

b) starting at the bottom, then right to left in each row..

c) starting at the center, then spirals outward.

d) putting the first component in the center, then squeezes the rest in around it.

Answer:

(a) starting at the top, then left to right in each row.

Explanation- FlowLayout arranges components in a container like words on a page. It fills the top line from left to right.

Q.82. 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.83. The method that changes the colour of a content is

a) setColor().

b) setBackgroundColor().

c) setBackground()

d) setForegroundColor()

Answer:

(c)setBackground()

Explanation- Sets the background colour of the component.

Q. 84. The type of object that determines where GUI components go in the content pane is the

a) layer organizer.

b) GUI manager.

c) layout manager.

d) frame hanger.

Answer:

(c) layout manager.

Explanation- A layout manager is an object that implements the Layout Manager interface and determines the size and position of the components within a container.

Q.85. If the user changes the size of the frame,

a) they stay where they are; the frame just gets bigger.

b) the layout manager changes the layout and re-distributes the components.

c) the user can not change the size of a frame if the program used setSize.

d) repaint() calls the frame's constructor, which puts everything back they way it started.

Answer:

(b) The layout manager changes the layout and re-distributes the components.

Explanation – Although components can provide size and alignment hints, a container's layout manager has the final say on the size and position of the components within the container.

Q. 86. An interface is a

a) collection of constants and method declarations.

b) class that a child class can extend.

c) collection of GUI components.

d) collection of public methods of a class.

Answer:

(a) collection of constants and method declarations.

Explanation- A interface is a collection of data attributes and methods that define the semantics of the interface. An interface is a collection of constants (not fields) and method declarations. The method declarations do not include an implementation (there is no method body.)

Q.87. 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. 88. Event Listener Interface that occurs when the status of the window changes is

a) KeyListener.

b) MouseEvent.

c) WindowEvent.

d) WindowListener.

Answer:

(d) WindowListener.

Explanation- WindowListener is the listener interface for receiving window events.

Q.89. An object that can hold data is called

a) attributes.

b) methods.

c) behaviour.

d) class.

Answer:

(a) attributes.

Explanation- An object that can hold data is called member variable or attributes; the value of these attributes defines the state of an object.

Q.90. A top-level window with a title and a border is a

a) frame.

b) label.

c) push button.

d) exit button.

Answer:

(a) frame.

Explanation- A frame is a top-level window with a title and a border. A frame is created through JFrame component.

Q. 91. 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.92. A message has three components that are

a) class, method-name and method body .

b) parameter list, target and an object.

c) target, selector and parameter list.

d) return-type, method and class.

Answer:

(c) target, selector and parameter list.

Explanation- Java implements messages as method calls. A message has three components: a target, a selector and a parameter list.

Q.93. 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.94. 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.95. 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.96. The button that initiates the counting process in the label is

a) Exit button().

b) Stop button().

c) Start button().

d) Increment button().

Answer:

(c) Start button().

Explanation- Start button(StartBtn) initiates the counting process by initializing the value as 0 in the label.

Q.97. Blueprint of a set of similar objects is termed as

a) container.

b) class.

c) property.

d) method.

Answer:

(b) class.

Explanation- A class represents a set of objects that have a common structure and common behaviour. Class is a blueprint that represents a set of similar objects.

Q.98. The property used to specify the icon that would appear on the title bar of frame is

a) background.

b) toolTipText.

c) custom code.

d) Compoent chooser.

Answer:

(c) custom code.

Explanation- To set iconImage property of a frame, we need to select ellipsis of iconImage property and select Custom code from drop down menu and type the code to specify the pathname.

Q.99. The smallest screen measurement that can be adjusted is

a) pixel.

b) dot.

c) character.

d) twip.

Answer:

(d) twip.

Explanation- In Java, size measurements are in twip. A twip is equal to 1/1440 of an inch.

Q.100. Event Listener that would respond to a key pressed on the keyboard is

a) FocusListener.

b) KeyListener.

c) WindowListener.

d) ItemListener.

Answer:

(b)KeyListener.

Explanation- KeyListener is the listener interface for receiving keyboard events (keystrokes). If component want to process its own keystrokes, the easiest way is to implement the KeyListener interface.