An example of event-driven model in Java development

Source: Internet
Author: User

Perhaps every software practitioner has a transition from learning a console application to learning visual programming, the advantage of a console application is that it is easy to practice the syntax and development habits of a language (such as. NET and Java), while visual programming learning can be very convenient to develop a variety of man-machine conversation interface (HMI )。 Visual programming may be the beginning of a beginner's interest in software, it may also be a milestone in software learning, as we can use various software integration development environments (IDES) to conveniently drag and drop various components (Component) on off-the-shelf interface windows, including our common buttons ( button), radio buttons (Radio button), check boxes, and so on (checkbox). This kind of drag-and-drop development is not only convenient, and the window will be immediately displayed in front of us, this is a software beginner may be a very fulfilling thing.

But many software learners in the process of learning visual development, only a very superficial understanding of visual programming, they may think that the use of drag-and-drop method to complete an interface is very commendable, but very few people will seriously understand the programming language for visual programming components of support and integration, I am deeply aware of the two-year teaching process at the Softworks Software Talent Training Center, so the following will be combined with my teaching experience to explain the most critical "event-driven model" in the visual programming process.

1. What is an event-driven model?

Before we explain the event-driven model, let's look at three major elements of the event-driven model:

• Event Source: The source body that can receive external events.

• Listener: An object that can receive notification of an event source.

• Event handler: The object that is used to handle the event.

Students should understand that any development technology based on the event-driven model includes the above three elements, whether it is. NET or Java technology, and even the Visual Basic and Delphi languages we used previously have an event-driven model development process based on these three major elements.

Now let's take a look at a life example, if one day you walk on the road accidentally by a drop in the sky Vase hit, and fainted dead past. The whole process is actually an event-handling process, and we can easily analyze the three major elements of the event-driven model that we just mentioned.

1. The person who is stunned is actually the source of the event, because he is the source of the external events that can be accepted.

2. The listener is the brain of this person because it senses pain.

3. Event handling is the person who passed out.

Because the event-driven model is ubiquitous in our daily lives, Java and other programming languages use this process in visual programming.

Event-driven models in 2.Java programming languages

In Java programming technology, the most common visual programming is the Java Swing technology, and Java Swing provides developers with a number of out-of-the-box components, such as buttons (JButton), radio buttons (Jradiobutton), and so on. In order to manage interactions between users and components that compose the graphical user interface of a program, you must understand how events are handled in Java.

Suppose the user clicks a button in the program's graphical user interface, which is actually the source of the event (the object that can raise the event). All Java Swing objects have the ability to perceive that they are being manipulated, so the JButton button has the ability to do so. An event usually has to have a source object, and this is the JButton object. When the button is clicked, the JButton component class generates an object that holds the ActionEvent for the event parameter, which contains information about the event and the source of the event. Figure 1-1 shows this mechanism.

Figure 1-1

Related Article

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.