The example of this article shares the Java flow layout graphical interface writing code for your reference. The specific content is as follows
package jisuanqi; import java.awt.*; public class MyFrame extends Frame{ //继承Frame类 public MyFrame() { super("第一个图形界面"); //设置框架窗口标题 this.setSize(200, 130); //设置组件尺寸(宽,高) this.setLocation(300, 240); //设置组件的显示位置 this.setBackground(Color.lightGray); //设置组件的背景颜色 this.setLayout(new FlowLayout()); //设置的容器布局为流布局,居中 this.add(new Label("姓名:")); //创建标签,添加到框架上 this.add(new TextField("陈浩翔",10)); //创建文本行,10列 this.add(new Label("密码")); this.add(new TextField(10)); //创建10列的文本行 this.add(new Button("OK")); //创建按钮 this.add(new Button("Cancel")); //创建按钮 this.setVisible(true); //是否显示框架窗口,必须在添加组件后 } public static void main(String[] args) { new MyFrame(); } }
This is the first time to write a graphical interface Source code, a little exciting.
The graphic construction method of flow layout defaults to center arrangement;
Alignment constant:
LEFT (0): Left aligned
CENTER (1): Centered
RIGHT (2): Right aligned
public FlowLayout(int align)
//The align parameter specifies the alignment method, and the value is the alignment constant.
The above is the entire content of this article. I hope it will be helpful to everyone's learning. I also hope that everyone will support the PHP Chinese website.
For more articles related to writing Java flow layout graphical interface, please pay attention to the PHP Chinese website!