0% found this document useful (0 votes)
12 views14 pages

Ajp Assignment No 3

The document discusses event handling in Java, covering various types of events, listeners, and methods associated with handling user interactions. It includes questions and answers related to event delegation, mouse events, key events, and the structure of event handling classes. Additionally, it addresses the use of inner classes and the implementation of interfaces for event handling.

Uploaded by

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

Ajp Assignment No 3

The document discusses event handling in Java, covering various types of events, listeners, and methods associated with handling user interactions. It includes questions and answers related to event delegation, mouse events, key events, and the structure of event handling classes. Additionally, it addresses the use of inner classes and the implementation of interfaces for event handling.

Uploaded by

pawardiksha172
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 14
Unit: 03 Event Handli P)Which of these packages contains all the classes and methods required for even handling in Hon nt Seneca tye mesa e ae 2)What is an event in del a)An event is an object b) An event is an object ©) An event is sn wot vapors a ie change in prow mi chee nt ae oes An event isa clas bjet, to create events Jone Drtikiens) => TH meshed “ tegipters a dStenes ber oocamean four Rusboard wed NeddMousetisener) “> “This ruethod cugtstea a [nitenes ©jaddMouseMotionListner() to dokect mtoue movement walang > The EvectObfet slaw, whith & He cwot class © " No Uae d) java.util jer Which ofthese methods canbe used o determine the type of even RUS Troe. acthod” Gatien Keel p ef the eved eee ee css ban wc crc b)EventObject act option b a la Avpe class 4 ad 7H eve nt, d)ltemEven Ja Which ofthese events wl be notified scl bar is manipulated? b)ComponentEvent > wher Acvwl\bax manipilated ©)AdjustmentEvent d)WindowEvent oa when a cosaclow- exalts ‘Which of these events will be penerated onbvent = Because 43 fered b}ComponentEvent Pee e)AdjustmentEvent a) Window Event 2) Register the component with the Listener The duagle te Powars a) Exception Handi Sting Handling “gt fran digg evedds Avch od ben 6) Event Handling DNoncortheaboe Sf ham dling, ble look and L1)The following specifies the advantages oft i lightwei feel.t follows MVC (Model View Controller) archit Swing S)AWT —c)BothARB <)None ofthe above wing A a Kghtwelgtt Grol . 12) Which ld be used to create an applet that accepts a click on a button a)publie stends Japplet implements Listener’ => (AetSon [fstenek b)publi eass My Applet extends Japplet implements ActionListener § buble class My App ds Japplet implements ActionListener Fmplernented tp {public class My Appel extends Jepret implements Eve handle butten lick e-setLayout(new FlowLayout()) RadioButton b=ne Button b.addActionl istener(thi); IRadioButton b2=new JRadioButton("blue"); b2.addActionListener( e.add(b2} IRadioButton b3=new JRadioButton( b3.addActionListener(t c.add(b3)) ButtonGroup be=new ButtonGroup() be.add public void actionPerformedActionEvent e) String str strme.getActionCommand; istr="red") setBackground Colored); else if'str=="blue") e.setBackground(Color, blue); else i'str=="green") e.setBackground(Color.green); “applet code=IR width=200 height=200> Because H+ vepearetts */p eves 17)An event is generated when the internal state of the event source is a) Not changed b) Changed = > fa ed Bs ©) Either changed or not d) None of these tb. option ih Semen 18)Consider the following output, Find the missing statement in the program. import java.awt.*;import java.awtevent.* import java.applet.*:import javax. swing. * Je & coeeuct Ay ©) functionKey(KeyPress k){} 4) Added(ContainerEvent e){} methods are used to close the window? in Visible(false) i f ondow bywindowClosing) > ThA method axe umd to cloke a wh e)stop0) Both a and b To process scroll bar events, you need to implement___ interface. 4) adjustmentlistener b) Mousel. iistener MP e ee aloupocan. cedheo eis Sonp amet 3 Udfustmed Listeney, 22)KeyEvent is subclass of ‘which of these classes? a)ComponentEvent —“b)ConainerEven, cient )nputEvent sg Because “H vupourcrtt Keyboard fp evect 23) and is a subclass of InputEvent. 4) MouseEvent, KesEvent b)WindowEvent,ltemEvent > Becowe Loth one vapverrd moun ©)MouseMotionEvent, MouseWheelEvent 4)ActionEvent,AdjustmentEvent Ruyboard L 24) _— method returns a value that indicates which modifier key were pressed when theaction event is generated EON on, mod fe hoy Fhe ie Chxt ®)eetModifiers() _b) setModifiers() _¢) getActionCommand() ~ d)none of these 25)Complete the following signature: void addTreeExpansionListener a) a)Treeexpansion I i collapsing nodes d)treelistener 26)Constants for AdjustmentEvent class are: a)BLOCK_INCREMENT byTRACK, 27)Which of these events will be generated if we elose an applet’s window? a)ActionEvent si b)ComponentE:vent wees phone Farts gjAdjustmentEvent “2 JE genxct. whet appl d) WindowEvent 28)Which ofthe following is the highest clas in the event delegation model? ‘java.util. EventListener © b) java.utiLEventObject > Eyetovject & Wioyhest Alas pvaawtAWTEVent ee ) java.awt.event.AWTEvent 29) is an object that describes a state change in the source. a)event b)Source U eed — doreaiter a Arab change Sa Powe. c)none of the mie all the above 30)Which of these methods can be used to change location of an event? a)changePoint() b)transtatePoint() . a ¢) ChangeCordinates() SBecaue HY change 4he locaton d) translateCordinates() 31)Which ofthese methods can be used to obtain the coordinates of a mouse? a)getPoint() b)getCoordinates() _e)getMouseXYQ _d)getMouseC es > Becawe vehwer x &y Avoedinater 32) Which of the following method is invoked when a window is changed from a normal to a minimized state? a) windowlconified() © °c by windowClosed() > Because it frwoked when a afindow & c)windowDeactivated mintmiaed . d) windowOpened() AD) Which of these is a superclass of all Adapter classes? a)Panel b) Applet Cae dyEvent > Beco optfond x a Auvperclard 34) Which of the following method does not belongs to Window istemner interface? ‘a)window Activated b) windowReactivated > Zk Goerrt ~belong +o, ©) windowDeiconified ia) 4) windowClosed() 35)Which event is generating when checkable menu item is selected or deselected? eltemEvent a)MouseEvent jstEvent ayKeyEvent —byListEven an ra Java Anonymous inner class? +36) Which are wo ways to create Class, Interface 9 id both. ane SBecoux i con be Anece ‘¢) Panel, Frame: ayEvent 37) The method returns a reference 0 the component that was added to or removed from the container. ; ‘b)getComponent( ) eygetChild(), d)geoReferenced() Pas cs A rioraine Se outvans vee tote 38) ner class can aces al the members of outer class ineloding__4at@ members an ‘methods. a) public b)Protected e)fiiend ayprivate Per cpceaue Innux clans con acter to all the member of evter 39) In case of__ we can implement only required methods of any interface. Aes, ayndapter lasses bye vent CjEventObject Listener > Becaue th allows to Smplemerd . 440) What is listener in context to event handling! aA listener isa variable that is notified when an event occurs, yA listener isa object that is notified when an event oceurs. ©) A listener isa method that is notified when an event occurs. GNoncoftiemenioned “> Q.(Becaune tH (eaten “oa eee 41)Which of the following are true? to specthic euvedta. a)The eventinheritance model has replaced the event-delegation model. 1b) The event-inheritance model is more efficient than the event-delegation model ) The event-delegation model uses event listeners to define the methods of event- handling class {) The event-delegation model yses the handleEvent() method to support event handling, S Becous TH uner Mane to hanclle ever ex 2 42) Which of the following components generate action events? a)Buttons —_b)Labels ‘c)Check boxes d) Windows > Bottonrs only con “genexcde action exec 43) What is the preferred way to handle an object’s events in Java 2? 8) Override the object's handleEvent() method. }) Add one or more event listeners to handle the events. ¢) Have the object override its processEvent() methods Fee ee taps at) mths TS AAcdune Ht -poujewad to hoadle excl by adeting 44) If'a class My WindowAdapter extends WindowAdapter and implements the uot 1 windowClosing() method. How to register this class ? Ena oy a) this.addWindowListener(new My WindowAdapter(); ‘b) addWindowListener(new MyWindowAdapter(); ©) thisaaddListener(new MyWindowAdapter(); . 4) addWindowListener(new MyAdapter)); elie ae oS ed \ Huyuoir apter . 45)In the following code, what is the name of the inner class? | | t public long getISBNO) t retrun ISBN; 1 } Periodical b) book ©)Book d)ISBN 46)What is the output of following code? impor java.awt. import java awtevent.*; impor java.applet.*; a " public class AdapterDemo extends Applet t public void init() ‘ addMouseListener(new MyMouseAdapter(this)); } }class MyMouseAdapter extends MouseAdapter { AdapterDemo adapterDemo; public MyMouseA dapter(AdapterDemo adapterDemo) t this.adapterDemo = adapterDemo; } // Handle mouse clicked. public void mouseClicked(MouseE-vent me) t adapterDemo.showStatus("Mouse clicked”); 3 y ‘a)Mouse pressed __b)Mouse clicked ——_)Mouse dragged )Mouse released 47)Consider following code segment- eae void mousePressed(MouseEvent event) Soon printin(event.getPoint(); b) Prints coordinates: 4) Print value of 8 and ries 48)A general form, event registration method- ‘a) void addTypel istener (TypeListener el) 1) public void add Type istener (HypeListener e) Py Mlote TypeListener (TypeListenerel) TRA Apuract Jooun &) public void addTypel istener (el) 2 pate an Veagister {49)ldemtfy correct methods in the place of blank space: pubic class Test extends Applet implements _ ( String msg’ public void init() i addKeyListener(this); 3 public void keyPressed(_ ky showStatus("KeyPressed"); ‘public void keyReleased(KeyEvent k) showStatus("KeyRealesed”): ) public void keyyped(KeyEvent k) ( msg = msgtk.getKeyChar(); repaint(); public void paint(Graphies 8) { g.drawString(msg, 20, 40); i ) a)KeyListener, KeyEvent byMouseL istener, Mousel:vent )ActionListener, ActionEvent a)WindowListener, Window vent 50) In the Delegation Event Mosel use interface element is able to delegate, the processing of aN EVER nnn come a) class b) a separate piece of code interface, d) listener 451) Listeners are created by implementing one or more of the defined by the. ‘a)interfaces bjclass —_eplistenets handler i ee a ot by hae a)string bjinteger ©) Boolean. long . SBecuuse Hc a matnod to Uckuer option c. 53) The example of user interface elements that implement the ItemSelectable interface- a)checkbox and cheekboxgroup bjextfield and textarea e Salcbuton and button “>Becaune option dl we Zan 4) Lists and choices He tom, 54) public void removeTypeListener( TypeListener el)Here Type means- a)name of the event Jjiype of listener ‘Trees Secu In types we can chotead He et he Ragboord / moune hiatenen etAetionCommand ) method returns Dpinteger «) Bootean tong > Ubove maroc vatuans Atoing 56) The gettem( ) method can be used par of thenchoe 1) pe of listener }nameof class 4) to obtain a refer )name of obj “3 Uvove mutttodl urea option el ce to the item that changed 57) The-translatePoint( ) method eee SS UWbore mathod ures Option b- b) changes the location of the event i co) name of class to change locodion 4) to obtain a reference to the item that changed 58) The Window Event class, WINDOW_DEACTIVATED, in a) This window has lost the focus. bb) Restoring the window to its original size, —>Becewupe windows DEACTIVATED, ei indian rn to minimized mana winded loAd er constants meaning: 59) The WindowEvent class, WINDOW_ICONIFIED, integer constanis meanin, A This window bslowihe ows. | 5 ewNDOW - 1COWIFIED means b) Restoring the w 3 A ©) Reducing the window from to minimized, window méirimi 4d) Reducing the window from to maximized 60) The WindowEvemt class, WINDOW _DEICONIFIED, integer constants meaning a) This window has lost the focus. b) Restoring the window to its original size> COIN Dow . DEICONIFIED mean © Reducing the window from to minimized °, Bese Ven rn punts vastooe from window ; minimtaed 61) Which are the not types of key events- a) KEY_DOUBLE > Key-Dovsre ts alid, 62)MOUSE_WHEEL integer constants is belong to_ _ oe srectavarstad > uoudt WHEEL prsbant Woux Bed c)MouseF vent Gall of these 63)MouseWheelEvent isa subclass of i aKeyEvent ——_b)MouseMotionf:vent @)MouseEvent —_d)MouseWheelEvent > Becaure 14 vupound HousecBed 64)Window Event is a subclass of __ 2)ComponentE vent DXContainertvent) a ecaune % handles evoth vuloded +o ©)ActionEvent A)AdjustmentEvent Aomponert Vike ufndow 4) void componentResized(ComponeniE venice) St WH not a metho D)raicomponndincdComponentnence) > BECCA J. 66)ComponentAdded( ) and componentRemoved( ) are the methods of a)ComponentListener b)MouseMotionEven > Becaune “+ horcleo changes G % Lomponart ©) ContainerListener a contafen 4) MouseWheelListener within 67)When a component loses focus.focusLost( js calle. a) keyboard bymouse > Because wher Aomp overt leer. window 4) panel 68)Which method not use to obtain the coordinates of the mouse- a)string getcode() bint GetKEY() ed int getKeyCode( ) dim getCode() 69)Which method used to capture ALT, CTRL, META OR SHIFT keys- a)getModifiers( ) b)getModc ) Becoure ured to fapture Feeys : emodifies() d) getAlt( ) Bric 1op-level class provides methods to Bre methods to add and remove keyboard and mouse event ycontainer b)Applet Window d) aaa * ve public class extends Frame implements WindowL istener WindowExample() add Window Liste setSize(400.400) setLayout(mull) setVisible(true) public static void main(String| new Window Example) a)Frame byWindow )Window Example dyExample 72)Assuming we have a class which imp! cements the ActionListener interface, which method should be used to register this with a Button? ayEnterActionlistener(*) b) addListener . 3 Qaetintistenery > optien d & cwoyack method aad ActionListener(*): 73)Which of these interfaces define a)KeyListener wee 4 ‘b)ButtonL istener S Abo mathod w define by, option )InputListener a) ActionListener method actionPerforme 7AykeyPressedi) is method of interface a)KeyListener byButtonL ister 3 Key Poured & the method ef option a e}lnputtistener {ActionListener 75)keyReleasedt) is mehod of a)ActionListener byButtonListener ilnputlistener = Key Releasecl fo the melfoct of sphend )KeyListener interface 76)keyTyped() is method of interface a)ActionListener byButtonListener e)InputListener yyListener > hey Fred anymouseClicked) is method Of. )MouseL stem FpvienLsieer Be ee lich ba mebod gf 9 ‘c)InputListener d)KeyListener 78)mouseEntered() is method OfnecgesapessderneeneentIMtOPFBCe. dt Sf ‘a)Inputl istener Ps onal aor = Sole Erlend “U5 itod aplenc, ‘)MouseListener d)KeyListener 79)mouseExited() is method of. interface MouseListener 6) ButtonLis Spasms, @ Keabiseny a G)MoweLsener DBsTonLNeag: SNOUT cl of eptina. 80)mousePressed() is method o. ierface a)inputListener IyButtonListener on )MouseListener > Becaure Ht Lovvuct gewol mathod AKeyListener Joa _optfone a) demtify correct general form of MouseClicked() method of Mouse Listener interface avoid mouseClickedime) a ws i Pyvoid Clicked(MouseEvent me) Pec 48 soo Ppedmacclvei(owetient me) 2 Jom {void mouseClick(MouseEvent me) Joon '82)Select the method of MouseMotionL istener Interface. avoid mouseC licked MouseE-vent me) ae PR MecNCSIMGsecved ms) tote Because Tt Sy gold mouseEited( Mouse vent me) ie Syvoid moseMovedoue¥vent me) Asovec method 83)Select the method of Mouse Wheel istener Interface. a" 2) void mouseClicked(MouseWheelEvent me) ; ee OP. cl Pe ememeciMouseWhedeven me >, UousetD » {6 Void mouseWheelMoved(MouseWheelEvent me) mithot gf optoae €) void mouseExited(MouseWheelEvent me) 84)Which of these are methods of TextListener Interface? ‘a)textValueChanged() byseText() STut itera 2 (part -f options )textChanged() d) getText() 85)Which of these method are used to register a keyboard event Li ajaddMousel istener() b)addKeyListener() o)KeyListener() daddKey(), > his serait, Ao vugiter Wat Rigbcard 8, atenw : 86)Which of these methods are used t)addMonseNotonListner) biaddMouse c)addMouseW Listner —Pecawe sawn Sell bar . Dycheckton we con charge Hu Aas Rao Bat a - hod 6 : > whdou ued t ma { y op! 1 Hy Window Listener qe pConaier ten 25) ldentty the cl ; VU nS a)FocusAdapter ‘byKeyAdapter re an adaphi Aas ananiner > an dap, ® oh oP d)ltemAdapter 46) Following are the integer constants which does not belong to Component Event class 2) COMPONENT HIDDEN b)COMPONENT MOVED = (pepo noth saat slams not Ueeng ou ©) COMPONENT RESIZED P d)COMPONENT_ICONIFIED hates option d ‘7)ldemify correct adapter in following code import javaapplet.* import java.awt.event.* applet code="AnonymousinnerClassDemo” width=200 height=100: applet public class AnonymousinnerClassDemo extends Apple public void addMouseListener(new ) public void mousePressed(MouseEvent me) showStatus("Mouse Pressed!” a)MouseAdapter b)MouseMotion Adapter e)KeyAdapter Aymbusepressed 98)An adapter class provide implementation of all methods in an event listener interface a)interface —bJabstrac jempty runnable 99)ldentity correct poole ee aa JueChanged( e to atl methods rameL abel .setTFext(isoString a)ScroolbarE vent b)AdjustmentEvent ©)ActionEvent d)TextAreaEvent LMA gr o > > Un adapter slams (Durovioles epifenc

You might also like