Java Graphical user interface cognition

Source: Internet
Author: User

In order for us to generate a graphical user interface with good platform independence, the Java language provides a layout manager tool to manage the layout of components in a container without using directly setting component locations. Component classes are created for the user interface, for example, Jbutton,jlabel and JTextField. Container classes are used to contain other components, such as Jframe,jpanel and JApplet. Helper classes are used to support GUI components, such as graphics,color,font,fontmetrics and dimension.

First, the Component class
An instance of the Component class can be displayed on the screen. The component class is the root class for all user interfaces that include the container class, and the JComponent class is the root class for all lightweight swing component classes. Both component and JComponent are abstract classes.

Second, the Container class
An instance of container can contain component instances. A container class is a GUI component that is used to hold other GUI components. Window,panel,applet,frame and dialog are both container classes for AWT components. To use the swing component as a container, you can use the Container,jframe,jdialog,japplet and JPanel in the following table.
Third, GUI Auxiliary class
Auxiliary classes are not subclasses of component, such as Graphics,color,font,fontmetrics,dimension, LayoutManager, and so on. They are used to describe the properties of a GUI component, such as the contents of a graphic, color, font, and size.
Iv. Layout Manager
FlowLayout is the simplest layout manager. Arranges components from left to right in the container, in the order in which they are added. When you fill a line, start a new line. You can use one of three constants Flowlayout.right,flowlayout.center and Flowlayout.left to specify the alignment of the component. You can also specify the interval in pixels between components. The properties of the layout manager can be changed dynamically. FlowLayout has attributes Alignment,hgap and vgap. You can use the Setalignment,sethgap and Setvgap methods to indicate alignment, horizontal and vertical spacing. GridLayout has attributes Rows,columns,hgap and vgap. You can use the Setrows,setcolumns,sethgap and Setvgap methods to specify the number of rows, the number of columns, and the horizontal and vertical intervals. BorderLayout has attributes Hgap and vgap. You can use the Sethgap and Setvgap methods to specify horizontal and vertical intervals. If you need to dynamically change the properties of the layout manager, the layout manager must use a variable to display the reference. This variable can then be used to change the properties of the layout manager. Using a panel as a sub-container assumes that you want to place a button and a text field in the frame. Buttons are placed in a grid, with a single line of text fields. If you put these components in a separate container, it is difficult to achieve the desired visual effect. Using the Java graphical user interface for programming, you can divide a window into several panels. The function of a panel is to group the sub-containers of user interface components. You can add these buttons to a panel, and then add the panel to the frame. The swing version of the panel is JPanel. You can use new JPanel () to create a panel with a default FlowLayout manager, or you can use new JPanel (LayoutManager) to create a panel with a specific layout manager. Use the Add (Component) method to add a component to the panel.

Java Graphical user interface cognition

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.