The full name of GUI is Graphical User Interface, that is, graphical user interface. It is a graphical interface provided by applications for user operations, including windows, menus, buttons, toolbars and other various graphical interfaces. element.
AWT is a toolkit for creating graphical user interfaces. It provides some components for implementing graphical interfaces. The JDK provides corresponding components for each component. Java classes, these classes are located in the Java.awt package.
There are two subclasses in Windows, Frame class and Dialog class, Frame class It is used to create a frame window with a title as the main interface of the program. The Dialog class is used to create a dialog box to interact with the user's information.
Panel is a container and cannot exist alone. It can only exist in Windows and its subclasses. A Panel object represents a rectangular area in which you can To accommodate other components,
package AWT; import java.awt.*; public class GeZi { public static void main(String[] args) { Frame f=new Frame("我的世界!"); //设置窗体的宽和高 f.setSize(600,300); //设置窗体在屏幕中所处的位置(参考是左上角坐标) f.setLocation(600,200); f.setVisible(true); } }
The position and size of the component in the container are determined by the layout manager. There are 5 layout managers provided in the java.awt package, namely FlowLayout (flow layout manager), BorderLayout (border layout manager), GirdLayout (grid layout manager), GirdBagLayout (grid package layout manager) ), CardLayout (Card Layout Manager), each container will use a layout manager by default when it is created. In the program, you can set the layout manager by calling the setLayout() method of the container object, and automatically use the layout manager. Established layout management.
In this layout mode, the container will place components from left to right in the order they are added. When the boundary of the container is reached, the component will be automatically placed at the beginning of the next line. The component can be set to left alignment, center alignment, or right alignment. FlowLayout has three construction methods.
FlowLayout()//组件默认居中对齐,水平,垂直间距离为5个单位 FlowLayout(int align)//指定组件相对于容器的对齐方式,水平,垂直间距默认5个单位 FlowLayout(int align,int hgap,int vgap)//指定组件的对齐方式和水平,垂直间距rrree
The above is the detailed content of How to use Java GUI flow layout manager FlowLayout. For more information, please follow other related articles on the PHP Chinese website!