Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
24 views
33 pages
Ajp Unit 3
Uploaded by
adityakukade39
AI-enhanced title
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
Download
Save
Save AJP UNIT 3 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
24 views
33 pages
Ajp Unit 3
Uploaded by
adityakukade39
AI-enhanced title
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
Carousel Previous
Carousel Next
Download
Save
Save AJP UNIT 3 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save AJP UNIT 3 For Later
You are on page 1
/ 33
Search
Fullscreen
The a» \ _Complete Reference Contains comprehensive J Covers new features, Includes details on applets, coverage of the Java including assertions, NIO, | servlets, Swing, JavaBeans, language and libraries regular expressions, and the AWT, and collections | much more | } Z RTE @ scanned with OKEN Scanner= } Java™ 2: The Complete Reference \cdziven programs. Thus, event han explained in Chapter 19, applets are event-driven Progra handling Isat the core of successfal applet programming. Most events to which your applet will respond are generated by the user. These events are passed t0 Your applet in a vanety, of ways, with the specific method depending upon the actual event. There are several 'y8, with the specific method depending, uP snerated by the mouse, types of events, The most commonly handled events are those the keybourd, and various controls, such a8 @ push button, Events are supported by the favaawiavent pack “The chapter begins with an overview of Java’s event handling mechanism. It then, examines the main event classes and interfaces, and develops several examples that SCtnomstrate tne fundamentals of event processing. This chapter also explains how to se adapter classes inter siases, and anonymous inner classes to streamline event Ranaling code. The examples provided in the remainder of this book make frequent, tse of dese techniques. Ts chapter examines an important aspect of Java that relates to applets: events, Ag Before beginning our discussion of event handling, an important point must be made: ‘The way in which events are handled by an applet changed significantly between the original version of Java (1.0) and modern versions of Java, beginning with version 1.1 ‘The 1.0 method of event handling is still supported, but it is not recommencied for new programs. Also, many of the methods that support the old 1,0 event model have been Seprecated, The modern approach is the way that events should be handled by all new programs, including those written for Java 2, and thus is the method employed by programs in this book. Fre Delegation Event Model “The modern approach to handling events is based on the delegation vent model, whi defines standard and consistent mechanisms to generate and process event Is concept SSquite simple: a soure get snevent and sends it to one or more Istirs. inthis, ‘scheme, the listener simy its until it receives an event. Once received, the listener processes the event and then returns. The advantage ofthis ‘design is that the application IDgic dt processes events is cleanly sepatated from the user interface tonic ta gerrates thst events, A user interface element is able to “delegate” the presaseive steven S separate plece af code. ‘Tn the delagation event model, listeners must register with a source in order to receive tiaotifeation. This provides an important Genefit: Roubeationsene cent only (0 ier tht wnt receive tem Thin mov fet way to han events an he Hesign used by the old Java LO approsch. Previously. an event was hropepeted up the SoaEEument Klerarchy until twas handled by a covsponent Whe week ee eens © Scanned with OKEN Scannerforeceive events that they did not process eee el clinatee ic nt Process, and it wasted valuable time, The delegation Java also allows you to process events wit sora Ein be done by etter Sos tout using Bh deegtin cont model This tent. This techie fe discussed at the end of ‘Chapter 22. However, the delegation of Santer Aelegation coent models the preferred design for the reasons ‘The following sections define events and describe the roles of sources and listeners. Events Inthe delegation model, an evont is an object that deerbes a state change in a source ean be generated as a consequence Gf person interctng with the clement ira graphical user interface. Some of the activities that cause events to be gencrated are Frotsing a button, entering a character va the Keyboard, aclectng on teen ina at and Efcking the mouse: Many other user operations could also be eted ae examples. "Events may also occur that are not directly cused by interectons witha mee intrf0ce. For example, an event muy be generated whan a incr expires, a counter excoeds ‘elue, a eoftevare or hardware fare occurs, ran operation is completed. You ace fects define events that are appropriate for your application. Event Sources "A source is an object that generates an event, This occurs when the internal state of that object changes in soma way. Sources may generate more than one type of event. \cbsarce must register listeners in order for the listeners to receive notifications about a specific type of event, Each type of event has its own registration method. Here is the general form: public void add TypeListener(TypeListener el) ere. Tapes the name of the thevithed eae niters Ko tio at rgicaes a mone Then ewentcecur al ete Sb Th none a menting teers hat rege to cei oe inten to rogieter The general form of uch meth jatener el) Public void add TypeListener(TypeListener 6) throws java-util-TooManyListenersExcePt ion listener is called add MouseMotionListener( *ittencrs are notified and receive a copy of the event the event. In all cases, notifications are sent only to, © Scanned with OKEN ScannerG56 sava™ 2: The Complete Reference Here, Type is the name of the event and elisa reference to the event listener, When such an event occurs, the registered listener is notified. This is known as unicasting the event. TA source must slao provide # method that allows a listener to unzegister an interest ina specific type of event. The general form of such a method is this: Public void removeTypeListener(TypeListener el) Here, Type is the name of the event and el isa reference to the event listener. For example, toremove a keyboard listener, you would call removeKeyListener() “The methods that acid or remove listeners are provided by the source that generates, events. For example, the Component class provides methods to acd and remove Keyboard and mouse event listeners. Event Listeners ‘A listener is an object that is notified when an event occurs. Ithas two major requirements First, must have been registered with one or more sources to receive notifications, about specific types of events. Second, it must implement methods to receive and [Process these notifications. "The methods that receive and process events are defined in a set of interfaces found in Jaawtevent, For example, the MouseMotionListener interface defines two methods to receive notifications when the mouse is dragged or moved. Any object may receive and. process one or both of these events if it provides an implementation of this interiace Many other listener interfaces are discusted later in this and other chapters. [_Jevent Classes © ‘The classes that represent events are at the core of Java’s event handling mechanism, ‘Thus, we begin our study of event handling with a tour of the event classes. As you. will see, they provide a consistent, easy-to-use means of encapsulating evento At the root of the Java event class hierarchy is EventObject, whichis in javacutl {tis the superclass for all events. Ite one constructor is shown here! EventObject(Object sr) ‘Here, se isthe object that generates this event. "EventObject contains two methods petSource() and toString(). The getSourcet) method returns the source ofthe event ts general orm ls sheen here ee ‘Object getSource() — As expected, toString() returns the string equivalent of the event ‘The class AWTEvent, defined within the java.awt package, is a subclass of EventObject. Itis the superclass (either directly or indirectly) of all AWT-based events © Scanned with OKEN Scanner-_ es7 Chapter 20: Event Wandling | | bys delegation event modal: getID() method canbe ued to determine the LRT SaaE The ignaturc or tine Reng mat can int getDO _sdaitional details about AWTEvent are provided at the end of Chapter 22. At this "itis important to know only that all of the other classes discussed in this sec#on PRiubelasses of AWTEvent ‘To summarize: fm EventObject isa superclass ofall events, fm AWTEvent isa superclass ofall AWT events thot are handled by the delegation “The package java.awt.event defines several types of events that are generated by ‘rious ser interface elements, Table 20-1 enumerates the most important of these event {chsses and provides a brief description of when they are generated. The most commonly lied constructors and methods in each clase are described in the following sections. Description lontvent Generated when a butt is pressed, ist tem i aon double-clicked, or a menu item is selected. AdjustmentEvent Generated when a scroll bar is manipulated, Componentivent Generated when a component is hidden, moved, resized, for becomes visible, ContainerEvent Generated when a component is added to or removed from a container, Focuskvent Generated when # component gains or loses Keyboard focus. Inputevent “Abstract super class for all component input event classes. temévent Generated when a check box or list item is clicked also Sani=S when a choice selection is made or a checkable SXSnu'item is selected or deselected, fai ert ie: © Scanned with OKEN ScannerEvent Class UeeyEvent Generated when input fs received from the keyboard,
You might also like
Final Year Synopsis 1
PDF
No ratings yet
Final Year Synopsis 1
9 pages
Ajp Unit 1
PDF
No ratings yet
Ajp Unit 1
56 pages
Ajp Unit 6
PDF
No ratings yet
Ajp Unit 6
22 pages
Name of Activity Title:-IEEE 7 Upcoming Conferences Details
PDF
No ratings yet
Name of Activity Title:-IEEE 7 Upcoming Conferences Details
4 pages
Chapter 4
PDF
No ratings yet
Chapter 4
23 pages
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6458)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (648)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (1005)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4.5/5 (1856)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (650)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (582)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brené Brown
4/5 (1175)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (298)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4.5/5 (4103)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (5181)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4.5/5 (1139)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
3.5/5 (464)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (2016)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (943)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2814)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (141)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (629)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (2886)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M.L. Stedman
4.5/5 (815)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (1022)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (244)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (836)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
Little Women
From Everand
Little Women
Louisa May Alcott
4.5/5 (2369)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
3.5/5 (233)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (144)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
4/5 (278)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2289)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4372)
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1267)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1090)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (280)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
4/5 (4135)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (903)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (2033)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2546)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (78)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Toibin
3.5/5 (2141)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (919)