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