第十一周课程总结

九宫格

1.实验代码:

package demo;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
public class test{
    public static void main(String[]args) {
        JFrame frame =new JFrame("九宫格布局");
        frame.setLayout(new GridLayout(3,3));
        JButton but =null;
        for(int i=0;i<9;i++) {
            but =new JButton("按钮"+i);
            frame.add(but);
        }
        frame.pack();
        frame.setVisible(true);
    }
}

2.实验截图:

实验总结:这个实验比较简单,书上也有例子,没什么问题。

课程总结:

基本容器:JFrame

 标签组件-Jlabel

 布局管理器

1)FlowLayout

 2)BorderLayout

 3)GridLayout

 4)CardLayout

5)绝对定位

如果不在窗体中指定布局管理器,也可以通过设置绝对坐标的方式完成布局设置。

public void setBounds(int  x, int y, int width, int  height)

感觉这周的学的东西有趣些,能够自己做一些比较实用的东西了,就比较感兴趣些。这周讲的东西也比较多,还要自己多花时间去消化消化。

原文地址:https://www.cnblogs.com/lyp82ndl/p/11815383.html