首页 > 代码库 > swing之flowlayout
swing之flowlayout
import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFrame; //1.继承 JFrame类 //2.在最上方定义组件 //3.在构造方法中创建组件 //4、在构造方法中添加组件 //5.设置窗体属性 //6.显示窗体 //7.在主函数中创建对象 public class flowlayout1 extends JFrame{ JButton [] a={null,null,null,null,null,null,null,null}; public static void main(String[] args) { // TODO Auto-generated method stub flowlayout1 f1=new flowlayout1(); } public flowlayout1 () { a[0]=new JButton("瓜子"); a[1]=new JButton("话梅"); a[2]=new JButton("西瓜"); a[3]=new JButton("草莓"); a[4]=new JButton("香蕉"); a[5]=new JButton("苹果"); a[6]=new JButton("栗子"); a[7]=new JButton("黄瓜"); //a[8]=new JButton("葡萄"); this.setLayout(new FlowLayout(FlowLayout.LEADING));//默认是边界布局,如果想变成其他布局,加上 this.add(a[0]); this.add(a[1]); this.add(a[2]); this.add(a[3]); this.add(a[4]); this.add(a[5]); this.add(a[6]); this.add(a[7]); this.setTitle("流式布局flowlayout"); this.setSize(400,320); this.setLocation(100, 180); this.setResizable(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } }
swing之flowlayout
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。