This article shares the code for writing Java flow layout graphical interface for your reference. The specific content is as follows
package jisuanqi;import java.awt.*;public class MyFrame extends Frame{ //Inherit the Frame class public MyFrame() { super("first graphical interface"); //Set the frame window title this.setSize(200, 130); //Set the component size (width, height) this.setLocation(300, 240); //Set the component's display position this.setBackground(Color.lightGray); //Set the component's background color this.setLayout(new FlowLayout()); //The container layout is a flow layout, centered this.add(new Label("name:")); //Create a label and add it to the frame this.add(new TextField("Cancel",10)); //Create a text line, 10 columns this.add(new Label("Password")); this.add(new TextField(10)); //Create a text line of 10 columns this.add(new Button("OK")); //Create a button this.add(new Button("Cancel")); //Create a button this.setVisible(true); // Whether to display the frame window, it must be after adding the component} public static void main(String[] args) { new MyFrame(); }} The first time I wrote the source code of the graphical interface, I was so excited.
The graphical construction method of flow layout is centered by default;
Alignment constants:
LEFT(0): left aligned
CENTER (1): Center
RIGHT (2): Right aligned
public FlowLayout(int align)
//The align parameter specifies the alignment method, and the value is an alignment constant.
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.