java学习10.16

继续java图形化页面的学习,今天学的是页面的分区和布局
import java.awt.*;

public class _1016 {
public static void main(String[] args) {
Frame frame = new Frame();
frame.setBounds(500, 500, 300, 300);
frame.setAlwaysOnTop(true);

    //边界布局

// BorderLayout borderLayout = new BorderLayout();
// frame.setLayout(borderLayout);
// borderLayout.setVgap(10);//设置纵向间距
// borderLayout.setHgap(10);//设置横向间距

    //流式布局

// FlowLayout flowLayout = new FlowLayout();
// flowLayout.setAlignment(FlowLayout.LEFT);//对齐
// frame.setLayout(flowLayout);
// frame.setVisible(true);
// frame.add(new Button("1.button"), BorderLayout.EAST);
// frame.add(new Button("2.button"), BorderLayout.WEST);
// frame.add(new Button("3.button"), BorderLayout.SOUTH);
// frame.add(new Button("4.button"), BorderLayout.NORTH);
// frame.add(new Button("5.button"), BorderLayout.CENTER);

    //卡片布局
    GridLayout gridLayout = new GridLayout();
    gridLayout.setRows(2);
    frame.setLayout(gridLayout);

// gridLayout.setRows(10);
// for(int i=0;i<10;i++)
// {
// frame.add(new Button(i+".button"));
//
//
//
// }

    Panel topPanel = new Panel();
    topPanel.setBackground(Color.ORANGE);
    topPanel.setLayout(gridLayout);
    for(int i=0;i<5;i++)
        topPanel.add(new Button(i+".button"));
    frame.add(topPanel);

    Panel bottomPanel = new Panel();
    bottomPanel.setBackground(Color.PINK);
    bottomPanel.setLayout(new FlowLayout());
    for(int i=0;i<5;i++)
        bottomPanel.add(new Button(i+".button"));
    frame.add(bottomPanel);

    frame.setVisible(true);


}

}

posted @   臧博涛  阅读(5)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
点击右上角即可分享
微信分享提示