Unit : 03
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
2) What is an event in delegation event model usedprogramming
by Java language?
a) An event is an object that describes a state change in a source.
b) An event is an object that describes a state change in processing.
c) An event is an object that describes any change by the user and system.
d) An event is a ss
claused for defining object, to create events.
3) Which of these methods are used to register a keyboard event listener?
a) KeyListener(
)
b) addKistener(
)
c) addKeyListener()
d) eventKeyboa
rdListener()
4) Which of these ethods
m are used to register a mouse
motion listener?
a) addMouse()
b) addMouseL istener()
c) addMouseMotionListner()
d) eventMouseMotionListener()
5) Event class is defined in which of these libraries?
a) java.io
b) java.lang
c) java.net
d) java.util
6) Which of thesemethods can be used to determine theoftype
event?
a) getID()
b) getSource()
c) getEvent()
d) getEventOb ject()
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
9) Which of these events will be generated if we close an applet’s window?
a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent
10) The Following steps are required to perform
1) Implement the Listener interface and overrides its methods
2) Register the component with the Listener
a) Exception Handling
b) String Handling
c) Event Handling
d) None of the above
11) The following specifies the advantages of
It is lightweight.
It supports pluggable look and feel.
It follows MVC (Model View Controller) architecture.
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)public class MyApplet extends Japplet implements Listener
b)public class MyApplet extends Japplet implements ActionListener
c)public class MyAppletextends Japplet implements ActionEvent
d)public class MyApplet extends Japplet implements Event
13) Select correct Listener from given option for ******.
import java.awt.*; import
java.awt.event.*;
import javax.swing.*;
public class JR extends JApplet implements ***********
{
Container c=getContentPane(); public
void init()
{
c.setLayout(new FlowLayout());
JRadioButton b1=new JRadioButton("red");
b1.addActionListener(this); c.add(b1);
JRadioButton b2=new JRadioButton("blue");
b2.addActionListener(this); c.add(b2);
JRadioButton b3=new JRadioButton("green");
b3.addActionListener(this); c.add(b3);
ButtonGroup bg=new ButtonGroup();
bg.add(b1);
bg.add(b2);
bg.add(b3); }
public void actionPerformed(ActionEvent e)
{
String str;
str=e.getActionCommand(); if(str=="red")
c.setBackground(Color.red); else
if(str=="blue")
c.setBackground(Color.blue); else
if(str=="green")
c.setBackground(Color.green);
}
}
/*<applet code=JR width=200 height=200></applet>*/
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
15) Which is the integer constants of TextEvent class?
a) TEXT_CHANGED
b) TEXT_FORMAT_CHANGED
c) TEXT_VALUE_CHANGED
d) TEXT_SIZE_CHANGED
16) MouseEvent is subclass of which of these classes?
a) ComponentEvent
b) ContainerEvent
c) ItemEvent
d) InputEvent
17) An event is generated when the internal state of the event source is_____
a) Not changed
b) Changed
c) Either changed or not
d) None of these.
18) Consider the following output. Find the missing statement in the program.
import java.awt.*; import
java.awt.event.*; import
java.applet.*; import
javax.swing.*;
/* <applet code="SimpleKey1" width=300 height=100> </applet> */ public
class SimpleKey1 extends JApplet implements KeyListener
{
String msg = ""; int
X = 10, Y = 20;
public void init()
{ addKeyListener(this);
requestFocus();
}
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);
}
}
a) Missing Semicolon
b) Missing {
c) Missing }
d) Missing ()
19) Which of the following are correct event handling methods?
a) mousePressed(MouseEvent e){ }
b) MousePressed(MouseClick e){}
c) functionKey(KeyPress k){}
d) Added(ContainerEvent e){}
20) Which methods are used to close the window?
a) setVisible(false)
b) windowClosing()
c) stop()
d) Both a and b
21) To process scroll bar events, you need to implement ________________ interface.
a) adjustmentlistener
b) MouseListener
c)AdjustmentListener
d) KeyListener
22) KeyEvent is subclass of which of these classes?
a) ComponentEvent
b) ContainerEvent
c) ItemEvent
d) InputEvent
23) _________ and _____________is a subclass of InputEvent.
a) MouseEvent, KeyEvent
b)WindowEvent,ItemEvent
c)MouseMotionEvent,MouseWheelEvent
d)ActionEvent,AdjustmentEvent
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
25) Complete the following signature:
void addTreeExpansionListener(___________________________ tel)
a) Treeexpansion listener
b) TreeExpansionListener
c) TreeListener
d) treelistener
26) Constants for AdjustmentEvent class are:
a) BLOCK_INCREMENT
b) TRACK
c) UNIT_DEVREMENT
d) all of
these
27) Which of these events will be generated if we close an applet’s window? a)ActionEvent
b)ComponentEvent
c)AdjustmentEvent
d) WindowEvent
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
29) ______ is an object that describes a state change in the source.
a) event
b) Source
c) none of the above
d) all the above
30) Which of these methods can be used to change location of an event?
a)changePoint()
b)translatePoint()
c) ChangeCordinates()
d) translateCordinates()
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
40) What is a listener in context to event handling?
a) A listener is a variable that is notified when an event occurs.
b) A listener is a object that is notified when an event occurs.
c) A listener is a method that is notified when an event occurs.
d) None of the mentioned
41) Which of the following are true?
a)The event-inheritance model has replaced the event-delegation model.
b) The event-inheritance model is more efficient than the event-delegation model.
c) The event-delegation model uses event listeners to define the methods of event-handling
classes.
d) The event-delegation model uses the handleEvent( ) method to support event handling.
42) Which of the following components generate action events?
a)Buttons
b)Labels
c)Check boxes
d) Windows
43) What is the preferred way to handle an object’s events in Java 2?
a) Override the object’s handleEvent( ) method.
b) Add one or more event listeners to handle the events.
c) Have the object override its processEvent( ) methods.
d) Have the object override its dispatchEvent( ) methods.
44) If a class MyWindowAdapter extends WindowAdapter and implements the windowClosing()
method.
How to register this class ?
a) this.addWindowListener(new MyWindowAdapter());
b) addWindowListener(new MyWindowAdapter());
c) this.addListener(new MyWindowAdapter());
d) addWindowListener(new MyAdapter());
45) In the following code, what is the name of the inner class?
public class Periodical
{
long ISBN;
public class Book
{
public long getISBN()
{
retrun ISBN;
}
}
}
a) Periodical
b) book
c) Book
d) ISBN
46) What is the output of following code?
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.
public void mouseClicked(MouseEvent me)
{
adapterDemo.showStatus("Mouse clicked");
}
}
a) Mouse pressed
b) Mouse clicked
c) Mouse dragged
d) Mouse released
47) Consider following code segment-
public void mousePressed(MouseEvent event)
{
System.out.println(event.getPoint());
}
Following code segement output is- a)
event generated
b) Print x co-ordinates
c) Display y co-ordinates
d) Print value of x and y co-ordinates
48) A general form, event registration method-
a) void addTypeListener (TypeListener el)
b) public void addTypeListener (TypeListener el)
c) public TypeListener (TypeListener el)
d) public void addTypeListener (el)
49) Identify correct methods in the place of blank space:
public class Test extends Applet implements _______________
{
String msg="";
public void init()
{
addKeyListener(this);
}
public void keyPressed(_____________ k)
{
showStatus("KeyPressed");
}
public void keyReleased(KeyEvent k)
{
showStatus("KeyRealesed");
}
public void keyTyped(KeyEvent k)
{
msg = msg+k.getKeyChar();
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg, 20, 40);
}
}
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
52) The isPopupTrigger( ) methods returns-
a)string
b)integer
c) Boolean
d)long
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
54) public void removeTypeListener(TypeListener el)
Here Type means-
a) name of the event
b) type of listener
c) name of class
d) name of object
55) The getActionCommand( ) method returns-
a)string
b)integer
c) Boolean
d)long
56) The getItem( ) method can be used...........
a) name of the method
b) type of listener
c) name of class
d) to obtain a reference to the item that changed
57) The translatePoint( ) method-
a) display x and y coordinates
b) changes the location of the event
c) name of class
d) to obtain a reference to the item that changed
58) The WindowEvent class, WINDOW_DEACTIVATED, integer constants meaning-
a) This window has lost the focus.
b) Restoring the window to its original size.
c) Reducing the window from to minimized.
d) Reducing the window from to maximized.
59) The WindowEvent class, WINDOW_ICONIFIED, integer constants meaning-
a) This window has lost the focus.
b) Restoring the window to its original size.
c) Reducing the window from to minimized.
d) Reducing the window from to maximized.
60) The WindowEvent class, WINDOW_DEICONIFIED, integer constants meaning-
a) This window has lost the focus.
b) Restoring the window to its original size.
c) Reducing the window from to minimized.
d) Reducing the window from to maximized.
61) Which are the not types of key events- a) KEY_DOUBLE
b) KEY_PRESSED
c) KEY_RELEASED
d) KEY_TYPED
62) MOUSE_WHEEL integer constants is belong to ___________- event.
a) MouseMotionEvent
b) MouseWheelEvent
c)MouseEvent
d)all of these
63) MouseWheelEvent is a subclass of_________________.
a) KeyEvent
b) MouseMotionEvent
c) MouseEvent
d) MouseWheelEvent
64) WindowEvent is a subclass of________________.
a) ComponentEvent
b) ContainerEvent
c) ActionEvent
d) AdjustmentEvent
65) Which one is not a method belong to ComponentListener Interface?
a) void componentResized(ComponentEvent ce)
b) void componentMoved(ComponentEvent ce)
c) void componentOpened(ComponentEvent ce)
d) void componentHidden(ComponentEvent ce)
66) ComponentAdded( ) and componentRemoved( ) are the methods of …………..
a)ComponentListener
b) MouseMotionEvent
c) ContainerListener
d) MouseWheelListener
67) When a component loses ___________focus, focusLost( ) is called. a)
keyboard
b)mouse
c)window
d) panel
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
71) Write the correct code at blank space:
public class ………………. extends Frame implements WindowListener
{
WindowExample()
{
addWindowListener(this);
setSize(400,400); setLayout(null);
setVisible(true);
}
public static void main(String[] args) {
new WindowExample();
}
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(*);
73) Which of these interfaces define a method actionPerformed()?
a) KeyListener
b) ButtonListener
c) InputListener
d) ActionListener
74) keyPressed() is method of …………………… interface.
a) KeyListener
b) ButtonListener
c) InputListener
d) ActionListener
75) keyReleased() is mehod of ………….. interface.
a) ActionListener
b) ButtonListener
c) InputListener
d) KeyListener
76) keyTyped() is method of………………..interface.
a) ActionListener
b) ButtonListener
c) InputListener
d) KeyListener
77) mouseClicked() is method of…………………interface.
a) MouseListener
b) ButtonListener
c) InputListener
d) KeyListener
78) mouseEntered() is method of…………………interface.
a) InputListener
b) ButtonListener
c) MouseListener
d) KeyListener
79) mouseExited() is method of…………………interface.
a) MouseListener
b) ButtonListener
c)InputListener
d) KeyListener
80) mousePressed() is method of…………………interface.
a) InputListener
b) ButtonListener
c) MouseListener
d) KeyListener
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)
82) Select the method of MouseMotionListener Interface.
a) void mouseClicked(MouseEvent me)
b) void mouseEntered(MouseEvent me)
c)void mouseExited(MouseEvent me)
d) void mouseMoved(MouseEvent me)
83) Select the method of MouseWheelListener Interface.
a) void mouseClicked(MouseWheelEvent me)
b) void mouseEntered(MouseWheelEvent t me)
c) void mouseWheelMoved(MouseWheelEvent mwe)
d) void mouseExited(MouseWheelEvent me)
84) Which of these are methods of TextListener Interface?
a) textValueChanged()
b) setText()
c) textChanged()
d) getText()
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()
87) Which of these methods are used to register a Window listener?
a) addMouseMotionListner()
b) ComponentListner()
c) WindowListener()
d) addWindowListener()
88) Which source generates adjustment events?
a) Scroll bar
b) Checkbox
c) Radio Button
d)List
89) WindowActivated() is method of……………. interface.
a) WindowListener
b) KeyListener
c) AdjustmentListener
d)ContainerListener
90) windowClosed() is method of……………. interface.
a) KeyListener
b) WindowListener
c) AdjustmentListener
d)ContainerListener
91) windowDeactivated() is method of……………. interface.
a) WindowListener
b) KeyListener
c) AdjustmentListener
d)ContainerListener
92) windowDeiconified() () is method of……………. interface.
a) WindowListener
b) KeyListener
c)AdjustmentListener
d)ContainerListener
93) windowGainedFocus() and windowLostFocus() methods are belongs to …………………interface . a)
WindowListener
b) KeyListener
c)AdjustmentListener
d) WindowFocusListener
94) windowClosed() is method of……………. interface.
a) KeyListener
b) WindowListener
c)AdjustmentListener
d)ContainerListener
95) Identify the class which is not an adapter class?
a)FocusAdapter
b)KeyAdapter
c)WindowAdapter
d)ItemAdapter
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
97) Identify correct adapter in following code:
import java.applet.*; import
java.awt.event.*;
/*
<applet code="AnonymousInnerClassDemo" width=200 height=100> </applet>
*/
public class AnonymousInnerClassDemo extends Applet
{
public void init()
{
addMouseListener(new ______________()
{
public void mousePressed(MouseEvent me)
{
showStatus("Mouse Pressed");
}
});
}
}
a) MouseAdapter
b) MouseMotion Adapter
c) KeyAdapter
d)mousepressed
98) An adapter class provides an ……………..implementation of all methods in an event listener interface.
a) interface
b) abstract
c) empty
d)runnable
99) Identify correct name of event:
public void adjustmentValueChanged(……………………. e)
{
Integer i =e.getValue();
frameLabel1.setText(i.toString());
}
a) ScroolbarEvent
b) AdjustmentEvent
c) ActionEvent
d)TextAreaEvent
100) Identify correct name of event:
public void mouseExited (________________ me)
{
// save coordinates
mouseX = 0; mouseY
= 10; msg = "Mouse
exited.";
repaint();
}
a) InputEvent
b) MouseMotionEvent
c) KeyEvent
d) MouseEvent
101) Fill correct listener names:
public class MouseEvents extends Applet implements
MouseListener, MouseMotionListener
{
String msg = "";
int mouseX = 0, mouseY = 0; // coordinates of mouse
public void init()
{
_______________ (this);
_______________ (this); }
…
}
a) addListener, addMouseListener
b) addMouseMotionListener, addKeyListener
c) MouseListener , MotionListener
d) addMouseListener, addMouseMotionListener
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
103) Identify the name of method which is not belong to WindowEvent.
a) int getOldState( )
b) int getNewState( )
c) Window OppositeWindow( )
d) Window getWindow( )
104) In List event source, generates _______events when an item is double-clicked. a)
action
b) item
c)text
d)window
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
108) Identify the correct class name:
import java.awt.*; import
java.awt.event.*;
public class ________________ extends KeyAdapter
{
Label l;
TextArea area;
Frame f;
KeyAdapterExample()
{
f=new Frame("Key Adapter");
l=new Label();
l.setBounds(20,50,200,20);
area=new TextArea();
area.setBounds(20,80,300, 300);
area.addKeyListener(this);
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());
}
public static void main(String[] args)
{
new KeyAdapterExample();
} }
a) KeyAdapterExample
b) KeyAdapter
c) KeyExample
d) AdapterExample
109) Identify the correct class name:
import java.awt.*; import
java.awt.event.*;
public class MouseAdapterExample extends MouseAdapter
{
Frame f;
MouseAdapterExample()
{
f=new Frame("Mouse Adapter");
f.addMouseListener(this);
f.setSize(300,300);
f.setLayout(null);
f.setVisible(true);
}
public void mouseClicked(MouseEvent e)
{ Graphics g=f.getGraphics();
g.setColor(Color.BLUE);
g.fillOval(e.getX(),e.getY(),30,30);
}
public static void main(String[] args)
{ new _______________();
}
}
a) mousePressed
b) MouseAdapterExample
c) mouseClicked
d) MouseAdapter
110) Which of these are integer constants defined in ActionEvent class?
a) ALT_MASK
b) CTRL_MASK
c) SHIFT_MASK
d) All of the mentioned
111) When the size of component is changed, ____________ event is generated.
a) ComponentEvent
b) ContainerEvent
c) FocusEvent
d) InputEvent
112) When the component is added or removed ? Which of these events is generated ?
a) ComponentEvent
b) ContainerEvent
c) FocusEvent
d) InputEvent
113) FocusEvent is subclass of which of these classes?
a) ComponentEvent
b) ContainerEvent
c) FocusEvent
d) InputEvent
114) Match the correct pairs-
a. getSource( ) i. Determine the type of the event
b. toString ( ) ii. Returns the source of the event
c. getID( ) iii- Constructor
d. EventObject(Object src) iv- returns the string equivalent of the event.
a) a-ii b-iv c-i d-iii
b) a-i b-iv c-ii d-iii
c) a-iii b-iv c-i d-ii
d) a-iv b-ii c-i d-iii
115) Match the correct pairs-
a. getKeyLocation() i. Set the keyCode value to indicate a physical key.
b. getKeyCode() ii. Returns the character associated with the key in this event.
c. getKeyChar() iii. Returns the location of the key that originated this key event.
d. setKeyCode(int keyCode) iv. Returns the integer keyCode associated with the key in this
event.
a) a-iii b-iv c-ii d-i
b) a-i b-iv c-ii d-iii
c) a-ii b-iv c-iii d-i
d) a-iv b-iii c-ii d-I
116) Consider following three statement
1) ActionListener Interace defines one method to receive action event
2) ItemListener Interface defines one method to recognize when the state of item change.. 3)
MouseListener interface defines mouseMoved() method
a) Statement 1 and 2 are true
b) Statement 1 and 3 are true
c) Statement 2 and 3 are true
d) All are true
117) Which of the following are true?
A) The MouseListener interface defines methods for handling mouse clicks.
B) The MouseMotionListener interface defines methods for handling mouse clicks.
C) The MouseClickListener interface defines methods for handling mouse clicks.
D) The ActionListener interface defines methods for handling the clicking of a button.
a) Statement A and D true
b) Statement A and C true
c) Statement B and D true
d) Statement C and D true
118) Which of the following statements are false
1)windowlistener define seven method
2)mouseMotionListerne define 2 method
3) ActionListener Interace defines three method to receive action event
4)KeyListener Interface define Three method
a) Statement 2 is False
b) Statement 3 is False
c) Statement 1 is False
d) Statement 1 and 4 are False
119) Consider the following code
import java.applet.*; import
java.awt.event.*;
/*
<applet code="InnerClassDemo" width=200 height=100> </applet>
*/
public class InnerClassDemo extends Applet { public
void init() {
addMouseListener(new MyMouseAdapter());
}
class MyMouseAdapter extends MouseAdapter { public
void mousePressed(MouseEvent me)
{ showStatus("Mouse Pressed");
}
}
}
a) output :Mouse Pressed
b) Error in code
c) Syntax error
d) Error in package
120) Fill in the blanks.
import java.applet.*; import
java.awt.event.*;
/*
<applet code="InnerClassDemo" width=200 height=100> </applet>
*/
public class InnerClassDemo extends Applet {
public void init() {
__________ (new MyMouseAdapter());
}
class MyMouseAdapter extends _________________
{
public void mousePressed(MouseEvent me) { showStatus("Mouse
Pressed");
}
}
}
a) addMouseListener, MouseAdapter
b) addmouselistener, MouseAdapter
c) addMouseListener, mouseAdapter
d) addMouseListener, mouseadapter
121) Fill the proper name of 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;
public MyMouseAdapter(AdapterDemo adapterDemo)
{
this.adapterDemo = adapterDemo;
}
// Handle mouse clicked.
public void mouseClicked(MouseEvent me)
{
adapterDemo.showStatus("Mouse clicked");
}
}
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.
Identify the correct adapter name and event name.
class MyWindowAdapter extends ________________
{
public void windowClosing(_____________ e)
{
System.exit(0);
}
}
a) WindowAdapter, WindowEvent
b) MyWindowAdapter, WindowEvent
c) WindowAdapter, windowEvent
d) WindowEvent, WindowAdapter
123) Identify the correct adapter name and event name.
public class MyFocusListener extends _______________
{
public void focusGained(_________________ fe)
{
Button button = (Button) fe.getSource();
label.setText(button.getLabel());
}
}
a) FocusAdapter, FocusEvent
b) focusAdapter, FocusEvent
c) focusadapter, FocusEvent
d) FocusAdapter, Focusevent
124) Identify the class which is not adapter class?
a)KeyAdapter
b)FocusAdapter
c)ItemAdapter
d)MouseMotionAdapter
125) Identify the correct event class
public void componentRemoved(____________________e)
{
displayMessage(" removed from ", e);
}
a) ContainerEvent
b) ComponentEvent
c) FocusEvent
d) WindowEvent
126) Find error in given program
import java.awt.*; import
java.awt.event.*;
public class KeyListenerExample extends Frame implements KeyListener { Label MyLAbel;
TextArea area;
KeyListenerExample()
{
MyLabel=new Label();
MyLabel.setBounds(20,50,100,20);
area=new TextArea();
area.setBounds(20,80,300, 300);
area.addKeyListener(this);
add(MyLabel);add(area);
setSize(400,400); setLayout(null);
setVisible(true);
}
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();
}
}
a) All methods of Interface are not implemented
b) Package is wrong
c) Code is correct
d) Compile time error
127) What is the output of the following java program?
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();
}
}
a) inside outerMethod inside innerMethod
b) inside
innerMethod
inside
outerMethod c)No
output
d)inside innerMethod
128) Identify the incorrect Integer constants for WindowEvent.
a)WINDOW_ACTIVATED
b)WINDOW_DEACTIVATED
c)WINDOW_LOST_FOCUS
d)WINDOW_GOT_FOCUS
129) Which source generates adjustment events?
a) Scroll bar
b) MenuItem
c) Button
d) List
130) Which of these are methods of TextListener Interface?
a) textValuechanged()
b) textvalueChanged()
c) TextValueChanged()
d) textValueChanged()
131) Generates ______________________ when the user enters a character.
a) TextEvent
b) KeyEvent
c) MouseEvent
d) ComponentEvent
132) Identify the class which is not an adapter class?
a) MouseAdapter
b) ItemAdapter
c) WindowAdapter
d) KeyAdapter
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
138) An adapter class provides an empty implementation of all methods in an __________
a) event listener interface
b) KeyListenerInterface
c) MouseListenerInterface
d) None of above
139) How many method define in FocusListener interface. a) 3
b) 5
c) 4
d) 2
140) How many method define in ContainerListener interface. a)
2
b) 1
c) 4
d) 3
141) Fill in the blank: MouseListener interface
define…........methods a) 1
b) 5
c) 4
d) 7
142) Fill in the blank: MouseMotionListener interface define…........methods a) 3
b) 4
c) 1
d) 2
143) WindowEvent is a subclass of
a) ComponentEvent
b) ContainerEvent
c) KeyEvent
d) InputEvent
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);