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

Practice Test 3 2023-24 Event Handling

Uploaded by

Vijay Bande
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)
41 views

Practice Test 3 2023-24 Event Handling

Uploaded by

Vijay Bande
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/ 2

Write Correct Answer Option in Square box. 8. When the InputEvent is not generated?

a. Key is entered through keyboard


1. What is an event in delegation event model used by b. Mouse is dragged
Java Programming language? c. Mouse wheel is moved
a. An event is an object that describes a state change d. None of the above
in a source.
b. An event is an object that describes a state change 9. What is anonymous inner class?
in processing. a. An anonymous inner class is one that is not
c. An event is an object that describes any changes by assigned a name.
the user and system b. An anonymous inner class is one that is not used
d. An event is a class used for defining object, to for creating the objects
create events. c. An anonymous inner class is one for which we
can not create the object.
2. Suppose you want to have an object eh handle the d. An anonymous inner class is one that which is
TextEvent of a TextArea object t. How should you declared but not used anywhere in the program.
add eh as the event handler for t?
a. t.addTextListener(eh); 10. KeyEvent is generated in following sequence…
b. eh.addTextListener(t); a. Key typed, pressed, released
c. addTextListener(eh.t); b. Key released, typed, pressed
d. addTextListener(t,eh); c. Key pressed, typed, released
d. Key pressed, released, typed
3. Which of the following components generate action
events? 11. Till now, two models have been introduced in
a. Buttons b. Check boxes Java for
c. Labels d. Windows a. Receiving and Processing events
b. Deleting and Processing events
4. When two or more objects are added as listeners c. Receiving and Deleting events
for the same event, which listener is first invoked d. Modifying and Receiving events
to handle the event?
a. The first object that was added as listener. 12. EventObject class belongs to:
b. The last object that was added as listener. a. java.util
c. There is no way to determine which listener will b. java.awt
be invoked first. c. java.lang
d. It is impossible to have more than one listener for d. java.awt.event
a given event.
13. A source generates an event and sends it to
5. Which of these methods can be used to determine ___________ listeners that can handle the event:
the type of event? a. One b. Two
a. getID() b. getEvent() c. One or more d. None of these
c. getSource() d. getEventObject()
14. Which of these are integer constants defined in
6. Which of these methods are used to register a ActionEvent class?
mouse motion listener? a. ALT_MASK b. CTRL_MASK
a.addMouse() c. SHIFT_MASK d. All of the mentioned
b.addMouseListener()
15. Which of the following method can be used to
c.addMouseMotionListener()
obtain the coordinates of a mouse?
d.eventMouseMotionListener()
a. getPoint() b. getCoordinates()
c. getMouseXY() d. getMouseCordinates()
7. How to remove the event listener?
a. Using removeListener( ) method.
16. is superclass of Window Event class.
b. Using removeTypeListener( ) method.
a. WindowEvent b. ComponentEvent
c. Using removeEvent( ) method.
c. ItemEvent d. InputEvent
d. It is not possible to remove the event listener.
17. Choose the correct output from following option 21. Which type of the following program :
When the key is pressed. import java.awt.event.ActionEvent; import
import java.awt.*; import java.awt.event.*; import java.awt.event.ActionListener; import
java.applet.*; /*<applet code=”SimpleKey” width=300 javax.swing.*; public class OuterClass extends
height=300></applet>*/ public class SimpleKey extends JFrame { public static void main(String[] args) {
Applet implements KeyListener { String msg = ""; int X = OuterClass outer = new OuterClass(); JButton
10, Y = 20; public void init() { addKeyListener(this); } button = new JButton(“Don’t click me!”);
public void keyPressed(KeyEvent ke) { showStatus("Key button.addActionListener(new ActionListener () {
Down"); } public void keyReleased(KeyEvent ke) { public void actionPerformed(ActionEvent event) {
showStatus("Key Up"); } public void keyTyped(KeyEvent System.out.printIn(“Ouch !”); } });
ke) { msg += ke.getKeyChar(); repaint(); } public void outer.add(button); outer.pack();
paint(Graphics g) { g.drawString(msg, X, Y); } } outer.setVisible(true); } }
a. Normal Inner Class
a. "Key Down" message shown at the status bar. b. Method Local Inner Class
b. "Key Up" message shown at the status bar. c. Anonymous Inner Class
c. The typed key is displayed at coordinates (10, 20) on d. Static Inner Class
the applet.
d. All of the above. 22.Which method is missing in following program
import java.awt.*; import java.awt.event.*; import
18. Which of the following statement/statements is/are java.applet.*; /* <applet code=”MouseEventsapp”
correct? width=300 height=400></applet>*/
S1: ActionEvent: It indicates the component-defined public class MouseEventsapp extends Applet
events occurred implements MouseListener { String msg = ""; int
S2: MouseEvent: Events generated during the mouse mouseX = 0, mouseY = 0; // coordinates of mouse
operation for the object public void init() { addMouseListener(this); }
S3: FocusEvent:This class indicates about the focus public void mouseClicked(MouseEvent me) {
where the focus has gained or lost by the object. mouseX = 0; mouseY = 10; msg = "Mouse
S4: KeyEvent: It is generated When key is pressed clicked."; repaint(); } public void
mouseEntered(MouseEvent me) { mouseX = 0;
a.S2S3S4 b.S1S2S3 mouseY = 10; msg = "Mouse entered."; repaint(); }
c.S1S2S4 d.S1S2S3S4 public void mouseExited(MouseEvent me) { //
save coordinates mouseX = 0; mouseY = 10; msg =
19. Find out the Error statement "Mouse exited."; repaint(); } public void
import java.applet.*; import java.awt.event.*; /* mousePressed(MouseEvent me) { msg = "Down";
<applet code="InnerClassDemo" width=200 repaint(); } public void paint(Graphics g) {
height=100> </applet>*/ g.drawString(msg, mouseX, mouseY); } }
public class InnerClassDemo extends Applet { public a. mouseReleased()
void init() { addMouseListener(new b. mouseDragged()
MyMouseAdapter()); } class MyMouseAdapter { c. mouseMoved()
public void mousePressed(MouseEvent me) { d. mouseActivated()
showStatus("Mouse Pressed"); } } }
23.What is a listener in context to event handling?
a. The “showStatus” method must used reference for a.A listener is a variable that is notified when an
invoking. event occurs.
b. The “init” method should be declared as a public b. A listener is a 'object that is notified when an
method. event occurs.
c. The “MyMouseAdapter” class should extend c. A listener is a method that is notified when an
“MouseAdapter”. event occurs.
d. There is no error in the provided code. d. None of the mentioned

20. From given list which is not method of Mouse Listener? 24. Which Event is generated when applet window
a. mouseClicked() b. mouseDragged() is closed by user?
c. mousePressed() d. mouseEntered() a. WindowEvent b.EventWindow
c. InputEvent d. ActionEvent

You might also like