In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is to share with you about the comparison between Java and C# event handling. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it with the editor.
The editor introduces Java and C# event handling respectively, including that in C#, Events members are used to declare a class event.
Both Java and C# event handling implement the event source-event responder mechanism, but they are not exactly the same. Java implements a two-level entity object mode of event source and event responder, where the event responder is also the event listener, while C # implements a three-level entity object mode of event source-agent-event responder. Here are two ways to specify.
Java event handling
Conceptually, an event is a transmission mechanism in which a certain state changes between the "source object" and the "listener object". Events have many different uses, such as mouse events that are often handled in Windows systems, window boundary change events, keyboard events, and so on. In Java, a general and extensible event mechanism is defined, which can:
◆ provides a common framework for the definition and extension of event types and delivery models, and is suitable for a wide range of applications.
◆ has a high degree of integration with Java language and environment.
◆ events can be captured and ignited by describing the environment.
◆ enables other construction tools to adopt certain techniques to directly control events at design time, as well as the relationship between event sources and event listeners.
The ◆ event mechanism itself does not depend on complex development tools.
Events are passed from the event source to the listener through the Java method call to the target listener object. For the occurrence of each specific event, a clear Java method is defined accordingly. These methods are defined centrally in the event listener (EventListener) interface, which inherits java.util.EventListener. A class that implements some or all of the methods in the event listener interface is the event listener. With the occurrence of an event, the corresponding state is usually encapsulated in an event state object, which must inherit from java.util.EventObject. The event state object is passed as a single parameter to the listener method that responds to the event. The identity of the event source that emits a particular event is to define a registration method for the event listener in accordance with the specified design format and to accept a reference to the interface instance of the specified event listener. Sometimes, when event listeners cannot directly implement the event listener interface, or there are other additional actions, it is necessary to insert an instance of an event adapter class between one source and one or more other listeners to establish a connection between them.
C# event handling
In the development of .NET applications, both WEB Forms (ASP.NET) and Windows Forms involve the event response and handling of a large number of objects, such as customers submitting an order online or moving the mouse over the Windows window. So how do you declare events and add response methods to events in C #?
In C #, Events members are used to declare a class event. It is common to declare an event member in a class in the following syntax: public event stands for name event name. If you declare a Click event member in the Control class, the syntax is as follows:
Public event EventHandler Click
In C #, a new data type delegate (representative) has been added to solve the event handling problem. Representative data types are very similar to pointers in the C language, but unlike pointers, the code is safe and manageable. Because of the simplicity of C # itself, it is also very easy to understand delegate for programs that have not used C and pointers.
In C #, by using delegate, you can easily add one or more response methods to an event in a .net object through the "+ =" (plus equals) operator; you can also cancel these response methods through a very simple "- =" (minus equals) operator. Java and C# event handling are described above.
This is the comparison between Java and C# event handling. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.