Chap 3
Chap 3
Event Handling
1) Which of thesepackages contains all the classes and methods required for even handling in Java?
a) java.app
let
b) java.awt
c) java.event
d) java.awt.event
a) KeyListener(
)
b) addKistener(
)
c) addKeyListener()
d) eventKeyboa
rdListener()
7) Which of these la
css is super class of all the events?
a) EventCla ss
b) EventOb ject
c) ActionEv ent
d) ItemEven t
8) Which of these
events will be notified if scroll bar is manipulated?
a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent
a) Exception Handling
b) String Handling
c) Event Handling
d) None of the above
a) Swing
b) AWT
c) Both A & B
d)None of the above
12) Which class header would be used to create an applet that accepts a click on a button?
a) ItemListener
b) ActionListener
c) MouseListener
d) WindowListener
14) Which of these methods will respond when you click any button by mouse?
a) mouseClicked()
b) mouseEntered()
c) mousePressed()
d) All of the mentioned
18) Consider the following output. Find the missing statement in the program.
a) Missing Semicolon
b) Missing {
c) Missing }
d) Missing ()
a) mousePressed(MouseEvent e){ }
b) MousePressed(MouseClick e){}
c) functionKey(KeyPress k){}
d) Added(ContainerEvent e){}
21) To process scroll bar events, you need to implement ________________ interface.
a) adjustmentlistener
b) MouseListener
c)AdjustmentListener
d) KeyListener
24) ______________ method returns a value that indicates which modifier key were pressed when the
action event is generated.
a) getModifiers()
b) setModifiers()
c) getActionCommand()
d)none of these
28) Which of the following is the highest class in the event delegation model?
a)java.util.EventListener
b) java.util.EventObject
c) java.awt.AWTEvent
d) java.awt.event.AWTEvent
31) Which of these methods can be used to obtain the coordinates of a mouse? a)getPoint()
b)getCoordinates()
c)getMouseXY()
d)getMouseCordinates()
32) Which of the following method is invoked when a window is changed from a normal to a
minimized state?
a) windowIconified()
b) windowClosed()
c)windowDeactivated
d) windowOpened()
33) Which of these is a superclass of all Adapter classes?
a)Panel
b) Applet
c) Component
d) Event
34) Which of the following method does not belongs to WindowListerner interface?
a) windowActivated
b) windowReactivated
c) windowDeiconified
d) windowClosed()
35) Which event is generating when checkable menu item is selected or deselected? a)
KeyEvent
b) ListEvent
c) ItemEvent
d) MouseEvent
36) Which are two ways to create Java Anonymous inner class?
a) Class, Interface
b) Applet
c) Panel, Frame
d)Event
37) The ___________method returns a reference to the component that was added to or removed from the
container.
a)getParent()
b)getComponent( )
c)getChild( )
d)geoReferenced()
38) Inner class can access all the members of outer class including_____data members and methods. a)
public
b)Protected
c)friend
d)private
39) In case of______ we can implement only required methods of any interface. a)adapter classes
b)Event
c)EventObject
d)Listener
45) In the following code, what is the name of the inner class?
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="AdapterDemo" width=300 height=100> </applet>
*/
public class AdapterDemo extends Applet
{ public void
init()
{
addMouseListener(new MyMouseAdapter(this));
}
}
class MyMouseAdapter extends MouseAdapter
{
AdapterDemo adapterDemo;
public MyMouseAdapter(AdapterDemo adapterDemo)
{
this.adapterDemo = adapterDemo;
} // Handle mouse clicked.
a) Mouse pressed
b) Mouse clicked
c) Mouse dragged
d) Mouse released
a)KeyListener, KeyEvent
b)MouseListener, MouseEvent
c)ActionListener, ActionEvent
d)WindowListener, WindowEvent
50) In the Delegation Event Model, a user interface element is able to delegate, the processing of an
event............................
a) class
b) a separate piece of code
c) interface
d) listener
51) Listeners are created by implementing one or more of the defined by the……………. a)
interfaces
b)class
c)listener
d)handler
53) The example of user interface elements that implement the ItemSelectable interface-
a) checkbox and checkboxgroup
b) textfield and textarea
c) radiobutton and button
d) Lists and choices
68) Which method not use to obtain the coordinates of the mouse-
a) string getcode()
b) int GetKEY()
c) int getKeyCode( )
d) int getCode()
69) Which method used to capture ALT, CTRL, META OR SHIFT keys-
a) getModifiers( )
b) getMod( )
c) modifiers ( )
d) getAlt( )
70) Which top-level class provides methods to add and remove keyboard and mouse event
listeners-
a) Container
b) Applet
c) Window
d) Component
a) Frame
b) Window
c) WindowExample
d)Example
72) Assuming we have a class which implements the ActionListener interface, which method
should be used to register this with a Button?
a) EnterActionListener(*);
b) addListener(*);
c) ActionListener(*);
d)addActionListener(*);
81) Identify correct general form of MouseClicked( ) method of Mouse Listener interface.
a) void mouseClicked(me)
b) void Clicked(MouseEvent me)
c) void mouseClicked(MouseEvent me)
d) void mouseClick(MouseEvent me)
85) Which of these method are used to register a keyboard event Listener ?
a) addMouseListener()
b) addKeyListener()
c) KeyListener()
d) addKey()
86) Which of these methods are used to register a mouse motion listener?
a) addMouseMotionListner()
b) addMouseListner()
c) addMouseWheelListner()
d) MouseMotionListner()
96) Following are the integer constants which does not belong to ComponentEvent class .
a) COMPONENT_HIDDEN
b) COMPONENT_MOVED
c) COMPONENT_RESIZED
d) COMPONENT_ICONIFIED
98) An adapter class provides an ……………..implementation of all methods in an event listener interface.
a) interface
b) abstract
c) empty
d)runnable
a) ScroolbarEvent
b) AdjustmentEvent
c) ActionEvent
d)TextAreaEvent
a) InputEvent
b) MouseMotionEvent
c) KeyEvent
d) MouseEvent
102) Listeners are created by implementing one or more of the interfaces defined by the___________
package.
a) java.awt.event
b) java.util.event
c) java.lang.event
d)java.awt.listener
105) In List event source, generates ___________ events when an item is selected or
deselected. a) action
b) item
c)text
d)window
106) In Menu Item, generates ____________ events when a menu item is selected. a) action
b) item
c) text
d)window
107) In Menu Item, generates ________ events when a checkable menu item is selected or
deselected.
a) action
b) item
c) text
d) window
f.add(l);
f.add(area);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
public void keyReleased(KeyEvent e) {
String text=area.getText();
String words[]=text.split("\\s");
l.setText("Words: "+words.length+" Characters:"+text.length());
}
a) KeyAdapterExample
b) KeyAdapter
c) KeyExample
d) AdapterExample
a) mousePressed
b) MouseAdapterExample
c) mouseClicked
d) MouseAdapter
112) When the component is added or removed ? Which of these events is generated ?
a) ComponentEvent
b) ContainerEvent
c) FocusEvent
d) InputEvent
a) Statement 2 is False
b) Statement 3 is False
c) Statement 1 is False
d) Statement 1 and 4 are False
a) addMouseListener, MouseAdapter
b) addmouselistener, MouseAdapter
c) addMouseListener, mouseAdapter
d) addMouseListener, mouseadapter
a) AdapterDemo
b) adapterDemo
c) adapterdemo
d) Adapterdemo
122) The following code segment shows that a class MyWindowAdapter extends WindowAdapter and
implements the windowClosing() method.
a) WindowAdapter, WindowEvent
b) MyWindowAdapter, WindowEvent
c) WindowAdapter, windowEvent
d) WindowEvent, WindowAdapter
a) FocusAdapter, FocusEvent
b) focusAdapter, FocusEvent
c) focusadapter, FocusEvent
d) FocusAdapter, Focusevent
a) ContainerEvent
b) ComponentEvent
c) FocusEvent
d) WindowEvent
}
public void keyPressed(KeyEvent e)
{
MyLabel.setText("Key Pressed");
}
public void keyReleased(KeyEvent e)
{
MyLabel.setText("Key Released");
}
public static void main(String[] args)
{
new KeyListenerExample();
}
}
class Outer
{ void
outerMethod() {
System.out.println("inside outerMethod");
// Inner class is local to outerMethod()
class Inner
{ void
innerMethod() {
System.out.println("inside innerMethod");
}
}
Inner y = new Inner();
y.innerMethod();
}
}
class MethodDemo
{ public static void
main(String[] args) { Outer x = new
Outer(); x.outerMethod();
}
}
133) Can outer Java classes access inner class private members?
a) Yes
b) No
134) An _______________ class listener interface and Event class Listener interface has
same name.
a) Main class
b) Adapter Class
c) Event Class
d) Inner Class
135) An adapter class provides an __________ implementation of all methods in an event listener
interface.
a) Complete
b) Multiple
c) Empty
d) None of above
136) Adapter classes are an _________ class for receiving various events.
a) Abstract class
b) Super class
c) Derived class
d) Base class
137) Which is the abstract adapter class for receiving keyboard focus events.
a) ComponentAdapter
b) KeyAdapter
c) FocusAdapter
d) MouseAdapter
c) 4
d) 2
144) Which method used to capture ALT, CTRL, META OR SHIFT keys-
a) getModifiers( )
b) getmodifiers( )
c) GetModifiers( )
d) Getmodifiers( )
145) Suppose that you want to have an object eh handle the TextEvent of a TextArea object t. How should
you add eh as the event handler for t?
a) t.addTextListener(eh);
b) eh.addTextListener(t);
c) addTextListener(eh.t);
d) addTextListener(t,eh);