java72-GUL流式布局管理器


//面向对象思想,流式管理布局器
import java.awt.*;
import javax.swing.*;
public class test07 extends JFrame {
    JButton[] an={null,null,null,null,null,null,null,null};//把需要的组件定义在这里
    public  static void main(String[] args){
        test07 lx1=new test07();//主函数调用即可
    }
    //定义一个构造器
    public  test07(){
        an[0]=new JButton("苹果");
        an[1]=new JButton("香蕉");
        an[2]=new JButton("李子");
        an[3]=new JButton("梨子");
        an[4]=new JButton("栗子");
        an[5]=new JButton("哈密瓜");
        an[6]=new JButton("西瓜");
        an[7]=new JButton("花生");
        this.setLayout(new FlowLayout());
       // this.setLayout(new FlowLayout(FlowLayout.LEFT));靠左
        //添加布局管理器,以免添加出现错误,由于java默认的边界布局管理器
 
        this.add(an[0]);
        this.add(an[1]);
        this.add(an[2]);
        this.add(an[3]);
        this.add(an[4]);
        this.add(an[5]);
        this.add(an[6]);
        this.add(an[7]);
        this.setTitle("歌谣");
        //设置初始位置
        this.setLocation(100,100);
        //设置大小
        this.setSize(180,180);
        //释放窗口关闭的资源,这个要写对
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //显示界面
        this.setVisible(true);
        //不可动
        this.setResizable(false);
        //1继承jframe类
        //2在最上方定义组件
        //3在构造方法中创建组件
        //4在构造方法添加组件
        //5设置窗体属性
        //6显示窗体
        //7在主函数创建对象
    }
}
运行结果

 

posted @   前端导师歌谣  阅读(24)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示