SlideShare uma empresa Scribd logo
1 de 51
Agenda
   Introduction
   C# Event Processing Macro View
   Required Components
   Role of Each Component
   How To Create Each Type Of Component
Introduction
   C# is a modern programming language supported
    by an extensive set of API structures and classes.
     i.e., The .Net Framework
   C# supports event-driven programming normally
    associated with Microsoft Windows applications.
   One normally thinks of events as being generated
    by GUI components
     …but any object can generate an “event” if it’s
      programmed to do so…
C# Event Processing Macro
View
   Generally speaking, two logical components are
    required to implement the event processing model:
     1) An event producer (or publisher)
     2) An event consumer (or subscriber)
   Each logical components has assigned
    responsibilities
   Consider the following diagram
C# Event Processing Macro
  View
 When an Event occurs                        Object B processes the
 notification is sent to all                 event notification in its
 the subscribers on the list                 event handler code
 for that particular event…



            Object A                        Object B
            (Event Publisher)            (Event Subscriber)

         Subscriber List                   Event Handler Code
           (Object B)




 Object A maintains a               Object B subscribes to event
 list of subscribers for         (or events) generated by Object A.
each publishable event
C# Event Processing Macro
   View
   When a Click event occurs
   notification is sent to all
   the subscribers on the
   list…


                    Button                MainApp
                   (Event Publisher)
                                        (Event Subscriber)

             Subscriber List
         (MainApp.onButtonClick)         onButtonClick




Button maintains a list
 of subscribers of its
     Click event
C# Event Processing Macro
View
   These two diagrams hide a lot of details
     How is the subscriber list maintained?
     How is the event generated?
     How is notification sent to each subscriber?
     What is an event – really?
     How can you add custom event processing to
      your programs?
   This presentation attempts to answer these
    questions in a clear manner…
C# Event Processing Macro
View
 The .Net API contains lots of classes that
  generate different types of events…
   Most are GUI related
     ○ Can you think of a few?
 It also contains lots of Delegates
   Can you name at least one?
 Let’s take a closer look at the C# event
  processing model
C# Event Processing Macro
View
    To implement custom event processing in your
     programs you need to understand how to create
     the following component types:
      Delegates
      Event Generating Objects (publishers)
       ○ Events
       ○ Event Notification Methods
      Event Handling Objects (subscribers)
       ○ Event Handler Methods
Required Components
   To implement custom event processing in your
    programs you need to understand how to create
    the following component types:
     Delegates
     Event Generating Objects (publishers)
      ○ Events
      ○ Event Notification Methods
     Event Handling Objects (subscribers)
      ○ Event Handler Methods
Role of Each Component
- Delegate -

   Delegate
     Delegate types represent references to methods
      with a particular parameter list and return type
      ○ Example
         EventHandler(Object sender, EventArgs e)
         Represents a method that has two parameters, the
          first one being of type Object and the second being
          of type EventArgs. Its return type is void.
         Any method, so long as its signature matches that
          expected by the delegate, can be handled by the
          delegate.
Role of Each Component
- Delegate -

   But just what is a delegate?
     A delegate is a reference type object.
     A delegate extends either the System.Delegate
      or MulticastDelegate class
      ○ Depends on whether one (Delegate) or more
        (MulticaseDelegate) subscribers are involved
     You do not extend Delegate or
      MulticastDelegate
      ○ The C# compiler does it for you
Role of Each Component
- Delegate -

   The delegate object contains the
    subscriber list.
     It is actually implemented as a linked list where
      each node of the list contains a pointer to a
      subscriber’s event handler method
   Delegates are types – like classes
     Except – you declare them with the delegate
      keyword and specify the types of methods they
      can reference
Role of Each Component
- Publisher -

   A publisher is any class that can fire an event and
    send event notifications to interested subscribers
   A publisher class contains the following critical
    elements:
     An event field
      ○ This is what subscribers subscribe to…
     An event notification method
      ○ This   activates the subscriber notification
         process when the event occurs
Role of Each Component
- Subscriber -

   A subscriber is a class that registers its interest in
    a publisher’s events
   A subscriber class contains one or more event
    handler methods
-   Event Handler Method –
   An event handler methods is an ordinary method
    that is registered with a publisher’s event.
   The event handler method’s signature must match
    the signature required by the publisher’s event
    delegate.
Role of Each Component
- Event -

   An event is a field in a class
   Events are declared with the event keyword
   Events must be a delegate type
     Delegates, remember, are objects that contain a list of
      pointers to subscriber methods that delegate can process
   An event field will be null until the first subscriber
    subscribes to that event
Role of Each Component
- Event Notification Method -
   In addition to an event field a publisher will have a
    method whose job is to start the subscriber
    notification process when the event occurs
     An event notification method is just a normal method
     It usually has a parameter of EventArgs or a user-defined
      subtype of EventArgs.
      ○ But it can have any number and type of parameters as
        required.
An Custom Event Example
- Elapsed Minute Timer -
   This example includes five separate source files:
     Delegate.cs
     Publisher.cs
     Subscriber.cs
     MinuteEventArgs.cs
     MainApp.cs
using System;

namespace CustomEventExample {
   public delegate void ElapsedMinuteEventHandler(Object sender, MinuteEventArgs
e);
} // end CustomEventExample namespace


using System;
namespace CustomEventExample {
  public class MinuteEventArgs : EventArgs {
   private DateTime date_time;
       public MinuteEventArgs(DateTime date_time){
     this.date_time = date_time;
   }

        public int Minute {
         get { return date_time.Minute; }

        }
    }
}
using System;

namespace CustomEventExample {

 public class Publisher {

   public event
ElapsedMinuteEventHandler MinuteTick;
   public Publisher(){

     Console.WriteLine("Publisher
Created");
   }
public void countMinutes(){
     int current_minute = DateTime.Now.Minute;
     while(true){
       if(current_minute != DateTime.Now.Minute){
          Console.WriteLine("Publisher:
{0}", DateTime.Now.Minute);
          onMinuteTick(new
MinuteEventArgs(DateTime.Now));
          current_minute = DateTime.Now.Minute;
       }//end if
     } // end while
   } // end countMinutes method



     public void onMinuteTick(MinuteEventArgs e){
        if(MinuteTick != null){
           MinuteTick(this, e);
         }
     }// end onMinuteTick method
  } // end Publisher class definition
} // end CustomEventExample namespace
using System;

namespace CustomEventExample {

 public class Subscriber {

  private Publisher publisher;

  public Subscriber(Publisher publisher){
    this.publisher = publisher;
    subscribeToPublisher();
    Console.WriteLine("Subscriber Created");
  }

  public void subscribeToPublisher(){
    publisher.MinuteTick += new ElapsedMinuteEventHandler(minuteTickHandler);
  }

  public void minuteTickHandler(Object sender, MinuteEventArgs e){
   Console.WriteLine("Subscriber Handler Method: {0}", e.Minute);

    }
   } // end Subscriber class definition
} // end CustomEventExample namespace
using System;

namespace CustomEventExample {

 public class MainApp {
 public static void Main(){
  Console.WriteLine("Custom Events are Cool!");

  Publisher p = new Publisher();
  Subscriber s = new Subscriber(p);
  p.countMinutes();

   } // end main
  } //end MainApp class definition
} // end CustomEventExample namespace
OUTPUT
AGENDA

 The Delegation Event model
 Event Listeners
 Event Classes
 Event Listener Interfaces
 Anonymous Inner Classes
 Examples
The Delegation Event
              Model
    The concept of Delegation Event model is

   A source generates an event and sends it to one or
    more listeners.
   The listener simply waits until it receives an event. Once
    an event is received, the listener processes events and
    then returns.
   Listeners must register with a source in order to receive
    an event notification.
Event Handling Model of
        AWT
                Event object
                • Event handling objects




                                      Event handling
                                      methods


 Event source        Event listener
 • Button            • Methods
 • Textbox
 • Etc.,
Events
o   An event is an object that describes a state
    change in a source.

o   Events are generated by
            • Pressing a button
            • Entering a character via the keyboard
            • Selecting an item in a list
            • Clicking the mouse
            • And so on…………..
Event Sources

o   A source is an object that generates an event.
o   A source must register listeners.

General form

     public void addTypeListener(TypeListener el)
     public void removeTypeListener(TypeListener el)



          Type - name of the event.
          el   - reference to the event listener.
Event Listeners
o   A listener is an object that is notified when an event
    occurs.

o   Two Requirements :
   It must have been registered with one or more sources to
    receive notifications.
   It must implement methods to receive and process these
    notifications.
EventObject
o   The root of the java event class hierarchy is
    EventObject, which is in java.util.
o   It is the super class of all the events.

 Two methods:
o getsource() - returns the source of the event.
o toString()   - returns the string equivalent of
  the event.
AWTEvent class

o   Defined within the java.awt package.
o   Subclass of EventObject
o   Superclass of all AWT-based events that are handled by
    the delegation event model.
Java.awt.event
      Event class                         Description

Action Event          Generated when a button is pressed,a list item is
                      double-clicked, or a menu item is selected.


AdjustmentEvent       Generated when a scroll bar is manipulated.


ComponentEvent        Generated when a component is hidden,
                      moved,resized, or becomes visible.


ContainerEvent        Generated when a component is added to or
                      removed from a container.

FocusEvent            Generated when a component gains or loses
                      keyboard focus.
Event class                        Description


InputEvent         Abstract superclass for all component input event
                   classes.

ItemEvent          Generated when a check box or list item is clicked;
                   also occurs when a choice selection is made or a
                   checkable menu item is selected or deselected.

KeyEvent           Generated when input is received from the keyboard.

MouseEvent         Generated when the mouse is dragged, moved,
                   clicked, pressed, or released; also generated when
                   the mouse enters or exits a component.

MousewheelEvent    Generated when the mouse wheel is moved.

TextEvent          Generated when the value of a text area or text field
                   is changed.

WindowEvent        Generated when a window is activated,closed,
                   deactivated, deiconified, iconified, opened or quit.
Event Listener Interfaces
   The ActionListener Interface
             void actionPerformed(ActionEvent ae)

   The AdjustmentListener Interface
              void adjustmentValueChanged(AdjustmentEvent ae)

   The ComponentListener Interface
            void componentResized(ComponentEvent ae)
            void componentMoved(ComponentEvent ae)
            void componentShown(ComponentEvent ae)
            void componentHidden(ComponentEvent ae)
   The ContainerListener Interface
              void componentAdded(ContainerEvent ae)
               void componentRemoved(ContainerEvent ae)

   The FocusListener Interface
               void focusGained(FocusEvent fe)
               void focusLost(FocusEvent fe)

   The ItemListener Interface
                 void itemStateChanged(ItemEvent ie)

   The KeyListener Interface
                 void KeyPressed(KeyEvent ke)
                 void KeyReleased(KeyEvent ke)
                  void KeyTyped(KeyEvent ke)
   The MouseListener Interface
               void mouseClicked(MouseEvent me)
               void mouseEntered(MouseEvent me)
               void mouseExited(MouseEvent me)
               void mousePressed(MouseEvent me)
               void mouseReleased(MouseEvent me)

   The MouseMotionListener Interface
               void mouseDragged(MouseEvent me)
               void mouseMoved(mouseEvent me)

   The MouseWheelListener Interface
               void mouseWheelMoved(MouseWheelEvent mwe)
   The TextListener Interface
              void textChanged(TextEvent te)

   The WindowFocusListener Interface
             void windowGainedFocus(WindowEvent we)
             void windowLostFocus(WindowEvent we)

   The WindowListener Interface
             void windowActivated(WindowEvent we)
             void windowClosed(WindowEvent we)
             void windowClosing(WindowEvent we)
             void windowDeactivated(WindowEvent we)
             void windowDeiconified(WindowEvent we)
             void windowIconified(WindowEvent we)
             void windowOpened(WindowEvent we)
Anonymous Inner Classes
Import java.applet.*;
Import java.awt.event.*;
Public class AnonymousInnerClassDemo extends Applet
{
    public void init()
    {
       addMouseListener(new MouseAdapter()
       {
               public void mousePressed(MouseEvent me) {
                       showStatus(“Mouse Pressed”); }
       });
} }
Handling Mouse Events
 import java.awt.*;
 import java.awt.event.*;
 import java.applet.*;
 public class MouseEvents extends Applet
          implements MouseListener,MouseMotionListener
{
   String msg = “ “;
    int mouseX=0, mouseY=0;
    public void init()
     {
               addMouseListener(this);
               addMouseMotionListener(this);
       }
public void mouseClicked(MouseEvent me)
 {
       mouseX=0;
       mouseY=10;
       msg = “Mouse clicked”;
       repaint();
}
 public void mouseEntered(MouseEvent me)
{
        mouseX=0;
       mouseY=10;
       msg = “Mouse Entered”;
       repaint();
}
public void mouseDragged(MouseEvent me)
{
       mouseX= me.getX();
       mouseY=me.getY();
       msg=“ * “;
       showStatus(“ Dragging mouse at “+ mouseX +
   “mouseY” +mouseY);
       repaint();
}
 public void paint(Graphics g)
{
   g.drawString(msg,mouseX,mouseY);
}
}
DIFFERENCES WITH JAVA & C#

1. Differences in terms of syntax of Java
   and C#
2. Modification of concepts in C# that
   already exist in Java
3. Language features and concepts that
   do not exist in Java at all.
Differences in terms of Syntax

                 JAVA MAIN vs C#
                  MAIN
Java:
public static void main(String[]
 args)

C#:
static void Main(string[] args)
 string is shorthand for the System.String class in C#.
  Another interesting point is that in C#, your Main method
  can actually be declared to be parameter -less
static void Main()
Differences in terms of Syntax

           PRINT STATEMENTS

Java:
System.out.println("Hello world!");
 C#:
 System.Console.WriteLine("Hello
  world!");
 or
 Console.WriteLine("Hello again!");
Differences in terms of Syntax
   DECLARING CONSTANTS

Java:
 In Java, compile-time constant values are declared inside a
  class as

static final int K = 100;

C#:
 To declare constants in C# the const keyword is used for
  compile time constants while the readonly keyword is used for
  runtime constants. The semantics of constant primitives and
  object references in C# is the same as in Java.

const int K = 100;
Modified concepts from
Java
               IMPORTING LIBRARIES
 Both the langugaes support this functionality
  and C# follows Java’s technique for importing
  libraries:

 C#: using keyword
 using System;
 using System.IO;
 using System.Reflection ;



 Java: import keyword
 import java.util .*;
 import java.io.*;
Enumerations
 Java's lack of enumerated types leads to the use of
  integers in situations that do not guarantee type
  safety.
 C# code:
 public enum Direction {North=1, East=2, West=4, South=8};
 Usage:
 D i r e c t io n w a l l = D i r e c t i o n. No rt h;

 Java equivalent code will be:
 public class Direction {
          public final static int                NORTH = 1;
          public final static int                EAST = 2;
          public final static int                WEST = 3;
          public final static int                SOUTH = 4;
 }
 Usage:
 i n t w a l l = D i r e c t i o n . NO RT H;
Reference
   The complete Reference, Java2, Fifth edition.

Websites:
 Java vs. C#: Code to Code Comparison
  http://www.javacamp.org/javavscsharp/
 A Comparative Overview of C#:
  http://genamics.com/developer/csharp_comparativ
  e.htm
THANK YOU…….

Mais conteúdo relacionado

Mais procurados

Java eventhandling
Java eventhandlingJava eventhandling
Java eventhandlingArati Gadgil
 
Event handling
Event handlingEvent handling
Event handlingswapnac12
 
Event handling63
Event handling63Event handling63
Event handling63myrajendra
 
tL20 event handling
tL20 event handlingtL20 event handling
tL20 event handlingteach4uin
 
Event Handling in Java
Event Handling in JavaEvent Handling in Java
Event Handling in JavaAyesha Kanwal
 
Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2PRN USM
 
Advance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handlingAdvance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handlingPayal Dungarwal
 

Mais procurados (8)

Java eventhandling
Java eventhandlingJava eventhandling
Java eventhandling
 
Event handling in Java(part 1)
Event handling in Java(part 1)Event handling in Java(part 1)
Event handling in Java(part 1)
 
Event handling
Event handlingEvent handling
Event handling
 
Event handling63
Event handling63Event handling63
Event handling63
 
tL20 event handling
tL20 event handlingtL20 event handling
tL20 event handling
 
Event Handling in Java
Event Handling in JavaEvent Handling in Java
Event Handling in Java
 
Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2
 
Advance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handlingAdvance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handling
 

Destaque

Windows Programming with AWT
Windows Programming with AWTWindows Programming with AWT
Windows Programming with AWTbackdoor
 
01 Java Is Architecture Neutral
01 Java Is Architecture Neutral01 Java Is Architecture Neutral
01 Java Is Architecture Neutralrajuglobal
 
c# events, delegates and lambdas
c# events, delegates and lambdasc# events, delegates and lambdas
c# events, delegates and lambdasFernando Galvan
 
[Development Simply Put] Events & Delegates In C# - Win Forms Controls
[Development Simply Put] Events & Delegates In C# - Win Forms Controls[Development Simply Put] Events & Delegates In C# - Win Forms Controls
[Development Simply Put] Events & Delegates In C# - Win Forms ControlsAhmed Tarek Hasan
 
12 iec t1_s1_oo_ps_session_17
12 iec t1_s1_oo_ps_session_1712 iec t1_s1_oo_ps_session_17
12 iec t1_s1_oo_ps_session_17Niit Care
 
Dbms & prog lang
Dbms & prog langDbms & prog lang
Dbms & prog langTech_MX
 
Spf chapter 03 WinForm
Spf chapter 03 WinFormSpf chapter 03 WinForm
Spf chapter 03 WinFormHock Leng PUAH
 
Integrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web siteIntegrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web siteHock Leng PUAH
 
C# Starter L06-Delegates, Event Handling and Extension Methods
C# Starter L06-Delegates, Event Handling and Extension MethodsC# Starter L06-Delegates, Event Handling and Extension Methods
C# Starter L06-Delegates, Event Handling and Extension MethodsMohammad Shaker
 
C# Delegates and Event Handling
C# Delegates and Event HandlingC# Delegates and Event Handling
C# Delegates and Event HandlingJussi Pohjolainen
 
Visual basic asp.net programming introduction
Visual basic asp.net programming introductionVisual basic asp.net programming introduction
Visual basic asp.net programming introductionHock Leng PUAH
 
Correlation
CorrelationCorrelation
CorrelationTech_MX
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notesWE-IT TUTORIALS
 

Destaque (18)

Windows Programming with AWT
Windows Programming with AWTWindows Programming with AWT
Windows Programming with AWT
 
01 Java Is Architecture Neutral
01 Java Is Architecture Neutral01 Java Is Architecture Neutral
01 Java Is Architecture Neutral
 
c# events, delegates and lambdas
c# events, delegates and lambdasc# events, delegates and lambdas
c# events, delegates and lambdas
 
[Development Simply Put] Events & Delegates In C# - Win Forms Controls
[Development Simply Put] Events & Delegates In C# - Win Forms Controls[Development Simply Put] Events & Delegates In C# - Win Forms Controls
[Development Simply Put] Events & Delegates In C# - Win Forms Controls
 
12 iec t1_s1_oo_ps_session_17
12 iec t1_s1_oo_ps_session_1712 iec t1_s1_oo_ps_session_17
12 iec t1_s1_oo_ps_session_17
 
Dbms & prog lang
Dbms & prog langDbms & prog lang
Dbms & prog lang
 
Spf chapter10 events
Spf chapter10 eventsSpf chapter10 events
Spf chapter10 events
 
Ch01
Ch01Ch01
Ch01
 
Spf chapter 03 WinForm
Spf chapter 03 WinFormSpf chapter 03 WinForm
Spf chapter 03 WinForm
 
Integrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web siteIntegrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web site
 
C# Starter L06-Delegates, Event Handling and Extension Methods
C# Starter L06-Delegates, Event Handling and Extension MethodsC# Starter L06-Delegates, Event Handling and Extension Methods
C# Starter L06-Delegates, Event Handling and Extension Methods
 
C# Delegates and Event Handling
C# Delegates and Event HandlingC# Delegates and Event Handling
C# Delegates and Event Handling
 
Intro++ to C#
Intro++ to C#Intro++ to C#
Intro++ to C#
 
Windowforms controls c#
Windowforms controls c#Windowforms controls c#
Windowforms controls c#
 
Visual basic asp.net programming introduction
Visual basic asp.net programming introductionVisual basic asp.net programming introduction
Visual basic asp.net programming introduction
 
Correlation
CorrelationCorrelation
Correlation
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notes
 
C#/.NET Little Wonders
C#/.NET Little WondersC#/.NET Little Wonders
C#/.NET Little Wonders
 

Semelhante a Java event processing model in c# and java

Event+driven+programming key+features
Event+driven+programming key+featuresEvent+driven+programming key+features
Event+driven+programming key+featuresFaisal Aziz
 
Event Handling in JAVA
Event Handling in JAVAEvent Handling in JAVA
Event Handling in JAVASrajan Shukla
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptxusvirat1805
 
PATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event ModelPATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event ModelMichael Heron
 
EventBus for Android
EventBus for AndroidEventBus for Android
EventBus for Androidgreenrobot
 
Event bus for android
Event bus for androidEvent bus for android
Event bus for android丞廷 鄭
 
OOP Lecture 11-EventHandling1.pptx
OOP Lecture 11-EventHandling1.pptxOOP Lecture 11-EventHandling1.pptx
OOP Lecture 11-EventHandling1.pptxTanzila Kehkashan
 
Chap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptxChap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptxTadeseBeyene
 
File Handling
File HandlingFile Handling
File HandlingSohanur63
 
Events: The Object Oriented Hook System.
Events: The Object Oriented Hook System.Events: The Object Oriented Hook System.
Events: The Object Oriented Hook System.Nida Ismail Shah
 
ITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxudithaisur
 
Delegates and Events in Dot net technology
Delegates and Events  in Dot net technologyDelegates and Events  in Dot net technology
Delegates and Events in Dot net technologyranjana dalwani
 
Event and Signal Driven Programming Zendcon 2012
Event and Signal Driven Programming Zendcon 2012Event and Signal Driven Programming Zendcon 2012
Event and Signal Driven Programming Zendcon 2012Elizabeth Smith
 

Semelhante a Java event processing model in c# and java (20)

Event+driven+programming key+features
Event+driven+programming key+featuresEvent+driven+programming key+features
Event+driven+programming key+features
 
event_handling.ppt
event_handling.pptevent_handling.ppt
event_handling.ppt
 
Unit 6 Java
Unit 6 JavaUnit 6 Java
Unit 6 Java
 
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
 
Event Handling in JAVA
Event Handling in JAVAEvent Handling in JAVA
Event Handling in JAVA
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
 
PATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event ModelPATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event Model
 
EventBus for Android
EventBus for AndroidEventBus for Android
EventBus for Android
 
Module3.11.pptx
Module3.11.pptxModule3.11.pptx
Module3.11.pptx
 
Module 5.pptx
Module 5.pptxModule 5.pptx
Module 5.pptx
 
Events1
Events1Events1
Events1
 
ax2012
 ax2012 ax2012
ax2012
 
Event bus for android
Event bus for androidEvent bus for android
Event bus for android
 
OOP Lecture 11-EventHandling1.pptx
OOP Lecture 11-EventHandling1.pptxOOP Lecture 11-EventHandling1.pptx
OOP Lecture 11-EventHandling1.pptx
 
Chap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptxChap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptx
 
File Handling
File HandlingFile Handling
File Handling
 
Events: The Object Oriented Hook System.
Events: The Object Oriented Hook System.Events: The Object Oriented Hook System.
Events: The Object Oriented Hook System.
 
ITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptx
 
Delegates and Events in Dot net technology
Delegates and Events  in Dot net technologyDelegates and Events  in Dot net technology
Delegates and Events in Dot net technology
 
Event and Signal Driven Programming Zendcon 2012
Event and Signal Driven Programming Zendcon 2012Event and Signal Driven Programming Zendcon 2012
Event and Signal Driven Programming Zendcon 2012
 

Mais de Tech_MX

Virtual base class
Virtual base classVirtual base class
Virtual base classTech_MX
 
Theory of estimation
Theory of estimationTheory of estimation
Theory of estimationTech_MX
 
Templates in C++
Templates in C++Templates in C++
Templates in C++Tech_MX
 
String & its application
String & its applicationString & its application
String & its applicationTech_MX
 
Statistical quality__control_2
Statistical  quality__control_2Statistical  quality__control_2
Statistical quality__control_2Tech_MX
 
Stack data structure
Stack data structureStack data structure
Stack data structureTech_MX
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application Tech_MX
 
Spanning trees & applications
Spanning trees & applicationsSpanning trees & applications
Spanning trees & applicationsTech_MX
 
Set data structure 2
Set data structure 2Set data structure 2
Set data structure 2Tech_MX
 
Set data structure
Set data structure Set data structure
Set data structure Tech_MX
 
Real time Operating System
Real time Operating SystemReal time Operating System
Real time Operating SystemTech_MX
 
Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)Tech_MX
 
Motherboard of a pc
Motherboard of a pcMotherboard of a pc
Motherboard of a pcTech_MX
 
More on Lex
More on LexMore on Lex
More on LexTech_MX
 
MultiMedia dbms
MultiMedia dbmsMultiMedia dbms
MultiMedia dbmsTech_MX
 
Merging files (Data Structure)
Merging files (Data Structure)Merging files (Data Structure)
Merging files (Data Structure)Tech_MX
 
Memory dbms
Memory dbmsMemory dbms
Memory dbmsTech_MX
 

Mais de Tech_MX (20)

Virtual base class
Virtual base classVirtual base class
Virtual base class
 
Uid
UidUid
Uid
 
Theory of estimation
Theory of estimationTheory of estimation
Theory of estimation
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
String & its application
String & its applicationString & its application
String & its application
 
Statistical quality__control_2
Statistical  quality__control_2Statistical  quality__control_2
Statistical quality__control_2
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application
 
Spss
SpssSpss
Spss
 
Spanning trees & applications
Spanning trees & applicationsSpanning trees & applications
Spanning trees & applications
 
Set data structure 2
Set data structure 2Set data structure 2
Set data structure 2
 
Set data structure
Set data structure Set data structure
Set data structure
 
Real time Operating System
Real time Operating SystemReal time Operating System
Real time Operating System
 
Parsing
ParsingParsing
Parsing
 
Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)
 
Motherboard of a pc
Motherboard of a pcMotherboard of a pc
Motherboard of a pc
 
More on Lex
More on LexMore on Lex
More on Lex
 
MultiMedia dbms
MultiMedia dbmsMultiMedia dbms
MultiMedia dbms
 
Merging files (Data Structure)
Merging files (Data Structure)Merging files (Data Structure)
Merging files (Data Structure)
 
Memory dbms
Memory dbmsMemory dbms
Memory dbms
 

Último

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Último (20)

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

Java event processing model in c# and java

  • 1.
  • 2. Agenda  Introduction  C# Event Processing Macro View  Required Components  Role of Each Component  How To Create Each Type Of Component
  • 3. Introduction  C# is a modern programming language supported by an extensive set of API structures and classes.  i.e., The .Net Framework  C# supports event-driven programming normally associated with Microsoft Windows applications.  One normally thinks of events as being generated by GUI components  …but any object can generate an “event” if it’s programmed to do so…
  • 4. C# Event Processing Macro View  Generally speaking, two logical components are required to implement the event processing model:  1) An event producer (or publisher)  2) An event consumer (or subscriber)  Each logical components has assigned responsibilities  Consider the following diagram
  • 5. C# Event Processing Macro View When an Event occurs Object B processes the notification is sent to all event notification in its the subscribers on the list event handler code for that particular event…  Object A Object B  (Event Publisher) (Event Subscriber) Subscriber List Event Handler Code (Object B) Object A maintains a Object B subscribes to event list of subscribers for (or events) generated by Object A. each publishable event
  • 6. C# Event Processing Macro View When a Click event occurs notification is sent to all the subscribers on the list…  Button MainApp  (Event Publisher) (Event Subscriber) Subscriber List (MainApp.onButtonClick) onButtonClick Button maintains a list of subscribers of its Click event
  • 7. C# Event Processing Macro View  These two diagrams hide a lot of details  How is the subscriber list maintained?  How is the event generated?  How is notification sent to each subscriber?  What is an event – really?  How can you add custom event processing to your programs?  This presentation attempts to answer these questions in a clear manner…
  • 8. C# Event Processing Macro View  The .Net API contains lots of classes that generate different types of events…  Most are GUI related ○ Can you think of a few?  It also contains lots of Delegates  Can you name at least one?  Let’s take a closer look at the C# event processing model
  • 9. C# Event Processing Macro View  To implement custom event processing in your programs you need to understand how to create the following component types:  Delegates  Event Generating Objects (publishers) ○ Events ○ Event Notification Methods  Event Handling Objects (subscribers) ○ Event Handler Methods
  • 10. Required Components  To implement custom event processing in your programs you need to understand how to create the following component types:  Delegates  Event Generating Objects (publishers) ○ Events ○ Event Notification Methods  Event Handling Objects (subscribers) ○ Event Handler Methods
  • 11. Role of Each Component - Delegate -  Delegate  Delegate types represent references to methods with a particular parameter list and return type ○ Example  EventHandler(Object sender, EventArgs e)  Represents a method that has two parameters, the first one being of type Object and the second being of type EventArgs. Its return type is void.  Any method, so long as its signature matches that expected by the delegate, can be handled by the delegate.
  • 12. Role of Each Component - Delegate -  But just what is a delegate?  A delegate is a reference type object.  A delegate extends either the System.Delegate or MulticastDelegate class ○ Depends on whether one (Delegate) or more (MulticaseDelegate) subscribers are involved  You do not extend Delegate or MulticastDelegate ○ The C# compiler does it for you
  • 13. Role of Each Component - Delegate -  The delegate object contains the subscriber list.  It is actually implemented as a linked list where each node of the list contains a pointer to a subscriber’s event handler method  Delegates are types – like classes  Except – you declare them with the delegate keyword and specify the types of methods they can reference
  • 14. Role of Each Component - Publisher -  A publisher is any class that can fire an event and send event notifications to interested subscribers  A publisher class contains the following critical elements:  An event field ○ This is what subscribers subscribe to…  An event notification method ○ This activates the subscriber notification process when the event occurs
  • 15. Role of Each Component - Subscriber -  A subscriber is a class that registers its interest in a publisher’s events  A subscriber class contains one or more event handler methods - Event Handler Method –  An event handler methods is an ordinary method that is registered with a publisher’s event.  The event handler method’s signature must match the signature required by the publisher’s event delegate.
  • 16. Role of Each Component - Event -  An event is a field in a class  Events are declared with the event keyword  Events must be a delegate type  Delegates, remember, are objects that contain a list of pointers to subscriber methods that delegate can process  An event field will be null until the first subscriber subscribes to that event
  • 17. Role of Each Component - Event Notification Method -  In addition to an event field a publisher will have a method whose job is to start the subscriber notification process when the event occurs  An event notification method is just a normal method  It usually has a parameter of EventArgs or a user-defined subtype of EventArgs. ○ But it can have any number and type of parameters as required.
  • 18. An Custom Event Example - Elapsed Minute Timer -  This example includes five separate source files:  Delegate.cs  Publisher.cs  Subscriber.cs  MinuteEventArgs.cs  MainApp.cs
  • 19. using System; namespace CustomEventExample { public delegate void ElapsedMinuteEventHandler(Object sender, MinuteEventArgs e); } // end CustomEventExample namespace using System; namespace CustomEventExample { public class MinuteEventArgs : EventArgs { private DateTime date_time; public MinuteEventArgs(DateTime date_time){ this.date_time = date_time; } public int Minute { get { return date_time.Minute; } } } }
  • 20. using System; namespace CustomEventExample { public class Publisher { public event ElapsedMinuteEventHandler MinuteTick; public Publisher(){ Console.WriteLine("Publisher Created"); }
  • 21. public void countMinutes(){ int current_minute = DateTime.Now.Minute; while(true){ if(current_minute != DateTime.Now.Minute){ Console.WriteLine("Publisher: {0}", DateTime.Now.Minute); onMinuteTick(new MinuteEventArgs(DateTime.Now)); current_minute = DateTime.Now.Minute; }//end if } // end while } // end countMinutes method public void onMinuteTick(MinuteEventArgs e){ if(MinuteTick != null){ MinuteTick(this, e); } }// end onMinuteTick method } // end Publisher class definition } // end CustomEventExample namespace
  • 22. using System; namespace CustomEventExample { public class Subscriber { private Publisher publisher; public Subscriber(Publisher publisher){ this.publisher = publisher; subscribeToPublisher(); Console.WriteLine("Subscriber Created"); } public void subscribeToPublisher(){ publisher.MinuteTick += new ElapsedMinuteEventHandler(minuteTickHandler); } public void minuteTickHandler(Object sender, MinuteEventArgs e){ Console.WriteLine("Subscriber Handler Method: {0}", e.Minute); } } // end Subscriber class definition } // end CustomEventExample namespace
  • 23. using System; namespace CustomEventExample { public class MainApp { public static void Main(){ Console.WriteLine("Custom Events are Cool!"); Publisher p = new Publisher(); Subscriber s = new Subscriber(p); p.countMinutes(); } // end main } //end MainApp class definition } // end CustomEventExample namespace
  • 25.
  • 26. AGENDA  The Delegation Event model  Event Listeners  Event Classes  Event Listener Interfaces  Anonymous Inner Classes  Examples
  • 27. The Delegation Event Model The concept of Delegation Event model is  A source generates an event and sends it to one or more listeners.  The listener simply waits until it receives an event. Once an event is received, the listener processes events and then returns.  Listeners must register with a source in order to receive an event notification.
  • 28. Event Handling Model of AWT Event object • Event handling objects Event handling methods Event source Event listener • Button • Methods • Textbox • Etc.,
  • 29. Events o An event is an object that describes a state change in a source. o Events are generated by • Pressing a button • Entering a character via the keyboard • Selecting an item in a list • Clicking the mouse • And so on…………..
  • 30. Event Sources o A source is an object that generates an event. o A source must register listeners. General form public void addTypeListener(TypeListener el) public void removeTypeListener(TypeListener el) Type - name of the event. el - reference to the event listener.
  • 31. Event Listeners o A listener is an object that is notified when an event occurs. o Two Requirements :  It must have been registered with one or more sources to receive notifications.  It must implement methods to receive and process these notifications.
  • 32. EventObject o The root of the java event class hierarchy is EventObject, which is in java.util. o It is the super class of all the events.  Two methods: o getsource() - returns the source of the event. o toString() - returns the string equivalent of the event.
  • 33. AWTEvent class o Defined within the java.awt package. o Subclass of EventObject o Superclass of all AWT-based events that are handled by the delegation event model.
  • 34. Java.awt.event Event class Description Action Event Generated when a button is pressed,a list item is double-clicked, or a menu item is selected. AdjustmentEvent Generated when a scroll bar is manipulated. ComponentEvent Generated when a component is hidden, moved,resized, or becomes visible. ContainerEvent Generated when a component is added to or removed from a container. FocusEvent Generated when a component gains or loses keyboard focus.
  • 35. Event class Description InputEvent Abstract superclass for all component input event classes. ItemEvent Generated when a check box or list item is clicked; also occurs when a choice selection is made or a checkable menu item is selected or deselected. KeyEvent Generated when input is received from the keyboard. MouseEvent Generated when the mouse is dragged, moved, clicked, pressed, or released; also generated when the mouse enters or exits a component. MousewheelEvent Generated when the mouse wheel is moved. TextEvent Generated when the value of a text area or text field is changed. WindowEvent Generated when a window is activated,closed, deactivated, deiconified, iconified, opened or quit.
  • 36. Event Listener Interfaces  The ActionListener Interface void actionPerformed(ActionEvent ae)  The AdjustmentListener Interface void adjustmentValueChanged(AdjustmentEvent ae)  The ComponentListener Interface void componentResized(ComponentEvent ae) void componentMoved(ComponentEvent ae) void componentShown(ComponentEvent ae) void componentHidden(ComponentEvent ae)
  • 37. The ContainerListener Interface void componentAdded(ContainerEvent ae) void componentRemoved(ContainerEvent ae)  The FocusListener Interface void focusGained(FocusEvent fe) void focusLost(FocusEvent fe)  The ItemListener Interface void itemStateChanged(ItemEvent ie)  The KeyListener Interface void KeyPressed(KeyEvent ke) void KeyReleased(KeyEvent ke) void KeyTyped(KeyEvent ke)
  • 38. The MouseListener Interface void mouseClicked(MouseEvent me) void mouseEntered(MouseEvent me) void mouseExited(MouseEvent me) void mousePressed(MouseEvent me) void mouseReleased(MouseEvent me)  The MouseMotionListener Interface void mouseDragged(MouseEvent me) void mouseMoved(mouseEvent me)  The MouseWheelListener Interface void mouseWheelMoved(MouseWheelEvent mwe)
  • 39. The TextListener Interface void textChanged(TextEvent te)  The WindowFocusListener Interface void windowGainedFocus(WindowEvent we) void windowLostFocus(WindowEvent we)  The WindowListener Interface void windowActivated(WindowEvent we) void windowClosed(WindowEvent we) void windowClosing(WindowEvent we) void windowDeactivated(WindowEvent we) void windowDeiconified(WindowEvent we) void windowIconified(WindowEvent we) void windowOpened(WindowEvent we)
  • 40. Anonymous Inner Classes Import java.applet.*; Import java.awt.event.*; Public class AnonymousInnerClassDemo extends Applet { public void init() { addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent me) { showStatus(“Mouse Pressed”); } }); } }
  • 41. Handling Mouse Events import java.awt.*; import java.awt.event.*; import java.applet.*; public class MouseEvents extends Applet implements MouseListener,MouseMotionListener { String msg = “ “; int mouseX=0, mouseY=0; public void init() { addMouseListener(this); addMouseMotionListener(this); }
  • 42. public void mouseClicked(MouseEvent me) { mouseX=0; mouseY=10; msg = “Mouse clicked”; repaint(); } public void mouseEntered(MouseEvent me) { mouseX=0; mouseY=10; msg = “Mouse Entered”; repaint(); }
  • 43. public void mouseDragged(MouseEvent me) { mouseX= me.getX(); mouseY=me.getY(); msg=“ * “; showStatus(“ Dragging mouse at “+ mouseX + “mouseY” +mouseY); repaint(); } public void paint(Graphics g) { g.drawString(msg,mouseX,mouseY); } }
  • 44. DIFFERENCES WITH JAVA & C# 1. Differences in terms of syntax of Java and C# 2. Modification of concepts in C# that already exist in Java 3. Language features and concepts that do not exist in Java at all.
  • 45. Differences in terms of Syntax JAVA MAIN vs C# MAIN Java: public static void main(String[] args) C#: static void Main(string[] args)  string is shorthand for the System.String class in C#. Another interesting point is that in C#, your Main method can actually be declared to be parameter -less static void Main()
  • 46. Differences in terms of Syntax PRINT STATEMENTS Java: System.out.println("Hello world!"); C#: System.Console.WriteLine("Hello world!"); or Console.WriteLine("Hello again!");
  • 47. Differences in terms of Syntax DECLARING CONSTANTS Java:  In Java, compile-time constant values are declared inside a class as static final int K = 100; C#:  To declare constants in C# the const keyword is used for compile time constants while the readonly keyword is used for runtime constants. The semantics of constant primitives and object references in C# is the same as in Java. const int K = 100;
  • 48. Modified concepts from Java IMPORTING LIBRARIES  Both the langugaes support this functionality and C# follows Java’s technique for importing libraries:  C#: using keyword using System; using System.IO; using System.Reflection ;  Java: import keyword import java.util .*; import java.io.*;
  • 49. Enumerations  Java's lack of enumerated types leads to the use of integers in situations that do not guarantee type safety.  C# code: public enum Direction {North=1, East=2, West=4, South=8}; Usage: D i r e c t io n w a l l = D i r e c t i o n. No rt h;  Java equivalent code will be: public class Direction { public final static int NORTH = 1; public final static int EAST = 2; public final static int WEST = 3; public final static int SOUTH = 4; } Usage: i n t w a l l = D i r e c t i o n . NO RT H;
  • 50. Reference  The complete Reference, Java2, Fifth edition. Websites:  Java vs. C#: Code to Code Comparison http://www.javacamp.org/javavscsharp/  A Comparative Overview of C#: http://genamics.com/developer/csharp_comparativ e.htm