SlideShare ist ein Scribd-Unternehmen logo
1 von 41
EVENT HANDLING
BY
SANA MATEEN
Event
• What is an Event?
• Change in the state of an object is known as event i.e. event
describes the change in state of source. Events are generated
as result of user interaction with the graphical user interface
components. For example, clicking on a button, moving the
mouse, entering a character through keyboard, selecting an
item from list, scrolling the page are the activities that causes
an event to happen.
Types of Events
• The events can be broadly classified into two categories:
• Foreground Events - Those events which require the direct interaction of
user.
• They are generated as consequences of a person interacting with the
graphical components in Graphical User Interface.
• For example, clicking on a button, moving the mouse, entering a character
through keyboard,selecting an item from list, scrolling the page etc.
• Background Events - Those events that require the interaction of end user
are known as background events.
• Operating system interrupts, hardware or software failure, timer expires,
an operation completion are the example of background events.
Event Handling
• Event Handling is the mechanism that controls the event and decides what
should happen if an event occurs.
• This mechanism have the code which is known as event handler that is executed
when an event occurs.
• Java Uses the Delegation Event Model to handle the events.
• This model defines the standard mechanism to generate and handle the events.
• Let's have a brief introduction to this model.
• The Delegation Event Model has the following key participants namely:
• Source - The source is an object on which event occurs. Source is responsible for
providing information of the occurred event to it's handler.
• Java provide as with classes for source object.
• Listener - It is also known as event handler.
• Listener is responsible for generating response to an event. From java
implementation point of view the listener is also an object.
• Listener waits until it receives an event. Once the event is received , the listener
process the event an then returns..
Event Handling
• The benefit of this approach is that the user interface logic is completely
separated from the logic that generates the event.
• The user interface element is able to delegate the processing of an event
to the separate piece of code. In this model ,Listener needs to be
registered with the source object so that the listener can receive the
event notification.
• This is an efficient way of handling the event because the event
notifications are sent only to those listener that want to receive them
• The methods that receive and process events are defined in a set of
interfaces, such as those found in java.awt.event.
• 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 interface.
Steps involved in event handling
• The User clicks the button and the event is generated.
• Now the object of concerned event class is created automatically and
information about the source and the event get populated with in same
object.
 Event object is forwarded to the method of registered listener class.
• the method now gets executed and returns.
• Points to remember about listener
• In order to design a listener class we have to develop some listener
interfaces.These Listener interfaces forecast some public abstract
callback methods which must be implemented by the listener class.
• If you do not implement the any if the predefined interfaces then your
class can not act as a listener class for a source object.
Event Classes
• At the root of the Java event class hierarchy is EventObject, which is in java.util.
• It is the superclass for all events. Its one constructor is shown here:
• EventObject(Object src)
• Here, src is the object that generates this event.
• EventObject defines two methods:
• getSource( ) and toString( ).
• The getSource( ) method returns the source of the event.
• Its general form is shown here:
• 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.
• It is the superclass (either directly or indirectly) of all AWT-based events used by
the delegation event model.
• Its getID( ) method can be used to determine the type of the event.
• The signature of this method is shown here:
• int getID().
• To summarize:
• • EventObject is a superclass of all events.
• • AWTEvent is a superclass of all AWT events that are handled by the delegation
event model.
Event Listener Interfaces
• When an event occurs, the event source invokes the appropriate
method defined by the listener and provides an event object as its
argument.
ActionEvent class
• An ActionEvent is generated when a button is pressed, a list item is
double-clicked, or a menu item is selected.
• The ActionEvent class defines four integer constants that can be used to
identify any modifiers associated with an action event:
• ALT_MASK, CTRL_MASK, META_MASK, and SHIFT_MASK.
• In addition, there is an integer constant, ACTION_PERFORMED, which can
be used to identify action events.
• ActionEvent has these three constructors:
• ActionEvent(Object src, int type, String cmd)
• ActionEvent(Object src, int type, String cmd, int modifiers)
• ActionEvent(Object src, int type, String cmd, long when, int modifiers)
Here, src is a reference to the object that generated this event.
• The type of the event is specified by type, and its command string is
cmd. The argument modifiers indicates which modifier keys (alt, ctrl,
meta, and/or shift) were pressed when the event was generated. The
when parameter specifies when the event occurred.
The ActionListener Interface
• This interface defines the actionPerformed( ) method that is invoked
when an action event occurs. Its general form is shown here:
• void actionPerformed(ActionEvent ae)
The WindowEvent Class
• There are ten types of window events. The WindowEvent class defines
integer constants that can be used to identify them. The constants and
their meanings are shown here:
The AdjustmentEvent Class
• An AdjustmentEvent is generated by a scroll bar. There are five types of
adjustment events.
• The AdjustmentEvent class defines integer constants that can be used to
identify them.
• The constants and their meanings are shown here:
• BLOCK_DECREMENT The user clicked inside the scroll bar to decrease its
value.
• BLOCK_INCREMENT The user clicked inside the scroll bar to increase its
value.
• TRACK The slider was dragged.
• UNIT_DECREMENT The button at the end of the scroll bar was clicked to
decrease its value.
• UNIT_INCREMENT The button at the end of the scroll bar was clicked to
increase its value.
• In addition, there is an integer constant, ADJUSTMENT_VALUE_CHANGED,
that indicates that a change has occurred.
• Here is one AdjustmentEvent constructor:
• AdjustmentEvent(Adjustable src, int id, int type, int val)
• Here, src is a reference to the object that generated this event.
• The id specifies the event.
• The type of the adjustment is specified by type, and its associated value is
val.
• The getAdjustable( ) method returns the object that generated the event.
Its form is shown here:
• Adjustable getAdjustable( )
• The type of the adjustment event may be obtained by the
getAdjustmentType( ) method.
• It returns one of the constants defined by AdjustmentEvent.
• The general form is shown here:
• int getAdjustmentType( )
• The amount of the adjustment can be obtained from the getValue( )
method, shown here:
• int getValue( ) For example, when a scroll bar is manipulated, this method
returns the value represented by that change.
The KeyEvent Class
• A KeyEvent is generated when keyboard input occurs.
• There are three types of key events, which are identified by these integer
constants: KEY_PRESSED, KEY_RELEASED, and KEY_TYPED.
• The first two events are generated when any key is pressed or released. The last
event occurs only when a character is generated.
• Remember, not all keypresses result in characters.
• For example, pressing shift does not generate a character.
• There are many other integer constants that are defined by KeyEvent.
• For example, VK_0 through VK_9 and VK_A through VK_Z define the ASCII
equivalents of the numbers and letters. Here are some others:
• The VK constants specify virtual key codes and are independent of
any modifiers, such as control, shift, or alt.
• KeyEvent is a subclass of InputEvent.
• Here is one of its constructors:
• KeyEvent(Component src, int type, long when, int modifiers, int
code, char ch)
• Here, src is a reference to the component that generated the
event.
• The type of the event is specified by type.
• The system time at which the key was pressed is passed in when.
• modifiers argument indicates which modifiers were pressed when
this key event occurred.
• The virtual key code, such as VK_UP, VK_A, and so forth, is passed
in code.
• The character equivalent (if one exists) is passed in ch. If no valid
character exists, then ch contains CHAR_UNDEFINED.
• For KEY_TYPED events, code will contain VK_UNDEFINED.
• The KeyEvent class defines several methods, but probably the
most commonly used ones are getKeyChar( ), which returns
the character that was entered, and getKeyCode( ), which
returns the key code.
• Their general forms are shown here:
• char getKeyChar( )
• int getKeyCode( ) If no valid character is available, then
getKeyChar( ) returns CHAR_UNDEFINED. When a KEY_TYPED
event occurs, getKeyCode( ) returns VK_UNDEFINED.
The KeyListener Interface
• This interface defines three methods.
• The keyPressed( ) and keyReleased( ) methods are invoked when a key is
pressed and released, respectively.
• The keyTyped( ) method is invoked when a character has been entered.
• For example, if a user presses and releases the a key, three events are
generated in sequence: key pressed, typed, and released.
• If a user presses and releases the home key, two key events are generated
in sequence: key pressed and released.
• The general forms of these methods are shown here:
• void keyPressed(KeyEvent ke)
• void keyReleased(KeyEvent ke)
• void keyTyped(KeyEvent ke)
• The MouseEvent class defines the following integer constants that can be used to
identify them:
• MouseEvent is a subclass of InputEvent. Here is one of its constructors:
• MouseEvent(Component src, int type, long when, int modifiers, int x, int y, int
clicks, boolean triggersPopup)
• Here, src is a reference to the component that generated the event.
• The type of the event is specified by type.
• The system time at which the mouse event occurred is passed in when.
• The modifiers argument indicates which modifiers were pressed when a mouse
event occurred.
• The coordinates of the mouse are passed in x and y.
• The click count is passed in clicks.
• The triggersPopup flag indicates if this event causes a pop-up menu to appear on
this platform.
• Two commonly used methods in this class are getX( ) and getY( ).
• These return the X and Y coordinates of the mouse within the component when the
event occurred. Their forms are shown here:
• int getX( )
• int getY( )
The MouseListener Interface
• This interface defines five methods. If the mouse is pressed and released at the
same point, mouseClicked( ) is invoked.
• When the mouse enters a component, the mouseEntered( ) method is called.
• When it leaves, mouseExited( ) is called. The mousePressed( ) and mouseReleased(
) methods are invoked when the mouse is pressed and released, respectively.
• The general forms of these methods are shown here:
• void mouseClicked(MouseEvent me)
• void mouseEntered(MouseEvent me)
• void mouseExited(MouseEvent me)
• void mousePressed(MouseEvent me)
• void mouseReleased(MouseEvent me)
• The MouseMotionListener Interface This interface defines two methods.
• The mouseDragged( ) method is called multiple times as the mouse is dragged.
• The mouseMoved( ) method is called multiple times as the mouse is moved.
• void mouseDragged(MouseEvent me)
• void mouseMoved(MouseEvent me)
To handle mouse events, you must implement the MouseListener and the
MouseMotionListener interfaces.
Adapter class
• Java provides a special feature, called an adapter class, that can simplify the
creation of event handlers in certain situations.
• An adapter class provides an empty implementation of all methods in an event
listener interface.
• Adapter classes are useful when you want to receive and process only some of
the events that are handled by a particular event listener interface.
• You can define a new class to act as an event listener by extending one of the
adapter classes and implementing only those events in which you are
interested.
• For example, the MouseMotionAdapter class has two methods,
mouseDragged( ) and mouseMoved( ), which are the methods defined by the
MouseMotionListener interface.
• If you were interested in only mouse drag events, then you could simply
extend MouseMotionAdapter and override mouseDragged( ).
• The empty implementation of mouseMoved( ) would handle the mouse
motion events for you.
Inner classes
• an inner class is a class defined within another class, or even within
an expression.
• To understand the benefit provided by inner classes, consider the
applet shown in the following listing.
• It does not use an inner class. Its goal is to display the string "Mouse
Pressed" in the status bar of the applet viewer or browser when the
mouse is pressed.
• There are two top-level classes in this program. MousePressedDemo
extends Applet, and MyMouseAdapter extends MouseAdapter.
• The init( ) method of MousePressedDemo instantiates
MyMouseAdapter and provides this object as an argument to the
addMouseListener( ) method.
• Notice that a reference to the applet is supplied as an argument to
the MyMouseAdapter constructor.
• This reference is stored in an instance variable for later use by the
mousePressed( ) method.
• When the mouse is pressed, it invokes the showStatus( ) method of
the applet
Anonymous Inner Classes
• An anonymous inner class is one that is not assigned a name. This
section illustrates how an anonymous inner class can facilitate the
writing of event handlers. Consider the applet shown in the following
listing. As before, its goal is to display the string "Mouse Pressed" in
the status bar of the applet viewer or browser when the mouse is
pressed.
1. There is one top-level class in this program:
AnonymousInnerClassDemo.
2. The init( ) method calls the
addMouseListener( ) method.
3. Its argument is an expression that defines and
instantiates an anonymous inner class.
Let’s analyze this expression carefully.
1. The syntax new MouseAdapter(){...} indicates
to the compiler that the code between the
braces defines an anonymous inner class.
2. Furthermore, that class extends
MouseAdapter. This new class is not named,
but it is automatically instantiated when this
expression is executed.
3. Because this anonymous inner class is defined
within the scope of
AnonymousInnerClassDemo, it has access to
all of the variables and methods within the
scope of that class.
Therefore, it can call the showStatus( ) method
directly.
1. There is one top-level class in this program:
AnonymousInnerClassDemo.
2. The init( ) method calls the
addMouseListener( ) method.
3. Its argument is an expression that defines and
instantiates an anonymous inner class.
Let’s analyze this expression carefully.
1. The syntax new MouseAdapter(){...} indicates
to the compiler that the code between the
braces defines an anonymous inner class.
2. Furthermore, that class extends
MouseAdapter. This new class is not named,
but it is automatically instantiated when this
expression is executed.
3. Because this anonymous inner class is defined
within the scope of
AnonymousInnerClassDemo, it has access to
all of the variables and methods within the
scope of that class.
Therefore, it can call the showStatus( ) method
directly.

Weitere ähnliche Inhalte

Was ist angesagt?

Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in javaGoogle
 
Java Event Handling
Java Event HandlingJava Event Handling
Java Event HandlingShraddha
 
Java gui event
Java gui eventJava gui event
Java gui eventSoftNutx
 
GUI (graphical user interface)
GUI (graphical user interface)GUI (graphical user interface)
GUI (graphical user interface)rishi ram khanal
 
Lesson 07 Actions and Commands in WPF
Lesson 07 Actions and Commands in WPFLesson 07 Actions and Commands in WPF
Lesson 07 Actions and Commands in WPFQuang Nguyễn Bá
 
File Handling
File HandlingFile Handling
File HandlingSohanur63
 
12 High Level UI Event Handling
12 High Level UI Event Handling12 High Level UI Event Handling
12 High Level UI Event Handlingcorneliuskoo
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5sotlsoc
 
state modeling In UML
state modeling In UMLstate modeling In UML
state modeling In UMLKumar
 
C# Delegates and Event Handling
C# Delegates and Event HandlingC# Delegates and Event Handling
C# Delegates and Event HandlingJussi Pohjolainen
 
5.state diagrams
5.state diagrams5.state diagrams
5.state diagramsAPU
 
Session 12 - Overview of taps, multitouch, and gestures
Session 12 - Overview of taps, multitouch, and gestures Session 12 - Overview of taps, multitouch, and gestures
Session 12 - Overview of taps, multitouch, and gestures Vu Tran Lam
 
behavioral model (DFD & state diagram)
behavioral model (DFD & state diagram)behavioral model (DFD & state diagram)
behavioral model (DFD & state diagram)Lokesh Singrol
 

Was ist angesagt? (20)

Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
 
Event handling
Event handlingEvent handling
Event handling
 
Event handling in Java(part 1)
Event handling in Java(part 1)Event handling in Java(part 1)
Event handling in Java(part 1)
 
Java Event Handling
Java Event HandlingJava Event Handling
Java Event Handling
 
Java gui event
Java gui eventJava gui event
Java gui event
 
GUI (graphical user interface)
GUI (graphical user interface)GUI (graphical user interface)
GUI (graphical user interface)
 
Unit 6 Java
Unit 6 JavaUnit 6 Java
Unit 6 Java
 
Lesson 07 Actions and Commands in WPF
Lesson 07 Actions and Commands in WPFLesson 07 Actions and Commands in WPF
Lesson 07 Actions and Commands in WPF
 
File Handling
File HandlingFile Handling
File Handling
 
What is Event
What is EventWhat is Event
What is Event
 
12 High Level UI Event Handling
12 High Level UI Event Handling12 High Level UI Event Handling
12 High Level UI Event Handling
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
 
state modeling In UML
state modeling In UMLstate modeling In UML
state modeling In UML
 
C# Delegates and Event Handling
C# Delegates and Event HandlingC# Delegates and Event Handling
C# Delegates and Event Handling
 
5.state diagrams
5.state diagrams5.state diagrams
5.state diagrams
 
Jar chapter 4, part 1
Jar chapter 4, part 1Jar chapter 4, part 1
Jar chapter 4, part 1
 
Session 12 - Overview of taps, multitouch, and gestures
Session 12 - Overview of taps, multitouch, and gestures Session 12 - Overview of taps, multitouch, and gestures
Session 12 - Overview of taps, multitouch, and gestures
 
Trabajo de case
Trabajo de caseTrabajo de case
Trabajo de case
 
behavioral model (DFD & state diagram)
behavioral model (DFD & state diagram)behavioral model (DFD & state diagram)
behavioral model (DFD & state diagram)
 
State Diagram
State DiagramState Diagram
State Diagram
 

Andere mochten auch

Understanding layout managers
Understanding layout managersUnderstanding layout managers
Understanding layout managersNuha Noor
 
Using cookies and sessions
Using cookies and sessionsUsing cookies and sessions
Using cookies and sessionsNuha Noor
 
Jdbc in servlets
Jdbc in servletsJdbc in servlets
Jdbc in servletsNuha Noor
 
Http request and http response
Http request and http responseHttp request and http response
Http request and http responseNuha Noor
 
Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...
Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...
Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...Nuha Noor
 
Jsp elements
Jsp elementsJsp elements
Jsp elementsNuha Noor
 
Reading init param
Reading init paramReading init param
Reading init paramNuha Noor
 

Andere mochten auch (13)

Understanding layout managers
Understanding layout managersUnderstanding layout managers
Understanding layout managers
 
Using cookies and sessions
Using cookies and sessionsUsing cookies and sessions
Using cookies and sessions
 
Jdbc in servlets
Jdbc in servletsJdbc in servlets
Jdbc in servlets
 
Xml schema
Xml schemaXml schema
Xml schema
 
Http request and http response
Http request and http responseHttp request and http response
Http request and http response
 
Dom parser
Dom parserDom parser
Dom parser
 
Xml dtd
Xml dtdXml dtd
Xml dtd
 
Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...
Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...
Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...
 
Xml dom
Xml domXml dom
Xml dom
 
Intro xml
Intro xmlIntro xml
Intro xml
 
Xhtml
XhtmlXhtml
Xhtml
 
Jsp elements
Jsp elementsJsp elements
Jsp elements
 
Reading init param
Reading init paramReading init param
Reading init param
 

Ähnlich wie Events1

event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptxusvirat1805
 
PROGRAMMING IN JAVA- unit 4-part II
PROGRAMMING IN JAVA- unit 4-part IIPROGRAMMING IN JAVA- unit 4-part II
PROGRAMMING IN JAVA- unit 4-part IISivaSankari36
 
OOP Lecture 11-EventHandling1.pptx
OOP Lecture 11-EventHandling1.pptxOOP Lecture 11-EventHandling1.pptx
OOP Lecture 11-EventHandling1.pptxTanzila Kehkashan
 
Swing and Graphical User Interface in Java
Swing and Graphical User Interface in JavaSwing and Graphical User Interface in Java
Swing and Graphical User Interface in Javababak danyal
 
Unit-3 event handling
Unit-3 event handlingUnit-3 event handling
Unit-3 event handlingAmol Gaikwad
 
Asp.net event handler
Asp.net event handlerAsp.net event handler
Asp.net event handlerSireesh K
 
Event+driven+programming key+features
Event+driven+programming key+featuresEvent+driven+programming key+features
Event+driven+programming key+featuresFaisal Aziz
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptxGood657694
 
Advance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handlingAdvance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handlingPayal Dungarwal
 
ITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxudithaisur
 
Chap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptxChap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptxTadeseBeyene
 

Ähnlich wie Events1 (20)

Module 5.pptx
Module 5.pptxModule 5.pptx
Module 5.pptx
 
Module3.11.pptx
Module3.11.pptxModule3.11.pptx
Module3.11.pptx
 
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing ButtonsJAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
 
AJP key event class.pptx
AJP key event class.pptxAJP key event class.pptx
AJP key event class.pptx
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
 
AJP Event classes.pptx
AJP Event classes.pptxAJP Event classes.pptx
AJP Event classes.pptx
 
PROGRAMMING IN JAVA- unit 4-part II
PROGRAMMING IN JAVA- unit 4-part IIPROGRAMMING IN JAVA- unit 4-part II
PROGRAMMING IN JAVA- unit 4-part II
 
OOP Lecture 11-EventHandling1.pptx
OOP Lecture 11-EventHandling1.pptxOOP Lecture 11-EventHandling1.pptx
OOP Lecture 11-EventHandling1.pptx
 
Swing and Graphical User Interface in Java
Swing and Graphical User Interface in JavaSwing and Graphical User Interface in Java
Swing and Graphical User Interface in Java
 
Unit-3 event handling
Unit-3 event handlingUnit-3 event handling
Unit-3 event handling
 
Asp.net event handler
Asp.net event handlerAsp.net event handler
Asp.net event handler
 
Event+driven+programming key+features
Event+driven+programming key+featuresEvent+driven+programming key+features
Event+driven+programming key+features
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
 
EventHandling.pptx
EventHandling.pptxEventHandling.pptx
EventHandling.pptx
 
Awt event
Awt eventAwt event
Awt event
 
Advance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handlingAdvance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handling
 
ITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptx
 
Chap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptxChap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptx
 
09events
09events09events
09events
 
Event handling
Event handlingEvent handling
Event handling
 

Kürzlich hochgeladen

HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 

Kürzlich hochgeladen (20)

HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 

Events1

  • 2. Event • What is an Event? • Change in the state of an object is known as event i.e. event describes the change in state of source. Events are generated as result of user interaction with the graphical user interface components. For example, clicking on a button, moving the mouse, entering a character through keyboard, selecting an item from list, scrolling the page are the activities that causes an event to happen.
  • 3. Types of Events • The events can be broadly classified into two categories: • Foreground Events - Those events which require the direct interaction of user. • They are generated as consequences of a person interacting with the graphical components in Graphical User Interface. • For example, clicking on a button, moving the mouse, entering a character through keyboard,selecting an item from list, scrolling the page etc. • Background Events - Those events that require the interaction of end user are known as background events. • Operating system interrupts, hardware or software failure, timer expires, an operation completion are the example of background events.
  • 4. Event Handling • Event Handling is the mechanism that controls the event and decides what should happen if an event occurs. • This mechanism have the code which is known as event handler that is executed when an event occurs. • Java Uses the Delegation Event Model to handle the events. • This model defines the standard mechanism to generate and handle the events. • Let's have a brief introduction to this model. • The Delegation Event Model has the following key participants namely: • Source - The source is an object on which event occurs. Source is responsible for providing information of the occurred event to it's handler. • Java provide as with classes for source object. • Listener - It is also known as event handler. • Listener is responsible for generating response to an event. From java implementation point of view the listener is also an object. • Listener waits until it receives an event. Once the event is received , the listener process the event an then returns..
  • 5. Event Handling • The benefit of this approach is that the user interface logic is completely separated from the logic that generates the event. • The user interface element is able to delegate the processing of an event to the separate piece of code. In this model ,Listener needs to be registered with the source object so that the listener can receive the event notification. • This is an efficient way of handling the event because the event notifications are sent only to those listener that want to receive them • The methods that receive and process events are defined in a set of interfaces, such as those found in java.awt.event. • 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 interface.
  • 6. Steps involved in event handling • The User clicks the button and the event is generated. • Now the object of concerned event class is created automatically and information about the source and the event get populated with in same object.  Event object is forwarded to the method of registered listener class. • the method now gets executed and returns. • Points to remember about listener • In order to design a listener class we have to develop some listener interfaces.These Listener interfaces forecast some public abstract callback methods which must be implemented by the listener class. • If you do not implement the any if the predefined interfaces then your class can not act as a listener class for a source object.
  • 7. Event Classes • At the root of the Java event class hierarchy is EventObject, which is in java.util. • It is the superclass for all events. Its one constructor is shown here: • EventObject(Object src) • Here, src is the object that generates this event. • EventObject defines two methods: • getSource( ) and toString( ). • The getSource( ) method returns the source of the event. • Its general form is shown here: • 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. • It is the superclass (either directly or indirectly) of all AWT-based events used by the delegation event model. • Its getID( ) method can be used to determine the type of the event. • The signature of this method is shown here: • int getID(). • To summarize: • • EventObject is a superclass of all events. • • AWTEvent is a superclass of all AWT events that are handled by the delegation event model.
  • 8.
  • 9. Event Listener Interfaces • When an event occurs, the event source invokes the appropriate method defined by the listener and provides an event object as its argument.
  • 10. ActionEvent class • An ActionEvent is generated when a button is pressed, a list item is double-clicked, or a menu item is selected. • The ActionEvent class defines four integer constants that can be used to identify any modifiers associated with an action event: • ALT_MASK, CTRL_MASK, META_MASK, and SHIFT_MASK. • In addition, there is an integer constant, ACTION_PERFORMED, which can be used to identify action events. • ActionEvent has these three constructors: • ActionEvent(Object src, int type, String cmd) • ActionEvent(Object src, int type, String cmd, int modifiers) • ActionEvent(Object src, int type, String cmd, long when, int modifiers) Here, src is a reference to the object that generated this event. • The type of the event is specified by type, and its command string is cmd. The argument modifiers indicates which modifier keys (alt, ctrl, meta, and/or shift) were pressed when the event was generated. The when parameter specifies when the event occurred.
  • 11. The ActionListener Interface • This interface defines the actionPerformed( ) method that is invoked when an action event occurs. Its general form is shown here: • void actionPerformed(ActionEvent ae) The WindowEvent Class • There are ten types of window events. The WindowEvent class defines integer constants that can be used to identify them. The constants and their meanings are shown here:
  • 12.
  • 13.
  • 14. The AdjustmentEvent Class • An AdjustmentEvent is generated by a scroll bar. There are five types of adjustment events. • The AdjustmentEvent class defines integer constants that can be used to identify them. • The constants and their meanings are shown here: • BLOCK_DECREMENT The user clicked inside the scroll bar to decrease its value. • BLOCK_INCREMENT The user clicked inside the scroll bar to increase its value. • TRACK The slider was dragged. • UNIT_DECREMENT The button at the end of the scroll bar was clicked to decrease its value. • UNIT_INCREMENT The button at the end of the scroll bar was clicked to increase its value. • In addition, there is an integer constant, ADJUSTMENT_VALUE_CHANGED, that indicates that a change has occurred.
  • 15. • Here is one AdjustmentEvent constructor: • AdjustmentEvent(Adjustable src, int id, int type, int val) • Here, src is a reference to the object that generated this event. • The id specifies the event. • The type of the adjustment is specified by type, and its associated value is val. • The getAdjustable( ) method returns the object that generated the event. Its form is shown here: • Adjustable getAdjustable( ) • The type of the adjustment event may be obtained by the getAdjustmentType( ) method. • It returns one of the constants defined by AdjustmentEvent. • The general form is shown here: • int getAdjustmentType( ) • The amount of the adjustment can be obtained from the getValue( ) method, shown here: • int getValue( ) For example, when a scroll bar is manipulated, this method returns the value represented by that change.
  • 16.
  • 17.
  • 18.
  • 19. The KeyEvent Class • A KeyEvent is generated when keyboard input occurs. • There are three types of key events, which are identified by these integer constants: KEY_PRESSED, KEY_RELEASED, and KEY_TYPED. • The first two events are generated when any key is pressed or released. The last event occurs only when a character is generated. • Remember, not all keypresses result in characters. • For example, pressing shift does not generate a character. • There are many other integer constants that are defined by KeyEvent. • For example, VK_0 through VK_9 and VK_A through VK_Z define the ASCII equivalents of the numbers and letters. Here are some others:
  • 20. • The VK constants specify virtual key codes and are independent of any modifiers, such as control, shift, or alt. • KeyEvent is a subclass of InputEvent. • Here is one of its constructors: • KeyEvent(Component src, int type, long when, int modifiers, int code, char ch) • Here, src is a reference to the component that generated the event. • The type of the event is specified by type. • The system time at which the key was pressed is passed in when. • modifiers argument indicates which modifiers were pressed when this key event occurred. • The virtual key code, such as VK_UP, VK_A, and so forth, is passed in code. • The character equivalent (if one exists) is passed in ch. If no valid character exists, then ch contains CHAR_UNDEFINED.
  • 21. • For KEY_TYPED events, code will contain VK_UNDEFINED. • The KeyEvent class defines several methods, but probably the most commonly used ones are getKeyChar( ), which returns the character that was entered, and getKeyCode( ), which returns the key code. • Their general forms are shown here: • char getKeyChar( ) • int getKeyCode( ) If no valid character is available, then getKeyChar( ) returns CHAR_UNDEFINED. When a KEY_TYPED event occurs, getKeyCode( ) returns VK_UNDEFINED.
  • 22. The KeyListener Interface • This interface defines three methods. • The keyPressed( ) and keyReleased( ) methods are invoked when a key is pressed and released, respectively. • The keyTyped( ) method is invoked when a character has been entered. • For example, if a user presses and releases the a key, three events are generated in sequence: key pressed, typed, and released. • If a user presses and releases the home key, two key events are generated in sequence: key pressed and released. • The general forms of these methods are shown here: • void keyPressed(KeyEvent ke) • void keyReleased(KeyEvent ke) • void keyTyped(KeyEvent ke)
  • 23.
  • 24.
  • 25. • The MouseEvent class defines the following integer constants that can be used to identify them: • MouseEvent is a subclass of InputEvent. Here is one of its constructors: • MouseEvent(Component src, int type, long when, int modifiers, int x, int y, int clicks, boolean triggersPopup) • Here, src is a reference to the component that generated the event. • The type of the event is specified by type. • The system time at which the mouse event occurred is passed in when. • The modifiers argument indicates which modifiers were pressed when a mouse event occurred. • The coordinates of the mouse are passed in x and y. • The click count is passed in clicks. • The triggersPopup flag indicates if this event causes a pop-up menu to appear on this platform. • Two commonly used methods in this class are getX( ) and getY( ). • These return the X and Y coordinates of the mouse within the component when the event occurred. Their forms are shown here: • int getX( ) • int getY( )
  • 26. The MouseListener Interface • This interface defines five methods. If the mouse is pressed and released at the same point, mouseClicked( ) is invoked. • When the mouse enters a component, the mouseEntered( ) method is called. • When it leaves, mouseExited( ) is called. The mousePressed( ) and mouseReleased( ) methods are invoked when the mouse is pressed and released, respectively. • The general forms of these methods are shown here: • void mouseClicked(MouseEvent me) • void mouseEntered(MouseEvent me) • void mouseExited(MouseEvent me) • void mousePressed(MouseEvent me) • void mouseReleased(MouseEvent me) • The MouseMotionListener Interface This interface defines two methods. • The mouseDragged( ) method is called multiple times as the mouse is dragged. • The mouseMoved( ) method is called multiple times as the mouse is moved. • void mouseDragged(MouseEvent me) • void mouseMoved(MouseEvent me)
  • 27. To handle mouse events, you must implement the MouseListener and the MouseMotionListener interfaces.
  • 28.
  • 29.
  • 30.
  • 31. Adapter class • Java provides a special feature, called an adapter class, that can simplify the creation of event handlers in certain situations. • An adapter class provides an empty implementation of all methods in an event listener interface. • Adapter classes are useful when you want to receive and process only some of the events that are handled by a particular event listener interface. • You can define a new class to act as an event listener by extending one of the adapter classes and implementing only those events in which you are interested. • For example, the MouseMotionAdapter class has two methods, mouseDragged( ) and mouseMoved( ), which are the methods defined by the MouseMotionListener interface. • If you were interested in only mouse drag events, then you could simply extend MouseMotionAdapter and override mouseDragged( ). • The empty implementation of mouseMoved( ) would handle the mouse motion events for you.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37. Inner classes • an inner class is a class defined within another class, or even within an expression. • To understand the benefit provided by inner classes, consider the applet shown in the following listing. • It does not use an inner class. Its goal is to display the string "Mouse Pressed" in the status bar of the applet viewer or browser when the mouse is pressed. • There are two top-level classes in this program. MousePressedDemo extends Applet, and MyMouseAdapter extends MouseAdapter. • The init( ) method of MousePressedDemo instantiates MyMouseAdapter and provides this object as an argument to the addMouseListener( ) method. • Notice that a reference to the applet is supplied as an argument to the MyMouseAdapter constructor. • This reference is stored in an instance variable for later use by the mousePressed( ) method. • When the mouse is pressed, it invokes the showStatus( ) method of the applet
  • 38.
  • 39.
  • 40. Anonymous Inner Classes • An anonymous inner class is one that is not assigned a name. This section illustrates how an anonymous inner class can facilitate the writing of event handlers. Consider the applet shown in the following listing. As before, its goal is to display the string "Mouse Pressed" in the status bar of the applet viewer or browser when the mouse is pressed.
  • 41. 1. There is one top-level class in this program: AnonymousInnerClassDemo. 2. The init( ) method calls the addMouseListener( ) method. 3. Its argument is an expression that defines and instantiates an anonymous inner class. Let’s analyze this expression carefully. 1. The syntax new MouseAdapter(){...} indicates to the compiler that the code between the braces defines an anonymous inner class. 2. Furthermore, that class extends MouseAdapter. This new class is not named, but it is automatically instantiated when this expression is executed. 3. Because this anonymous inner class is defined within the scope of AnonymousInnerClassDemo, it has access to all of the variables and methods within the scope of that class. Therefore, it can call the showStatus( ) method directly. 1. There is one top-level class in this program: AnonymousInnerClassDemo. 2. The init( ) method calls the addMouseListener( ) method. 3. Its argument is an expression that defines and instantiates an anonymous inner class. Let’s analyze this expression carefully. 1. The syntax new MouseAdapter(){...} indicates to the compiler that the code between the braces defines an anonymous inner class. 2. Furthermore, that class extends MouseAdapter. This new class is not named, but it is automatically instantiated when this expression is executed. 3. Because this anonymous inner class is defined within the scope of AnonymousInnerClassDemo, it has access to all of the variables and methods within the scope of that class. Therefore, it can call the showStatus( ) method directly.