zoukankan      html  css  js  c++  java
  • 4.4日学习总结

     这周没有学习什么东西,主要是考虑小组合作的APP,这周进行了商讨跟PPT的制作

    Panel面板  Window窗口 Frame框架 Dialog对话框
    container是component的子类;
    容器的特点:1、容器有一定的范围,一般的容器是矩形的,有些可以用边框框出来
    2、容器有一定是位置;
    3、容器通常有一个背景,背景填充整个容器
    4、容器可以包含其他的基本组件,当容器显示出来的时候包含的基本组件会显示出来,否则则不会;
    Container类常用方法
    add() 像容器中添加其他组件,可以是普通组件也可以是容器
    getComponent()返回指定的组件
    getComponentCount() 返回该容器内组件的个数
    getComponents()返回该容器的所有组件setLocation(int x,int y)设置组件位置setSize(int width,int hight)设置组件大小setBounds(int x,int y,int width,int hight)同时设置组件的位置,大小setVisible(boolean b)设置组件的可见性;
    
    按钮类
    public static void main(String[] args)
        {
            //创建一个窗口
            Frame frame=new Frame();
            frame.setTitle("添加按钮");//设置窗口的程序
            frame.setBounds(150,150,400,300);//窗口的起始位置x=150,y=150宽400,高300
            Button btn=new Button("确定");//定义按钮对象
            frame.add(btn);//将按钮添加到Frame中        
            frame.setVisible(true);//显示(true)或隐藏窗口(false)
        }
    
    
    
    BorderLayout边界布局管理器是Frame的默认的布局管理器,将窗口划分成东、西、南、北、中五部分,将容器划分成5个区域,只能容纳5个组件
    public static void main(String[] args)
        {
            //创建一个窗口
            Frame frame=new Frame("Bourderyout布局管理器");//窗口的名字
            frame.setBounds(150,150,400,300);//窗口的起始位置x=150,y=150宽400,高300
            //LayoutManager布局管理器接口
            LayoutManager lm=new BorderLayout();//创建BorderLayout布局管理器对象
            frame.setLayout(lm);//为Frame设置布局管理器,默认为BorderLayout
            //add函数第一个参数是要添加的组件对象,第二个是组件在容器里面的位置,位置参数是类中的常量
            frame.add(new Button("北"),BorderLayout.NORTH);    
            frame.add(new Button("南"),BorderLayout.SOUTH);
            frame.add(new Button("西"),BorderLayout.WEST);
            frame.add(new Button("东"),BorderLayout.EAST);
            frame.add(new Button("中"),BorderLayout.CENTER);
            frame.setVisible(true);//显示(true)或隐藏窗口(false)
        }
    
    
    Flowyout布局管理器会按照加入组件的顺序从左向右排列;
    hgap水平间距 vgap垂直间距 align组件的排列方向      构建方法 FlowLayout()  FlowLayout(int align)使用指定排列方式 FlowLayout(int align,int hgap,int vgap)
    align中使用的参数有FlowLayout.LEFT FlowLayout.CENTER FlowLayout.RIGHT
    public static void main(String[] args)
        {
            //创建一个窗口
            Frame frame=new Frame();
            frame.setTitle("FlowLayout布局管理器");
            frame.setBounds(150,150,400,300);//窗口的起始位置x=150,y=150宽400,高300
            //LayoutManager布局管理器接口
            frame.setLayout(new FlowLayout());//为Frame设置布局管理器,如果不设置默认为BorderLayout
            for(int i=0;i<10;i++)
            {
            frame.add(new Button("按钮"+i));
            }
            frame.setVisible(true);//显示(true)或隐藏窗口(false)
        }
    
    
    
    将窗口划分成很多网格,每一格中放入一个组件,按照从左到右从上到下的顺序;
    GridLayout(int rows,int cols)指定行数列数默认横向行间距纵向行间距
    GardLayout(int rows,int cols,int hgap,int vgap)指定行数列数指定横向行间距纵向行间距
    public static void main(String[] args)
        {
            //创建一个窗口
            Frame frame=new Frame();
            frame.setTitle("GridLayout布局管理器");
            frame.setBounds(150,150,400,300);//窗口的起始位置x=150,y=150宽400,高300
            //设置网格的行与列5行5列
            frame.setLayout(new GridLayout(5,5));//为Frame设置布局管理器,如果不设置默认为BorderLayout
            for(int i=1;i<=25;i++)
                frame.add(new Button("按钮"+i));
            frame.setVisible(true);//显示(true)或隐藏窗口(false)
        }
    
    
    
    CardLayout布局管理器是以时间来管理组件将加入容器里面的组件看成一叠卡片只有最上面的可以被看见
    CardLayout()默认的构造方法    CardLayout(int hgap,int vgap)指定左右边界间距,上下边界间距
    first(Container target)显示target容器中的第一个卡片     last(Container target)显示target容器中的最后一个卡片
    previous(Container target)显示target容器中的前一个卡片   next()显示target容器中的后一个卡片
    show(Container target,String name)显示容器中指定名字的卡片
    public static void main(String[] args)
        {
            //创建一个窗口
            Frame frame=new Frame();
            frame.setTitle("CardLayout布局管理器");
            frame.setBounds(150,150,400,300);//窗口的起始位置x=150,y=150宽400,高300
            CardLayout layout=new CardLayout();
            frame.setLayout(layout);//为Frame设置布局管理器
            Panel p1=new Panel();
            p1.setBackground(Color.RED);//设置第一个面板为红色
            p1.add(new Label("背景为红色的面板"));
            
            Panel p2=new Panel();
            p2.setBackground(Color.BLUE);
            p2.add(new Label("背景为蓝色的面板"));
            
            Panel p3=new Panel();
            p3.setBackground(Color.GREEN);
            p3.add(new Label("背景为绿色的面板"));
            frame.add("redpanel",p1);//将面板添加到frame中
            frame.add("bluepanel",p2);
            frame.add("greenpanel",p3);
            layout.last(frame);
            frame.setVisible(true);//显示(true)或隐藏窗口(false)
        }
  • 相关阅读:
    (二)php的常量和变量
    关于标签系统的一点想法。
    Linux运维工程师中级面试题
    Linux C 编程内存泄露检测工具(一):mtrace
    掌握sudo的使用
    Scala极速入门
    处理千万级以上的数据提高查询速度的方法
    linux svn服务器搭建、客户端操作、备份与恢复
    select/poll/epoll 对比
    汇编指令和标志寄存器
  • 原文地址:https://www.cnblogs.com/1234yyf/p/12637678.html
Copyright © 2011-2022 走看看