• Document


    1.继承JFrame

    2.定义需要的组件

    3.创建组件

    4.设置布局管理器

    5.添加组件

    6.显示窗体

    ---------------------------------------------

    小代码:

    /***
    * 功能页面:GUI界面开发
    *
    * BorderLayout演示
    * @author yanlong
    * 2017/6/4
    * 1.继承JFrame
    * 2.定义你需要的组件
    * 3。创建组件
    * 4.添加组件
    * 5.对窗体设置
    * 6.显示窗体
    */
    package com.test1;

    import javax.swing.JButton;
    import javax.swing.JFrame;

    public class Demo8_1 extends JFrame{
    //把需要的swing组件的定义部分写到这里
    JFrame jf=new JFrame();
    static JButton jb1=null;

    public static void main(String[] args){
    Demo8_1 demo8_1=new Demo8_1();
    }
    //构造函数
    public Demo8_1(){
    //JFrame jf=new JFrame();
    //添加一个按键
    jb1=new JButton("我是一个按键");
    //添加JButton组件
    this.add(jb1);
    //设置窗口的标题
    this.setTitle("陈燕龙");
    //设置大小,按像素
    this.setSize(200,200);
    //初始化位置
    this.setBackground(null);
    //设置初始化位置
    this.setLocation(500, 500);
    //设置当关闭串口的时候,保证退出
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //显示
    this.setVisible(true);
    }
    }

    -----------------------------------------

    /***
    * BorderLayout演示
    * @author yanlong
    * 2017/6/4
    * 1.继承JFrame
    * 2.定义你需要的组件
    * 3。创建组件
    * 4.添加组件
    * 5.对窗体设置
    * 6.显示窗体
    */
    package com.test1;

    import java.awt.BorderLayout;

    import javax.swing.JButton;
    import javax.swing.JFrame;

    public class Demo8_2 extends JFrame{
    //定义组件
    JButton jb1,jb2,jb3,jb4,jb5;

    public static void main(String[] args){
    Demo8_2 demo8_2=new Demo8_2();
    }
    public Demo8_2(){
    //创建组件
    jb1=new JButton("中部");
    jb2=new JButton("北部");
    jb3=new JButton("东部");
    jb4=new JButton("南部");
    jb5=new JButton("西部");
    //添加组件
    this.add(jb1,BorderLayout.CENTER);
    this.add(jb2,BorderLayout.NORTH);
    this.add(jb3,BorderLayout.EAST);
    this.add(jb4,BorderLayout.SOUTH);
    this.add(jb5,BorderLayout.WEST);
    //设置窗体的属性
    this.setTitle("边距布局案例");
    this.setSize(300,200);
    this.setLocation(200,200);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //显示窗体
    this.setVisible(true);

    }


    }

    -------------------------------------------

    /**
    * 功能:流式布局案例
    */
    package com.test1;

    import java.awt.FlowLayout;

    import javax.swing.JButton;
    import javax.swing.JFrame;

    public class Demo8_3 extends JFrame {
    //定义组件
    JButton jb1,jb2,jb3,jb4,jb5,jb6;

    public static void main(String[] args){
    Demo8_3 demo8_3=new Demo8_3();
    }


    public Demo8_3(){
    //创建组件
    jb1=new JButton("关飞0");

    jb2=new JButton("关飞1");
    jb3=new JButton("关飞2");
    jb4=new JButton("关飞3");
    jb5=new JButton("关飞4");
    jb6=new JButton("关飞5");
    //添加组件
    this.add(jb1);
    this.add(jb2);
    this.add(jb3);
    this.add(jb4);
    this.add(jb5);
    this.add(jb6);
    //设置布局管理器
    this.setLayout(new FlowLayout(FlowLayout.RIGHT));
    //设置窗体的属性
    this.setTitle("流式布局");
    this.setSize(350,200);
    this.setLocation(200,200);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //禁止用户改变窗体大小
    this.setResizable(false);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //显示
    this.setVisible(true);
    }
    }

    -------------------------------------

    /**
    * 网格布局
    */
    package com.test1;

    import java.awt.GridLayout;

    import javax.swing.JButton;
    import javax.swing.JFrame;

    public class Demo8_4 extends JFrame{
    //定义需要的组件
    int size=9;
    JButton jbs[]=new JButton[size];
    public static void main(String[] args){
    //创建实例化
    Demo8_4 demo8_4 =new Demo8_4();
    }
    public Demo8_4(){

    //创建组件
    for(int i=0;i<=8;i++){
    // jbs[i]=new JButton(String.valueOf(i));
    jbs[i]=new JButton(String.valueOf(i));
    }
    //设置网格布局
    this.setLayout(new GridLayout(3,3));
    //添加组件
    for(int i=0;i<size;i++){
    this.add(jbs[i]);
    }
    //设置窗体属性
    this.setTitle("网格布局管理器");
    this.setSize(300, 200);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setLocation(200, 200);
    //显示
    this.setVisible(true);
    }
    }

  • 相关阅读:
    roughViz 一个可重用,功能强大的手绘图表组件
    sqlg rdbms 上实现的Apache TinkerPop
    golang 几个好用的cli package
    ent 基本使用十九 事务处理
    oracle查看表空间和物理文件大小
    Oracle备份的几种方式
    Oracle导出/导入数据库的三种模式
    Oracle 11g 数据库 expdp/impdp 全量导入导出
    Oracle查询数据库中所有表的记录数
    oracle 如何查看当前用户的表空间名称
  • 原文地址:https://www.cnblogs.com/chenyanlong/p/6942439.html
Copyright © 2020-2023  润新知