In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Net compared with Java Swing example analysis, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
Readers who have studied Java Swing must be confused about the relatively complex event-driven model in Swing. Although the event-driven model is completely reflected in Java Swing, it is really difficult for a software beginner to understand such a "nude" event-driven model.
Microsoft's .net is much simpler than Java Swing's GUI programming. It is also an event-driven model. The .net framework does a lot of encapsulation. Net calls this encapsulation a Delegate. The code is as follows:
/ / when the btnSubmit button is clicked, it is required to be handed over to the btnSubmit_Click method to handle / / EventHandler starts to the delegate in the middle, / / it is responsible for distributing events to the specified method for processing this.btnSubmit.Click + = new EventHandler (this.btnSubmit_Click) / / event handling method / / object sender: event source, in this case, btnSubmit object / / EventArgs e: event handling parameter, which stores the necessary information that needs to be provided to the programmer private void btnSubmit_Click (object sender, EventArgs e) {/ / print This is a button statement System.Diagnostics.Debug.WriteLine ("This is button");}
As a comparison between .net and Java Swing, let's take a look at the event handling and delegation of Java Swing is much more complicated: the code is as follows: (if you are not familiar with Swing event-driven, you can refer to my other article: detailed explanation of event-driven model examples (Java):
/ / add a listener SelectHandler to the btnSubmit, when the btnSubmit is clicked / / the actionPerformed with the listener is responsible for handling the business of the click event / / because the event source btnSubmit and the listener class SelectHandler are in two different classes / / in order for the SelectHandler class to get the information of the page, we need to pass the form object (this) / / to the listener btnSubmit.addActionListener (new SelectHandler (this)) / / listener SelectHandler, which must implement the action event ActionListener interface / / to achieve the role of event distribution class SelectHandler implements ActionListener {private CommonDialogDemo form = null; / / pass the form object CommonDialogDemo through the constructor to public SelectHandler (CommonDialogDemo form) {this.form = form in the SelectHandler class } / / event handling method. When btnSubmit is clicked, the following print code publicvoid actionPerformed (ActionEvent e) {System.out.println ("This is button");}} is automatically executed.
According to the above code, we can clearly see that .net compared with Java Swing, Java Swing is much more troublesome, and what is more unbearable is that if there are multiple buttons on a page, we have to write multiple event listening classes for each button, and these classes are generally set as internal classes. Readers who have studied software modeling may know that internal software modeling is not recommended in software engineering, so writing such code will obviously increase design redundancy and complexity, so we can consider writing a similar one ourselves. The same event delegate class as EventHandler in Net to handle event distribution.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.