Deep understanding. NET Event

Source: Internet
Author: User

Two days ago when chatting with a friend mentioned the incident, so write down this article and he shared the understanding of the incident. Because I dare not to enjoy it, please correct me.

In WinForm programming, the concept of events revolves around it all the time. The click of a button is an event. In. NET, the concept of events has always been a complex, esoteric theory, and the delegate keyword itself is a profound one to find.

In fact, the event is not so complex and abstruse. MS is just trying to get a little bit of code written by a programmer to tinker with the idea of an agent. In fact, if you have an understanding of Java interface Programming, you will have a much better understanding of. NET Events. Of course, we'll touch on Java code first.

In Java GUI programming, there is no proxy concept, it uses interfaces. Let's take a look at a window with a button:

1import java.awt.event.ActionEvent;
2import Java.awt.event.ActionListener;
3import Java.awt.event.WindowAdapter;
4import java.awt.event.WindowEvent;
5import Javax.swing.JButton;
6import Javax.swing.JFrame;
7
8public class Eventstudy {
9 public static void Main (string[] args) {
JFrame f = new JFrame ();
One JButton B = new JButton ();
F.addwindowlistener (New Windowadapter () {
@Override public
void windowclosing (WindowEvent e) {
system.exit (0);
}
);
F.setsize (+);
B.settext ("I ' m a button");
B.addactionlistener (new ActionListener () {
@Override public
void actionperformed (ActionEvent E ) {
System.out.println ("The button is clicked.");
}
);
F.add (b);
F.setvisible (true);
}
30

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.