Take you into graphical user interface (3)

zhaozj2021-02-17  62

Today we discuss the topic of the theoretical, so it's boring, but you have to calm down, if you can't fully understand, don't be discouraged, you will gradually understand these things in the future practice.

First discuss the principle of display graphics in Java: First Java adopts the design mode of "Model-View-Controller, MVC), which involves the problem about design mode, here I designated The mode is expanded. If you want everyone to know the classic book "Design Pattern: Elements of Reusable Object-Oriented Software" If you are not very well to this, you can slowly experience the future application, of course, if you have enough time I also strongly recommend that you have a good research mode. Three separate classes are implemented in the MVC mode: Model: Save Content View: Displays the Controller: Controlling the user's input From this mode: "Model" It's not by the user interface (user interface), it is only responsible for saving; "View" is just the display of the model, so a model can have multiple views; "Controller" is responsible for users' input events, such as the mouse click, then determine Change the view or model. However, in use, because there is a dependency between the view and the controller, the implementation of the controller's operation and the implementation of the view has a strong dependence, so the view and controller generally have a composite object representation, which uses a controller corresponding to A view. In this way, the MVC has become a document / view structure, and Sun is called "Separable Model Architecture". Swing components are insertable and sensible to provide an independent object called a component's visual appearance and interface for the user, which is the independent object called UI, which is the view controller section in the MVC mode.

Then discuss the concept of the component: Some user interface elements in the window are called components, such as buttons, check boxes, and text boxes, and the like. So how do it displayed in the window? First, all java.awt.component classes are the old ancestors of all components, which defines the basic properties and methods of all components. Then, we have to mention the concept of a Container, which is a subclass of Component, and its object can contain other components. JFrame is a subclass of frame, and it and the relationship of Compoment can be represented by the following figure.

Depending on the feature of the container we design the user interface, it is actually adding components in the container. This may be you can't understand, but you read the following to the introduction of the window you will know. A simple JFrame frame (window) is actually very complicated, in order to intuitive expression, I still use a picture to display

The ContentPane object is most important to us now, because we generally add the GUI assembly here, the display of the text and the drawing of graphics are also completed here. There is also a menu and should be done here. (As for several other objects, we will discuss during future use)

I have been here today, I will introduce you to you tomorrow, introduce you to how to add GUI components to the window zone. Looking forward to your continuing support kwaif@sina.com

转载请注明原文地址:https://www.9cbs.com/read-29115.html

New Post(0)