📄 flowlayoutdemo.java
字号:
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.*;
import java.awt.*;
public class FlowLayoutDemo extends JFrame
{
//声明JButton组件对象
JButton jbutton1,jbutton2,jbutton3,jbutton4;
public FlowLayoutDemo()
{
super("FlowLayout Demo");
//设置内容面板的布局方式为:流动布局FlowLayout方式
getContentPane().setLayout(new FlowLayout());
//创建JButton组件对象
jbutton1=new JButton("JButton1");
jbutton2=new JButton("JButton2");
jbutton3=new JButton("JButton3");
jbutton4=new JButton("JButton4");
//向内容面板中添加按钮组件对象
getContentPane().add(jbutton1);
getContentPane().add(jbutton2);
getContentPane().add(jbutton3);
getContentPane().add(jbutton4);
}
public static void main(String[] args)
{
FlowLayoutDemo flowLayoutDemo = new FlowLayoutDemo();
flowLayoutDemo.setSize(200,100); //设置窗口大小
flowLayoutDemo.setVisible(true); //设置窗口可见
flowLayoutDemo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -