0% found this document useful (0 votes)
28 views

Unit 2 MCQ BY ROOMIES

Uploaded by

manojschavan6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Unit 2 MCQ BY ROOMIES

Uploaded by

manojschavan6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

UNIT 2 MCQ BY ROOMIES

Unit 2 :

1. Is super class of all the events


- A) Object
- B) Event
- C) EventObject
- D) SuperEventObject
- Answer: C) EventObject

2. Which of these packages contains all the classes and methods required for event handling in
Java?
- A) java.awt
- B) java.util
- C) java.event
- D) java.awt.event
- Answer: D) java.awt.event

3. Which of these events is generated when a window is closed?


- A) WindowClosedEvent
- B) WindowCloseEvent
- C) WindowEvent
- D) CloseEvent
- Answer: C) WindowEvent

4. ________method is used to register a keyboard event listener


- A) registerKeyListener()
- B) addKeyListener()
- C) setKeyListener()
- D) attachKeyListener()
- Answer: B) addKeyListener()
UNIT 2 MCQ BY ROOMIES

5. Which of these methods can be used to know the degree of adjustment made by the user?
- A) getAdjustment()
- B) calculateAdjustment()
- C) getValue()
- D) adjustValue()
- Answer: C) getValue()

6. A MenuItem object can generate __________ events.


- A) ItemEvent
- B) ActionEvent
- C) MenuEvent
- D) MenuItemEvent
- Answer: B) ActionEvent

7. A source generates an event and sends it to ___________ listeners that can handle the event.
- A) Only one
- B) At least two
- C) One or more
- D) Exactly three
- Answer: C) One or more

8. A ________________ is an object that is notified when an event occurs.


- A) Notifier
- B) Emitter
- C) Listener
- D) Observer
- Answer: C) Listener

9. A ________________________ is generated when a component is added to or removed from a


container.
- A) ComponentEvent
- B) ContainerEvent
UNIT 2 MCQ BY ROOMIES

- C) AddRemoveEvent
- D) ChangeEvent
- Answer: B) ContainerEvent

10. ActionEvent Class is used for Which Control?


- A) Button, List, MenuItem
- B) TextField, TextArea, ComboBox
- C) CheckBox, RadioButton
- D) Label, Panel, Frame
- Answer: A) Button, List, MenuItem

11. Adapter class belongs to the package


- A) java.awt
- B) java.util
- C) javax.event
- D) java.awt.event
- Answer: D) java.awt.event

12. Adapter Class provides_____________________________


- A) Full implementation of all methods of a listener
- B) Partial implementation of all methods of a listener
- C) Empty implementation of all methods of a listener
- D) Abstract implementation of all methods of a listener
- Answer: C) Empty implementation of all methods of a listener

13. An event is generated when the internal state of the event source is ___________.
- A) Constant
- B) Initialized
- C) Changed
- D) Reset
- Answer: C) Changed
UNIT 2 MCQ BY ROOMIES

14. An object that would like to be notified of and respond to an event is


- A) ActionListener
- B) EventDispatcher
- C) EventNotifier
- D) EventListener
- Answer: D) EventListener

15. At the root of the Java event class hierarchy is ___________ which is the superclass for all
events.
- A) EventRoot
- B) EventBase
- C) EventSource
- D) EventObject
- Answer: D) EventObject

16. Change in the state of an object is known as __________


- A) Transition
- B) Transformation
- C) Event
- D) StateChange
- Answer: C) Event

17. CheckBox implements following Listener Interface


- A) ItemListener
- B) ActionListener
- C) CheckboxListener
- D) CheckListener
- Answer: A) ItemListener

18. ComponentEvent is the superclass of _______________.


UNIT 2 MCQ BY ROOMIES

- A) Only ActionEvent
- B) Only WindowEvent
- C) Only AdjustmentEvent
- D) All of the above
- Answer: D) All of the above

19. Event class is defined in which of these libraries?


- A) java.util
- B) javax.event
- C) java.awt.event
- D) java.awt
- Answer: C) java.awt.event

20. Event Listeners are____________________________________


- A) Objects
- B) Interfaces
- C) Classes
- D) Methods
- Answer: B) Interfaces

21. EventObject class present in__________package.


- A) java.util
- B) javax.event
- C) java.awt.event
- D) java.awt
- Answer: D) java.awt

22. EventObject contains two important methods:________ and___________.


- A) getEvent() and setEvent()
- B) getSource() and toString()
- C) receiveEvent() and processEvent()
UNIT 2 MCQ BY ROOMIES

- D) handleEvent() and describeEvent()


- Answer: B) getSource() and toString()

23. Events are supported by the _____________.


- A) java.event
- B) javax.event
- C) java.awt.event
- D) java.awt
- Answer: C) java.awt.event

24. Focus events are fired whenever a component _____________________the focus.


- A) Receives
- B) Gains or loses
- C) Holds
- D) Transfers
- Answer: B) Gains or loses

25. FocusEvent is a subclass of which of these classes?


- A) InputEvent
- B) ComponentEvent
- C) AWTEvent
- D) EventObject
- Answer: C) AWTEvent

26. Generated when a window is activated, de-activated, closed, de-activated, de-iconified,


iconified, opened or quit.
- A) WindowEvent
- B) AppletEvent
UNIT 2 MCQ BY ROOMIES

- C) FrameEvent
- D) SystemEvent
- Answer: A) WindowEvent

27. getID() method is provided by __________ class.


- A) EventClass
- B) AWTEvent
- C) EventID
- D) EventObject
- Answer: B) AWTEvent

28. getKeyChar( ) and getkeyCode( ) methods belong to which event class?


- A) ActionEvent
- B) InputEvent
- C) KeyEvent
- D) TextEvent
- Answer: C) KeyEvent

29. getSource() is a method of which class.


- A) EventObject
- B) AWTEvent
- C) EventSource
- D) SourceObject
- Answer: A) EventObject

30. How many types of component events are in Java?


- A) 2
- B) 3
- C) 4
UNIT 2 MCQ BY ROOMIES

- D) 5
- Answer: C) 4

31. How to obtain the command name for invoking ActionEvent?


- A) Using getCommandName( ) method.
- B) Using fetchActionCommand( ) method.
- C) Using retrieveCommand( ) method.
- D) Using getActionCommand( ) method.
- Answer: D) Using getActionCommand( ) method.

32. How to remove the event listener?


- A) Using removeListener( ) method.
- B) Using unregisterListener( ) method.
- C) Using removeTypeListener( ) method.
- D) Using detachListener( ) method.
- Answer: C) Using removeTypeListener( ) method.

33. If a class extends the ActionListener interface, it must contain a method called. __________.
- A) action()
- B) actionPerformed()
- C) execute()
- D) handleAction()
- Answer: B) actionPerformed()

34. If the scroll bar is manipulated, __________ event will be notified.


- A) ScrollEvent
- B) AdjustEvent
- C) AdjustmentEvent
UNIT 2 MCQ BY ROOMIES

- D) ScrollBarEvent
- Answer: C) AdjustmentEvent

35. If we close an applet’s window, _________ event will be generated.


- A) AppletClosedEvent
- B) CloseEvent
- C) AppletWindowClosedEvent
- D) WindowEvent
- Answer: D) WindowEvent

36. If _____________ is manipulated, AdjustmentEvent event will be notified.


- A) Slider
- B) ProgressBar
- C) ScrollBar
- D) Dial
- Answer: C) ScrollBar

37. In EventObject, which method is used to determine the type of event?


- A) getType()
- B) identifyEvent()
- C) determineEventType()
- D) getSource()
- Answer: A) getType()

38. In Java, an event is an _________ which specifies the change of state in the source.
- A) Abstract
- B) Object
- C) Entity
- D) Indicator
UNIT 2 MCQ BY ROOMIES

- Answer: B) Object

39. In Java, events are all the activities that occur between ___________.
- A) A and C
- B) A and B
- C) B and D
- D) C and D
- Answer: B) A and B

40. In which package class AWTEvent defined?


- A) java.util
- B) javax.event
- C) java.awt
- D) java.awt.event
- Answer: C) java.awt

41. In which package the methods for receiving and processing events are defined?
- A) java.util
- B) javax.event
- C) java.awt
- D) java.awt.event
- Answer: D) java.awt.event

42. In which places can put the event handling code?


- A) Only in main()
- B) Only in constructors
- C) Only in methods
UNIT 2 MCQ BY ROOMIES

- D) All mentioned above


- Answer: D) All mentioned above

43. Interface used to handle menu events is:


- A) MenuListener
- B) ActionListener
- C) ItemListener
- D) EventListener
- Answer: A) MenuListener

44. ItemListener event defines this method…


- A) itemChanged()
- B) itemUpdated()
- C) itemStateChanged()
- D) itemModified()
- Answer: C) itemStateChanged()

45. KeyEvent is a subclass of ________.


- A) InputEvent
- B) TextEvent
- C) AWTEvent
- D) EventObject
- Answer: A) InputEvent

46. KeyListener interface has got _______________ methods.


- A) 1
- B) 2
- C) 3
- D) 4
- Answer: C) 3
UNIT 2 MCQ BY ROOMIES

47. mouseDragged() method present in which listener?


- A) ActionListener
- B) MouseListener
- C) MouseMotionListener
- D) MouseEventAdapter
- Answer: C) MouseMotionListener

48. MouseEvent is a subclass of which of these classes?


- A) InputEvent
- B) TextEvent
- C) AWTEvent
- D) EventObject
- Answer: A) InputEvent

49. Name the event that gets generated when a button is clicked.
- A) ButtonEvent
- B) ClickEvent
- C) ActionEvent
- D) PressEvent
- Answer: C) ActionEvent

50. Name the method defined in EventObject class that returns the Object generated from the
event. Select the one correct answer.
- A) getObject()
- B) getEventSource()
- C) getSourceObject()
- D) getSource()
- Answer: D) getSource()
UNIT 2 MCQ BY ROOMIES

51. On which AWT component event listener can not be applied?


- A) Button
- B) Panel
- C) Label
- D) Textfield
- Answer: C) Label

52. public void mouseMoved(MouseEvent me) is a method of _______________.


- A) MouseListener
- B) ActionListener
- C) MouseMotionListener
- D) MouseEventAdapter
- Answer: C) MouseMotionListener

53. Scrollbar control generates ……………………………. Event.


- A) ScrollEvent
- B) AdjustEvent
- C) AdjustmentEvent
- D) ScrollBarEvent
- Answer: C) AdjustmentEvent

54. Select the proper constructor of EventObject class.


- A) EventObject(Object src)
- B) EventObject(EventType type)
- C) EventObject(int id)
- D) EventObject(String name)
- Answer: A) EventObject(Object src)
UNIT 2 MCQ BY ROOMIES

55. Some of the event listener interfaces are_____________.


- A) Limited to ActionListener
- B) Limited to MouseListener
- C) Limited to KeyListener
- D) All of these
- Answer: D) All of these

56. Source object can register only one listener.


- A) True
- B) False
- Answer: B) False

57. Text changed ( ) method is used for______.


- A) When the text is updated
- B) When the text is selected
- C) When the text is changed
- D) When the text is cleared
- Answer: C) When the text is changed

58. TextEvent defines the following integer constant:


- A) TEXT_CHANGED
- B) TEXT_MODIFIED
- C) TEXT_UPDATED
- D) TEXT_VALUE_CHANGED
- Answer: D) TEXT_VALUE_CHANGED
UNIT 2 MCQ BY ROOMIES

59. TextField generates which events.


- A) ActionEvent, TextEvent
- B) ChangeEvent, TextEvent
- C) FocusEvent, TextEvent
- D) ActionEvent, KeyEvent
- Answer: A) ActionEvent, TextEvent

60. The constructor which the Text Event class defines.


- A) TextEvent(Object source, int event_type)
- B) TextEvent(int event_type, Object source)
- C) TextEvent(int event_type)
- D) TextEvent()
- Answer: A) TextEvent(Object source, int event_type)

61. The default layout of the contentPane of a JApplet is __________.


- A) FlowLayout
- B) BorderLayout
- C) GridLayout
- D) CardLayout
- Answer: B) BorderLayout

62. The delegation Event model is based on the concept of


- A) Delegated Inheritance
- B) Delegated Implementation
- C) Both A and B
- D) Delegated Abstraction
- Answer: C) Both A and B
UNIT 2 MCQ BY ROOMIES

63. The delegation model is used as a standard for


- A) Event Handling
- B) Event Delegation
- C) Event Listening
- D) Event Management
- Answer: C) Event Listening

64. The Following are event classes


- A) Action Event, Focus Event, Container Event
- B) MouseEvent, WindowEvent, KeyBoardEvent
- C) ActionEvent, FocusEvent, ContainerEvent
- D) ActionEvent, KeyEvent, MouseEvent
- Answer: C) Action Event, Focus Event, Container Event

65. The Following method is an abstract method of the MouseEvent class.


- A) getClickCount()
- B) getPressCount()
- C) getMouseCount()
- D) getEventCount()
- Answer: A) getClickCount()

66. The following method is an abstract method of TextListener interface.


- A) textChanged(TextEvent obj)
- B) textUpdated(TextEvent obj)
- C) textModified(TextEvent obj)
- D) textStateChanged(TextEvent obj)
- Answer: A) textChanged(TextEvent obj)

67. The following method must be overridden to handle KeyEvent.


UNIT 2 MCQ BY ROOMIES

- A) keyPressed(KeyEvent e)
- B) keyReleased(KeyEvent e)
- C) keyTyped(KeyEvent e)
- D) All of the mentioned
- Answer: D) All of the mentioned

68. The method in the ActionEvent ________ returns the action command of the button.
- A) getAction()
- B) fetchAction()
- C) getCommand()
- D) getActionCommand()
- Answer: D) getActionCommand()

69. The method that is used for registering a keyboard event is known as
____________________.
- A) registerKeyListener()
- B) addKeyListener()
- C) attachKeyListener()
- D) setKeyListener()
- Answer: B) addKeyListener()

70. The MouseEvent class does not define the _____________ integer constant.
- A) MOUSE_WHEELMOVE
- B) MOUSE_DRAGGED
- C) MOUSE_MOVED
- D) MOUSE_PRESSED
- Answer: A) MOUSE_WHEELMOVE
UNIT 2 MCQ BY ROOMIES

71. The MouseListener interface is used to make mouse handling.


- A) True
- B) False
- Answer: A) True

72. The MouseListener's _______________ method is called after the mouse button is released.
- A) public void mouseUp(MouseEvent e)
- B) public void mouseReleased(MouseEvent e)
- C) public void mouseClicked(MouseEvent e)
- D) public void mousePressed(MouseEvent e)
- Answer: B) public void mouseReleased(MouseEvent e)

73. The MouseMotionListener Interface has __________________ method.


- A) void mouseMoved(MouseEvent me)
- B) void mouseDragged(MouseEvent me)
- C) void mousePressed(MouseEvent me)
- D) void mouseClicked(MouseEvent me)
- Answer: B) void mouseDragged(MouseEvent me)

74. The signature for the registration method for an ActionEvent should be.
- A) public void addActionListener(ActionListener l)
- B) public void registerActionListener(ActionListener l)
- C) public void addEventActionListener(ActionListener l)
- D) public void attachActionListener(ActionListener l)
- Answer: A) public void addActionListener(ActionListener l)

75. The superclass of ContainerEvent, FocusEvent, and WindowEvent is _______________.


UNIT 2 MCQ BY ROOMIES

- A) ComponentEvent
- B) AWTEvent
- C) EventObject
- D) InputEvent
- Answer: B) AWTEvent

76. The ________ interface is used to handle button events:


- A) ActionListener
- B) ButtonListener
- C) ClickListener
- D) ButtonEvent
- Answer: A) ActionListener

77. The ___________ interface handles list events:


- A) ItemListener, ActionListener
- B) ActionListener, ListListener
- C) ListListener
- D) ItemListener
- Answer: D) ItemListener

78. The __________________interface handles choice events.


- A) ChoiceListener
- B) ActionListener
- C) ItemListener
- D) ActionEvent
- Answer: C) ItemListener

79. Till now two models have been introduced in java for:
UNIT 2 MCQ BY ROOMIES

- A) Event Handling
- B) Receiving and processing events
- C) Event Delegation
- D) Both A and B
- Answer: D) Both A and B

80. To write event-driven programs using AWT or Swings, Use?


- A) Option A
- B) Option B
- C) Both Option A and B
- D) Neither Option A nor B
- Answer: C) Both Option A and B

81. What is a listener in the context of event handling?


- A) A listener is an object that is notified when an event occurs.
- B) A listener is a function that is invoked when an event occurs.
- C) A listener is a class that is responsible for creating events.
- D) A listener is a keyword in Java for handling events.
- Answer: A) A listener is an object that is notified when an event occurs.

82. What is a listener in the context of event handling?


- A) A listener is an object that is notified when an event occurs.
- B) A listener is a function that is invoked when an event occurs.
- C) A listener is a class that is responsible for creating events.
- D) A listener is a keyword in Java for handling events.
- Answer: A) A listener is an object that is notified when an event occurs.

83. What is an event in the Delegation Event model?


UNIT 2 MCQ BY ROOMIES

- A) An event is an object that describes a state change in a source.


- B) An event is a function that is triggered when a user interacts with the application.
- C) An event is a keyword in Java for handling user input.
- D) An event is a type of loop in programming.
- Answer: A) An event is an object that describes a state change in a source.

84. What is event handling?


- A) Controlling Event
- B) Processing Events
- C) Managing Events
- D) All of the Above
- Answer: D) All of the Above

85. What is the use of MouseMotion Listener Interface?


- A) mouseDragged()
- B) mousePressed()
- C) mouseMoved()
- D) mouseReleased()
- Answer: A) mouseDragged()

86. What kind of event is fired when the user selects an item from a menu?
- A) MenuEvent
- B) ItemEvent
- C) ActionEvent
- D) SelectEvent
- Answer: C) ActionEvent

87. When a component obtains keyboard focus, which method is invoked?


UNIT 2 MCQ BY ROOMIES

- A) void focusChanged(FocusEvent fe)


- B) void focusGained(FocusEvent fe)
- C) void keyboardFocus(FocusEvent fe)
- D) void focusActivated(FocusEvent fe)
- Answer: B) void focusGained(FocusEvent fe)

88. When a component is added or removed from a container, ________________ event is


generated?
- A) AddEvent
- B) RemoveEvent
- C) ContainerEvent
- D) ChangeEvent
- Answer: C) ContainerEvent

89. When a key is pressed, which event is occurred?


- A) KeyPressEvent
- B) KeyTypedEvent
- C) KeyPressedEvent
- D) Both A and B
- Answer: D) Both A and B

90. When a list item is double-clicked, which event is generated?


- A) DoubleClickEvent
- B) ClickEvent
- C) ActionEvent
- D) ItemEvent
- Answer: C) ActionEvent

91. When the size of a component is changed, ________________ event is generated.


UNIT 2 MCQ BY ROOMIES

- A) ResizeEvent
- B) SizeChangeEvent
- C) ComponentChangeEvent
- D) ComponentEvent
- Answer: D) ComponentEvent

92. When two or more objects are added as listeners for the same event, which listener is first
invoked to handle the event?
- A) The first listener added
- B) The last listener added
- C) There is no way to determine which listener will be invoked first.
- D) All listeners are invoked simultaneously.
- Answer: C) There is no way to determine which listener will be invoked first.

93. When we need to use checkboxes or items from the list or use a checkable menu, an
________________ is generated.
- A) CheckEvent
- B) ItemEvent
- C) CheckboxEvent
- D) SelectEvent
- Answer: B) ItemEvent

94. Which of the following are true


- A) The event-inheritance model is more efficient than the event-delegation model.
- B) The event-delegation model is more efficient than the event-inheritance model.
- C) Both A and B
- D) Neither A nor B
- Answer: A) The event-inheritance model is more efficient than the event-delegation model.

95. Which among the following is not an AWT Event


- A) ActionEvent
- B) FocusEvent
- C) AdjustEvent
UNIT 2 MCQ BY ROOMIES

- D) ContainerEvent
- Answer: C) AdjustEvent

96. Which among the following is true for Adaptor Classes?


- A) Adaptor classes increase the complexity of event listeners.
- B) Adaptor classes reduce the complexity of event listeners.
- C) Adaptor classes have no impact on the complexity of event listeners.
- D) Adaptor classes replace event listeners.
- Answer: B) Adaptor classes reduce the complexity of event listeners.

97. Which are various methods of WindowListener interface from the following?
- A) void windowOpened(WindowEvent e)
- B) void windowClosing(WindowEvent e)
- C) void windowActivated(WindowEvent e)
- D) All of the above
- Answer: D) All of the above

98. Which are WindowEvent class defines integer constants?


- A) WINDOW_OPENED, WINDOW_CLOSED
- B) WINDOW_CLOSING, WINDOW_CLOSED
- C) WINDOW_ACTIVATED, WINDOW_CLOSED
- D) All the Above
- Answer: D) All the Above

99. Which class is at the root in the Java event class hierarchy?
- A) EventClass
- B) EventObject
- C) EventSource
- D) RootEvent
- Answer: B) EventObject
UNIT 2 MCQ BY ROOMIES

100. Which class is used for this Processing Method processActionEvent()?


- A) Button
- B) List
- C) MenuItem
- D) All of the above
- Answer: D) All of the above

101. Which event is generated by List?


- A) SelectEvent
- B) ItemEvent
- C) ListEvent
- D) Both A and B
- Answer: D) Both A and B

102. Which Event is generated by Scrollbar class?


- A) AdjustmentEvent
- B) ScrollEvent
- C) ScrollbarEvent
- D) AdjustEvent
- Answer: A) AdjustmentEvent

103. Which is a method of the MouseMotionListener Interface?


- A) public void mouseDragged(MouseEvent )
- B) public void mouseMoved(MouseEvent )
- C) public void dragMouse(MouseEvent )
- D) public void moveMouse(MouseEvent )
- Answer: A) public void mouseDragged(MouseEvent )
UNIT 2 MCQ BY ROOMIES

104. Which is not the correct listener?


- A) TextAreaListener
- B) MouseListener
- C) KeyListener
- D) ActionListener
- Answer: A) TextAreaListener

105. Which is the interface of MouseEvent class?


- A) ActionListener
- B) MouseAdapter
- C) MouseListener
- D) MouseMotionListener
- Answer: C) MouseListener

106. Which Listener handles all List related Events?


- A) ActionListener
- B) ItemListener
- C) ListListener
- D) ListAdapter
- Answer: B) ItemListener

107. Which method does display the message whenever there is an item selection or deselection
of the CheckboxMenuItem menu?
- A) itemSelected()
- B) itemChanged()
- C) itemStateChanged method.
- D) itemClicked()
- Answer: C) itemStateChanged method.
UNIT 2 MCQ BY ROOMIES

108. Which method is applicable if alphanumeric key is pressed?


- A) keyTyped
- B) keyPressed
- C) keyReleased
- D) keyActivated
- Answer: A) keyTyped

109. Which method is defined when the action event occurs?


- A) actionPerformed()
- B) actionEvent()
- C) eventPerformed()
- D) eventAction()
- Answer: A) actionPerformed()

110. Which Method Is used to register a mouse Motion Listener?


- A) addMouseListener()
- B) registerMouseMotionListener()
- C) addMouseMotionListener()
- D) registerMouseListener()
- Answer: C) addMouseMotionListener()

111. Which method used for returning mouse coordinates?


- A) getCoordinates()
- B) fetchMouseCoordinates()
- C) retrieveMousePosition()
- D) getX(), getY()
- Answer: D) getX(), getY()
UNIT 2 MCQ BY ROOMIES

112. Which methods are defined by ComponentListener?


- A) void componentHidden(ComponentEvent obj)
- B) void componentShown(ComponentEvent obj)
- C) void componentResized(ComponentEvent obj)
- D) All of the above
- Answer: D) All of the above

113. Which of the following are correct event handling methods?


- A) mousePressed(MouseEvent e){}
- B) keyTyped(KeyEvent e){}
- C) actionPerformed(ActionEvent e){}
- D) All of the above
- Answer: D) All of the above

114. Which of the following are true?


- A) Both A and B
- B) Neither A nor B
- C) Only A
- D) Only B
- Answer: A) Both A and B

115. Which of the following components generate ActionEvent?


- A) Button
- B) TextField
- C) Checkbox
- D) None
- Answer: D) None
UNIT 2 MCQ BY ROOMIES

116. Which of the following components can generate ItemEvent?


- A) CheckBoxMenuItem
- B) TextArea
- C) Label
- D) RadioButton
- Answer: A) CheckBoxMenuItem

117. Which of the following is not an event class in Java?


- A) ClickEvent
- B) DragEvent
- C) KeyEvent
- D) FocusEvent
- Answer: A) ClickEvent

118. Which of the following is the highest class in the event delegation class hierarchy?
- A) java.util.EventObject
- B) java.awt.event.Event
- C) java.awt.event.DelegateEvent
- D) java.awt.event.HighestEvent
- Answer: A) java.util.EventObject

119. Which of the following is the legal adapter class in Java?


- A) KeyAdapter
- B) ButtonAdapter
- C) TextAreaAdapter
- D) WindowAdapter
- Answer: A) KeyAdapter
UNIT 2 MCQ BY ROOMIES

120. Which of the following Listeners have their Adapter class?


- A) MouseListener
- B) ActionListener
- C) WindowListener
- D) KeyListener
- Answer: C) WindowListener

121. Which of the following methods is used to register a listener to a button?


- A) addActionListener(ActionListener obj)
- B) registerListener(EventListener obj)
- C) attachListener(Listener obj)
- D) setListener(ActionListener obj)
- Answer: A) addActionListener(ActionListener obj)

122. Which of these events is generated when a button is pressed?


-

A) ActionEvent
- B) ButtonEvent
- C) ClickEvent
- D) PressEvent
- Answer: A) ActionEvent

123. Which of these methods can be used to obtain the command name for invoking
ActionEvent object?
- A) getActionCommand()
- B) retrieveCommand()
- C) fetchActionCommand()
UNIT 2 MCQ BY ROOMIES

- D) obtainCommandName()
- Answer: A) getActionCommand()

124. Which of these is an AdapterClass?


- A) KeyAdapter class
- B) ButtonAdapter class
- C) WindowAdapter class
- D) MouseMotionAdapter class
- Answer: A) KeyAdapter class

125. Which of these adapter classes from the following?


- A) MouseAdapter
- B) ActionListenerAdapter
- C) KeyListenerAdapter
- D) EventAdapter
- Answer: A) MouseAdapter

126. Which of these are constants defined in Window Event class?


- A) WINDOW_OPENED
- B) WINDOW_CLOSED
- C) WINDOW_ACTIVATED
- D) All of the Above
- Answer: D) All the Above

127. Which of these constant values will change when the button at the end of the scrollbar is
clicked to increase its value?
- A) UNIT_DECREMENT
- B) UNIT_INCREMENT
- C) BLOCK_DECREMENT
UNIT 2 MCQ BY ROOMIES

- D) BLOCK_INCREMENT
- Answer: B) UNIT_INCREMENT

128. Which of these events is generated when the computer gains or loses input focus?
- A) FocusEvent
- B) InputFocusEvent
- C) WindowEvent
- D) KeyEvent
- Answer: A) FocusEvent

129. Which of these events will be notified if the scrollbar is manipulated?


- A) AdjustmentEvent()
- B) ScrollEvent()
- C) ScrollbarEvent()
- D) ManipulationEvent()
- Answer: A) AdjustmentEvent()

130. Which of these events is generated when a window is minimized?


- A) WindowOpenedEvent
- B) WindowMinimizedEvent
- C) WindowStateChangedEvent
- D) Both a and b
- Answer: D) Both a and b

131. Which of these events is generated when the component is added or removed?
- A) ContainerEvent
- B) AddRemoveEvent
- C) ComponentChangeEvent
- D) ComponentEvent
UNIT 2 MCQ BY ROOMIES

- Answer: A) ContainerEvent

132. Which of these events will be generated if we close a Frame's window?


- A) WindowEvent
- B) CloseEvent
- C) FrameEvent
- D) ExitEvent
- Answer: A) WindowEvent

133. Which of these interfaces define a method actionPerformed()?


- A) ActionListener
- B) ActionPerformedListener
- C) ActionEvent
- D) ActionListenerInterface
- Answer: A) ActionListener

134. Which of these is the superclass of WindowEvent class?


- A) ComponentEvent
- B) EventObject
- C) AWTEvent
- D) WindowObject
- Answer: A) ComponentEvent

135. Which of these is the superclass of all Adapter classes?


- A) Applet
- B) AdapterObject
- C) Adapter
- D) EventAdapter
UNIT 2 MCQ BY ROOMIES

- Answer: C) Adapter

136. Which of these methods are used to determine the type of adjustment event?
- A) getAdjustmentType()
- B) determineAdjustmentType()
- C) fetchAdjustmentType()
- D) obtainAdjustmentType()
- Answer: A) getAdjustmentType()

137. Which of these methods are used to register a mouse motion listener?
- A) addMouseListener()
- B) addMouseMotionListener()
- C) registerMouseMotionListener()
- D) attachMouseMotionListener()
- Answer: B) addMouseMotionListener()

138. Which of these methods can be used to know the degree of adjustment made by the user?
- A) getDegree()
- B) fetchAdjustment()
- C) determineAdjustment()
- D) getValue()
- Answer: D) getValue()

139. Which of these methods is defined in MouseMotionAdapter class?


- A) mouseMoved()
- B) mouseDragged()
- C) mouseClicked()
- D) mousePressed()
UNIT 2 MCQ BY ROOMIES

- Answer: B) mouseDragged()

140. Which of these methods is used to get the x-coordinate of the mouse?
- A) getX()
- B) fetchX()
- C) obtainX()
- D) determineX()
- Answer: A) getX()

141. Which of these methods is used to get Y coordinate of the mouse?


- A) fetchY()
- B) determineY()
- C) obtainY()
- D) getY()
- Answer: D) getY()

142. Which of these methods is used to know the full URL of a URL object?
- A) getFullURL()
- B) fetchURL()
- C) determineURL()
- D) getHost()
- Answer: D) getHost()

143. Which of these methods is used to obtain the object that generated a ComponentEvent?
- A) getComponent()
- B) fetchObject()
- C) determineObject()
- D) getContainer()
UNIT 2 MCQ BY ROOMIES

- Answer: D) getContainer()

144. Which of these methods is used to obtain the object that generated a WindowEvent?
- A) getWindowObject()
- B) fetchWindowObject()
- C) determineWindowObject()
- D) getWindow()
- Answer: D) getWindow()

145. Which of these methods will be invoked if a character is generated?


- A) keyGenerated()
- B) generateKey()
- C) keyPressed()
- D) keyTyped()
- Answer: D) keyTyped()

146. Which of these methods will respond when you click any button by mouse?
- A) mouseClicked()
- B) buttonClicked()
- C) actionPerformed()
- D) All of the mentioned
- Answer: D) All of the mentioned

147. Which of these methods will respond when you click any button by mouse?
- A) mouseClicked()
- B) buttonClicked()
- C) actionPerformed()
- D) All of these
UNIT 2 MCQ BY ROOMIES

- Answer: C) actionPerformed()

148. Which of these is not a constant defined in ComponentEvent class?


- A) COMPONENT_SIZED
- B) COMPONENT_MOVED
- C) COMPONENT_RESIZED
- D) COMPONENT_CLOSED
- Answer: D) COMPONENT_CLOSED

149. Which two parameters are required for JTable constructor to create a table?
- A) Data array and Column Headings
- B) Rows and Columns
- C) Table size and Color
- D) Data array and Table size
- Answer: A) Data array and Column Headings

150. windowEvent is a subclass of ________________________


- A) EventObject()
- B) ComponentEvent()
- C) AWTEvent()
- D) WindowEvent()
- Answer: C) AWTEvent()

151. __________ generates action events when an item is double-clicked.


- A) List
- B) Checkbox
- C) Choice
- D) Button
UNIT 2 MCQ BY ROOMIES

- Answer: A) List

152. __________ is generated when a checkbox is clicked, a list item is clicked, a choice selection
is made, or a checkable menu item is selected or deselected.
- A) MouseEvent
- B) ItemEvent
- C) ActionEvent
- D) CheckboxEvent
- Answer: B) ItemEvent

153. ___________ class provides an empty implementation of all methods in an Event Listener
interface?
- A) Adapter
- B) EmptyListener
- C) AbstractListener
- D) NullListener
- Answer: A) Adapter

154. _________________ generates an event and sends it to one or more listeners.


- A) EventGenerator
- B) EventDispatcher
- C) EventEmitter
- D) Event Source
- Answer: D) Event Source

155.a) ActionEvent: It indicates the component-defined events occurred


b)MouseEvent: Events generated during the mouse operation for the object
c) FocusEvent: This class indicates about the focus where the focus has gained or lost by the
object.
d) KeyEvent: It is generated When a key is pressed
UNIT 2 MCQ BY ROOMIES

- A) All a, b, c, and d are correct


- B) Only a and b are correct
- C) Only c and d are correct
- D) Only a, b, and c are correct
- Answer: A) All a, b, c, and d are correct

156. For the following code, select the method that can be used to handle the event.
```java
import java.awt.event.;
import java.awt.;
import java.applet.;

public class checkbackg extends Applet implements ItemListener {


Checkbox m1, m2, m3;

public void init() {


m1 = new Checkbox("A");
m2 = new Checkbox("B");
m3 = new Checkbox("C");
add(m1);
add(m2);
add(m3);
m1.addItemListener(this);
m2.addItemListener(this);
}

public void ______________(ItemEvent ie) {


if (ie.getSource() == m1)
setBackground(Color.red);
if (ie.getSource() == m2)
setBackground(Color.green);
}
UNIT 2 MCQ BY ROOMIES

}
/<applet code=checkbackg.class height=150 width=150> </applet>/
```
- A) itemStateChanged(ItemEvent ie)
- B) itemChanged(ItemEvent ie)
- C) itemSelected(ItemEvent ie)
- D) itemClicked(ItemEvent ie)
- Answer: A) itemStateChanged(ItemEvent ie)

157. For Key events, KeyEvent class is used 2) For Mouse motion events, MouseEvent class is
used 3) For Component events, ComponentEvent class is used 4) For Window events,
WindowEvent class is used
- A) 1, 2, 3 are true
- B) 1, 2, 4 are true
- C) 2, 3, 4 are true
- D) 1, 3, 4 are true
- Answer: D) 1, 3, 4 are true

158. What will be the output of the following code?


```java
import java.awt.;
import java.applet.;
import java.awt.event.;

public class adm extends Applet {


public void init() {
addMouseMotionListener(new mma1(this));
UNIT 2 MCQ BY ROOMIES

}
}

class mma1 extends MouseAdapter {


adm a;

public mma1(adm a) {
this.a = a;
}

public void mouseDragged(MouseEvent me) {


a.showStatus("mouse dragged");
}
}
/<applet code="adm" width=500 height=500> </applet>/
```
- A) Error
- B) "mouse dragged" will be displayed when the mouse is dragged over the applet.
- C) "mouse dragged" will be displayed when the mouse is clicked.
- D) The applet window will be blank.
- Answer: B) "mouse dragged" will be displayed when the mouse is dragged over the applet.

159. Which line of code is missing in the following code, and what is the error statement?
```java
import java.awt.;
import java.awt.event.;
import java.applet.;

/<applet code="KeyEventDemo.class" width=400 height=400> </applet>/


public class KeyEventDemo extends Applet implements _______________ {
String msg = "";
UNIT 2 MCQ BY ROOMIES

public void init() {


addKeyListener(this);
}

public void keyPressed(KeyEvent e) {


showStatus("Key Down");
int key = e.getKeyCode();
repaint();
}

public void keyTyped(KeyEvent e) {


msg += e.getKeyChar();
repaint();
}

public void paint(Graphics g) {


g.drawString(msg, 10, 20);
}
}
```
- A) KeyListener and public void keyReleased(KeyEvent e) { showStatus("Key up"); }
- B) KeyAdapter and public void keyReleased(KeyEvent e) { showStatus("Key up"); }
- C) KeyAdapter and public void keyPressed(KeyEvent e) { showStatus("Key Down"); }
- D) KeyListener and public void keyPressed(KeyEvent e) { showStatus("Key Down"); }
- Answer: A) KeyListener and public void keyReleased(KeyEvent e) { showStatus("Key up");
}

160. What will happen when you attempt to compile and run the following code?
```java
import java.awt.;
import java.awt.event.;
UNIT 2 MCQ BY ROOMIES

public class mouseClick extends Frame implements MouseListener {


public static void main(String argv[]) {
mouseClick s = new MClick();
}

MClick() {
this.addMouseListener(this);
}

public void mouseClicked(MouseEvent e) {


System.out.println(e.getWhen());
}
}
```
- A) Error: not override MouseListener methods, class name not found
- B) The program will compile and run successfully, and it will print the time of mouse click.
- C) The program will compile and run successfully, but it will not print anything.
- D) The program will compile successfully but will throw an exception at runtime.
- Answer: A) Error: not override MouseListener methods, class name not found

161. Which statement is incorrect or missing in the following code?


```java
import java.awt.;
import java.awt.event.;
import javax.swing.;

public class radio extends JApplet implements ActionListener {


public void init() {
Container c = getContentPane();
UNIT 2 MCQ BY ROOMIES

c.setLayout(new FlowLayout());

JRadioButton b1 = new JRadioButton("Red");


b1.addActionListener(this);
c.add(b1);

JRadioButton b2 = new JRadioButton("Green");


b2.addActionListener(this);
c.add(b2);

JRadioButton b3 = new JRadioButton("Blue");


b3.addActionListener(this);
c.add(b3);

ButtonGroup bg = new ButtonGroup();


bg.add(b1);
bg.add(b2);
bg.add(b3);
}

public void actionPerformed(ActionEvent e) {


setBackground(e.getActionCommand());
}
}
```
- A) Container c = getContentPane();
- B) Container c = new Container();
- C) Container c = new JContainer();
- D) Container c = new JPanel();
- Answer: A) Container c = getContentPane();
UNIT 2 MCQ BY ROOMIES

162. A Frame's background color is set to Color.Yellow, and a Button's background color is set
to Color.Blue. Suppose the Button is added to a Panel, which is added to the Frame. What
background color will be used with the Panel?
- A) Color.Blue
- B) Color.Yellow
- C) Color.Green
- D) Color.Red
- Answer: B) Color.Yellow

163. A Java exception is an instance of __________.


- A) Breakable
- B) ExceptionObject
- C) Throwable
- D) ErrorObject
- Answer: C) Throwable

164. Abstract Methods of MouseMotion Listener Interface.


- A) mouseMoved(MouseEvent)
- B) mouseDragged(MouseEvent)
- C) mousePressed(MouseEvent)
- D) mouseClicked(MouseEvent)
- Answer: A) mouseMoved(MouseEvent), B) mouseDragged(MouseEvent)

165. Action event is applied on


- A) Button, TextField, List, Menu
- B) CheckBox, TextArea, RadioButton
- C) Window, Frame, Dialog
- D) Panel, Scrollbar, Label
- Answer: A) Button, TextField, List, Menu

166. Adapter classes are similar to EventListener interfaces?


- A) True
- B) False
UNIT 2 MCQ BY ROOMIES

- Answer: A) True

167: Add the missing statement in the given Java program:

```java
import java.awt.;
import java.awt.event.;
import java.applet.;

public class ButtonDemo extends Applet implements ActionListener {


String msg = "";
Button yes, no, maybe;

public void init() {


yes = new Button("Yes");
maybe = new Button("Undecided");
add(yes);
add(no);
add(maybe);
yes.addActionListener(this);
no.addActionListener(this);
maybe.addActionListener(this);
}

public void actionPerformed(ActionEvent ae) {


String str = ae.getActionCommand();
if (str.equals("Yes")) {
msg = "You pressed Yes.";
} else if (str.equals("No")) {
msg = "You pressed No.";
} else {
UNIT 2 MCQ BY ROOMIES

msg = "You pressed Undecided.";


}
repaint();
}

public void paint(Graphics g) {


g.drawString(msg, 6, 100);
}
}
```

Options:
1. `Button no=new Button("NO");`
2. `Button undecided=new Button("Undecided");`
3. `Button maybe=new Button("Maybe");`
4. `Button no=new Button("No");`

Answer: 1. `Button no=new Button("NO");`

---

168: After inserting which statement in the following program, the output window will be
closed when the close button is clicked?

```java
import java.awt.event.;
import java.awt.;

class Demo extends Frame {


Demo() {
setSize(500,500);
setVisible(true);
UNIT 2 MCQ BY ROOMIES

setTitle("My Window");
}

public static void main(String args[]) {


new Demo();
}
}
class AdapterDemo extends WindowAdapter {
Demo d1;

AdapterDemo(Demo d) {
d1=d;
}
public void windowClosing(WindowEvent we) {
d1.dispose();
}
}
```
Options:
1. `addWindowListener(new AdapterDemo(this));`
2. `this.addWindowListener(new AdapterDemo(this));`
3. `AdapterDemo ad = new AdapterDemo(this);`
4. `new AdapterDemo(this).addWindowListener();`

Answer: 2. `this.addWindowListener(new AdapterDemo(this));`

---

169: An event adapter can be implemented using ___________.

Options:
1. `MouseListener`
UNIT 2 MCQ BY ROOMIES

2. `All of the Above`


3. `WindowAdapter`
4. `ActionListener`

Answer: 2. `All of the Above`

---

170:An event is generated when the internal state of the event source is __________.

Options:
1. `stopped`
2. `changed`
3. `initialized`
4. `paused`

Answer: 2. `changed`

---

171:Analyse the following code and find out errors:


```java
import java.awt.;
import java.applet.;
import java.awt.event.;
public class Demo extends Applet implements ItemListener {
Label jlb1 = new Label("Select Color:");
UNIT 2 MCQ BY ROOMIES

Choice ch = new Choice();


TextField jtf1 = new TextField(12);
public void init() {
city=new List(4);
city.addItem("Pune");
city.addItem("Mumbai");
city.addItem("Nagpur");
city.addItem("Kolhapur");
city.addItem("Solapur");
jtf=new TextField(12);
add(jtf);
}
public void itemStateChanged(ItemEvent ie) {
String s=(String)ie.getItem();
jtf1.setText(s);
}
}
```
Options:
1. `Error is in the statement String s=(String)ie.getItem();`
2. `Error is in the statement city=new List(4);`
3. `Error is in the statement add(jtf);`
4. `No errors in the code.`

Answer: 1. `Error is in the statement String s=(String)ie.getItem();`

172:Analyse the following code and select the missing statement:


```java
import javax.swing.;
import javax.swing.tree.;
public class TreeDemo extends JFrame {
public static void main(String args[]) {
UNIT 2 MCQ BY ROOMIES

TreeDemo frame = new TreeDemo();


frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
DefaultMutableTreeNode mercury = new DefaultMutableTreeNode("Mercury");
root.add(mercury);
DefaultMutableTreeNode venus = new DefaultMutableTreeNode("Venus");
root.add(venus);
DefaultMutableTreeNode mars = new DefaultMutableTreeNode("Mars");
root.add(mars);
JTree tree = new JTree(root);
JScrollPane scrollPane = new JScrollPane(tree);
frame.add(scrollPane, BorderLayout.CENTER);
frame.setSize(300, 150);
frame.setVisible(true);
}
}
``
Options:
1. `import java.awt.;`
2. `import java.util.;`
3. `import javax.swing.tree.DefaultMutableTreeNode;`
4. `import javax.swing.;`

Answer: 4. `import javax.swing.;`

---

173:Analyse the following code and find out the missing statement:

```java
import java.awt.;
import java.applet.;
UNIT 2 MCQ BY ROOMIES

public class Demo extends Applet implements ItemListener {


TextField jtf;
List city;

public void init() {


city=new List(4);
city.addItem("Pune");
city.addItem("Mumbai");
city.addItem("Nagpur");
city.addItem("Kolhapur");
city.addItem("Solapur");
jtf=new TextField(12);
add(jtf);
}

public void itemStateChanged(ItemEvent ie) {


String s=city.getSelectedItem();
jtf.setText(s);
}
}
```

Options:
1. `TextField jtf=new TextField(12);`
2. `TextField jtf;`
3. `TextField jtf=new TextField();`
4. `All of the above`

Answer: 2. `TextField jtf;`

---
UNIT 2 MCQ BY ROOMIES

174:What will be the output of the following code?

```java
import javax.swing.;
import javax.swing.border.;
import java.awt.;

public class BorderTest extends JFrame {


public BorderTest() {
Border border = new TitledBorder("MyButton");
JButton b1 = new JButton("Ok");
JButton b2 = new JButton("Cancel");
b1.setBorder(border);
b2.setBorder(border);
add(b1, BorderLayout.NORTH);
add(b2, BorderLayout.SOUTH);
}

public static void main(String args[]) {


JFrame f = new BorderTest();
f.setSize(200, 100);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
```

Options:
1. `Two buttons displayed with the same border.`
2. `Two buttons displayed with different borders.`
3. `No buttons displayed.`
UNIT 2 MCQ BY ROOMIES

4. `One button displayed with the specified border.`

Answer: 1. `Two buttons displayed with the same border.`

175: Analyse the following code:

```java
import javax.swing.;
import java.awt.;

public class Test extends JFrame {


public Test() {
setLayout(new FlowLayout());
add(new

JButton("Java"));
add(new JButton("Java"));
add(new JButton("Java"));
add(new JButton("Java"));
}

public static void main(String[] args) {


JFrame frame = new Test();
frame.setSize(200, 100);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
```

Options:
1. `Four buttons are displayed with the same text "Java".`
UNIT 2 MCQ BY ROOMIES

2. `One button is displayed with the text "Java".`


3. `No buttons are displayed.`
4. `Two buttons are displayed with the text "Java".`

Answer: 1. `Four buttons are displayed with the same text "Java".`

---

176: `ButtonGroup bg = new ButtonGroup();` is used to create a group of ___________.

Options:
1. `CheckBox`
2. `RadioButton`
3. `ToggleButton`
4. `ComboBox`

Answer: 2. `RadioButton`

177: Choose the correct missing statement from the given code:

```java
import java.awt.;
import java.applet.;
import java.awt.event.;

public class eventdemo2 extends Applet implements ActionListener {


TextField t1, t2;
Button b1;

public void init() {


t1 = new TextField(5);
t2 = new TextField(5);
UNIT 2 MCQ BY ROOMIES

b1 = new Button("FACTORIAL");
add(t1);
add(t2);
add(b1);
}

public void actionPerformed(ActionEvent a) {


if (a.getSource() == b1) {
int fact = 1;
int n1 = Integer.parseInt(t1.getText());
while (n1 != 0) {
fact = fact (n1);
n1 = n1 - 1;
}
t2.setText(Integer.toString(fact));
}
}
}
```

Options:
1. `b1.addActionListener(this);`
2. `t1.addActionListener(this);`
3. `b1.addMouseListener(this);`
4. `t2.addActionListener(this);`

Answer: 1. `b1.addActionListener(this);`

---

178: Choose the correct option for the given code:


UNIT 2 MCQ BY ROOMIES

```java
import java.awt.;
import java.awt.event.;
import java.applet.;

public class DemoE extends Applet {


public void init() {
Button b = new Button("Click");
b.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent me) {
showStatus("Button clicked");
}
});
add(b);
}
}
```

Options:
1. The program will display "Button clicked" message in the status bar on clicking the button with the
mouse.
2. The program will display "Mouse clicked" message in the status bar on clicking the button with the
mouse.
3. The program will display "Button pressed" message in the status bar on pressing the button.
4. The program will not display any message.

Answer: 1. The program will display "Button clicked" message in the status bar on clicking the
button with the mouse.

---

179: Choose the correct output for the given code:


UNIT 2 MCQ BY ROOMIES

```java
/ <applet code="MyControl10" width=300 height=300> </applet> /
import java.applet.;
import java.awt.;
import java.awt.event.;

public class MyControl10 extends Applet implements ItemListener {


CheckboxGroup g;
Checkbox c1, c2, c3;
int red, green, blue;

public void init() {


g = new CheckboxGroup();
c1 = new Checkbox("Red", g, false);
c2 = new Checkbox("Green", g, false);
c3 = new Checkbox("Blue", g, true);
setLayout(null);
c1.setBounds(20, 20, 70, 20);
c2.setBounds(20, 45, 70, 20);
c3.setBounds(20, 70, 70, 20);
add(c1);
add(c2);
add(c3);
c1.addItemListener(this);
c2.addItemListener(this);
c3.addItemListener(this);
red = blue = green = 0;
}

public void itemStateChanged(ItemEvent ie) {


red = green = blue = 0;
UNIT 2 MCQ BY ROOMIES

if (c1.getState()) red = 255;


if (c2.getState()) green = 255;
if (c3.getState()) blue = 255;
repaint();
}

public void paint(Graphics g) {


Color c = new Color(red, green, blue);
g.setColor(c);
g.fillRect(90, 20, 100, 100);
}
}
```

Options:
1. All of the above
2. Only "Red" checkbox selected will fill the rectangle with red color.
3. Only "Green" checkbox selected will fill the rectangle with green color.
4. Only "Blue" checkbox selected will fill the rectangle with blue color.

Answer: 2. Only "Red" checkbox selected will fill the rectangle with red color.

---

59 | P a g e

180: Choose the correct output from the following options when the key is pressed.

```java
/ <applet code="SimpleKey" width=300 height=100> </applet> /
import java.awt.;
UNIT 2 MCQ BY ROOMIES

import java.awt.event.;
import java.applet.;

public class SimpleKey extends Applet implements KeyListener {


String msg = "";
int X = 10, Y = 20;

public void init() {


addKeyListener(this);
}

public void keyPressed(KeyEvent ke) {


showStatus("Key Down");
}

public void keyReleased(KeyEvent ke) {


showStatus("Key Up");
}

public void keyTyped(KeyEvent ke) {


msg += ke.getKeyChar();
repaint();
}

public void paint(Graphics g) {


g.drawString(msg, X, Y);
}
}
```

Options:
1. Key Down msg shown at the status bar
UNIT 2 MCQ BY ROOMIES

2. Key Up msg shown at the status bar


3. Key Typed msg displayed at the specified position
4. No message is displayed

Answer: 1. Key Down msg shown at the status bar

You might also like