Java 13th Day Learning content Review--java White Paper 8th Chapter

Source: Internet
Author: User
Tags imap

Java Event handling mechanism

    1. The information about the event is encapsulated in an event object (a parameter), and the event source distributes the time object to all of its monitors, and the monitor responds to the event.

    2. AWT Time processing mechanism

      1. The Listener object constructs an instance that implements the Listener interface

      2. An event source is an instance of an object that can register (add) listeners and send events (events sent to listeners)

      3. When an event occurs, the event source is sent to all monitors that are added to the event source

      4. The monitor uses the event information sent over to determine how the corresponding

3. An event source can correspond to multiple monitors, listener interface ActionListener interface, this interface contains only one method

The Void actionperformed (ActionEvent event) parameter is the event that is sent, and differs depending on the type of event.

4. About creating a button:

JButton x = new JButton (first name, image); parameter can make 1 or two

5. Use the Add method to add a button to the canvas

6. Frame Builder: A. Build canvas B. Controls added to the canvas c. Build listener D. Link the control to the listener E. Add the canvas to the frame

7. It is often the case that listeners need to operate on other objects, and one workaround is to set this monitor class as the inner class for that object class, and the author suggests that

8. Use the method event (this is the time that was sent). GetSource () Gets the object reference of the event that occurred, and the. Getactioncommand () method returns the command string associated with the action event

9. Creating a listener that contains a method can also be implemented as follows: Eventhandler.create (Actionlistener.class, frame (must be a public class), "Loaddate", "Source.text") Detailed with P299 and reflection mechanism

10. There are two ways of changing perceptions:

A. Static mode: Modifies the contents of a particular file, which is set only once when swing is started

B. Dynamic mode: Use Method Uimanager.setlookandfeel (look and feel name), find the perception of the target style; Swingutilities.updatecomponenttreeui (frame. This (prevents this from being used incorrectly)) Refreshes all components.

Detailed and P302;

11. About actions in Java

"Action" is the expansion of the monitor, it is based on the monitor, add pictures, explain the information and other functions, detailed and P306

Object instances of 12.MouseEvent become mouse events, detailed with P312

13. Method Getmodifiersex method can get mouse event mouse button and keyboard decoration, under WIN32 Button3_down_mask can detect right mouse click this time, the details of the relevant mask in p313

14. There are two separate excuses for mouse events MouseListener interface and Mousemotionlistener interface, which is responsible for mouse movement and drag.

There is a method in the 15.Cursor class Getpredefinedcursor method, the use of special parameters can set the mouse shape, detailed and P313

The inheritance structure diagram of the 16.AWT event class is detailed and p319

17. Events can be divided into two categories: semantic and low-level events, the event classes and corresponding event interfaces that are included in both events, and event adapters detailed in p319~p320

18. About adapters: Each AWT monitor interface with multiple methods is equipped with its own adapter, in order to prevent the use of the definition of trouble, you can design a class to inherit the adapter, and then just need to define the required interface method is good, do not redefine the interface all methods.

19. Listeners, frequent anonymous local classes

20. Listen to the form (frame), the event type being sent is windowevent, the listener interface is Windowslistener, and the (frame) is used. Addwindows () {Anonymous Local class}, add event listeners about the framework (form) and connect. Detailed in p305

21. Use the method Getnewstate method to get the status of the form

22. A listener can have multiple event sources (such as mouse click events and keyboard combination time), and the swing package provides an action interface that extends to the ActionListener interface. The action interface is implemented in the AbstractAction class in addition to the Actionperformed method, so you can use class inheritance AbstractAction classes to implement Actionperformed

23. Can Build button JButton (action variable instance name) according to "Action";

The 24.KeyStroke class encapsulates the description of the "key" and constructs an object instance of the class that needs to use its static method. Getkeystroke method, detailed in p309

25. Links to keyboard instructions and monitors, detailed in p311,: Two tables, IMAP contains key directive and its Id,amap contains ID and action (monitor), Input IMAP =. Getinputmap ("key combination description"), Input.put ( The placement key can be associated with the ID pair),

. Getactionmap () Get AMAP,. Put (placement ID and action pair);


This article is from the "Developing_rookie" blog, make sure to keep this source http://8942041.blog.51cto.com/8932041/1634786

Java 13th Day Learning content Review--java White Paper 8th Chapter

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.