CUI入门

GUI简介

1.图像用户界面

为什么少人用?

图形界面不美观,需要JRE环境(比较大)

为什么要学?

mvc思想

把之前java代码语法串连起来

可以做一些小工具

1.AWT

new来创建的 面向对象思想

1.包含许多类和窗口

2.元素 窗口 按钮 文本框

3.java.awt

awt的类图谱

2.组件和容器

2.1frame

第一个frame窗口

Frame frame = new Frame("hello");
​
//设置窗口可见性
frame.setVisible(true);
​
//设置窗口初始位置
frame.setLocation(100, 100);
​
//设置窗口大小
frame.setSize(300, 200);
​
//设置窗口背景颜色
frame.setBackground(Color.white);
//这是final修饰的常量,直接用类名访问
frame.setBackground(new Color(155,22,55));
//参数是一个color类的类型,通过new一个color类型,构造器,传入rgb的参数
​
//设置窗口是否可以缩放 false 不缩放
frame.setResizable(false);
//设置窗口标题
frame.setTitle("第一个frame的窗口");
遇到不会的类,直接看源码frame
遇到方法,直接.
遇到参数是另一个类, 直接通过new一个来看源码,看源码的构造器有哪些??

类的封装 封装一个frame

public class lesson1_02 {
    public static void main(String[] args) {
        
        myFrame myFrame = new myFrame(100, 100, 300, 200, Color.red);
        myFrame myFrame1 = new myFrame(400, 100, 300, 200, Color.BLUE);
        myFrame myFrame2 = new myFrame(100, 300, 300, 200, Color.yellow);
        myFrame myFrame3 = new myFrame(400, 300, 300, 200, Color.magenta);
    }
​
}
//对frame类的封装;
class myFrame extends Frame{
    static int id=0;
     public myFrame() {}
     public myFrame(int x,int y,int w,int h,Color color) 
     {
         super("myframe"+( ++id));
         setVisible(true);
         setBounds(x, y, w, h);
         setBackground(color);
         
     }
    
}

2.2panel面板

可以看成一个空间,但是不能单独存在

PANEL的坐标和frame一模一样

   //设置panel的坐标 相对于外层frame的坐标
        panel.setBounds(50, 50, 400, 300);
        panel.setBackground(new Color(155, 50, 99));

需要
LAYOUT 布局
frame.setLayout(null);
​
可见
frame.setVisible(true);
​
frame添加组件是panel
frame.add(panel);

关闭窗口de 实现

事件监听 //监听

addwindowliastener(需要windowListenerl类型 )

(需要什么new什么类型)

addwindowliastener(new windowListenerl() )

windowListenerl()发现是个接口,需要实现太多方法

///使用适配器模式

ctrl+t 找到这个接口的实现类

通过new这个实现类类实现这个接口,因为实现类必须实现接口的所有抽象方法

addwindowliastener(new windowAdapter() )

///发现这个 windowAdapter()

重写里面windowsclose()方法

//当关闭按钮,窗口要执行的事件是,关闭程序

system.exit(0);

public static void main(String[] args) {
        //panel 可以看成一个空间,不能独立存在
        
        Frame frame = new Frame();
        Panel panel = new Panel();
        //设置frame的布局为null(不设置看不到里面的pannl,只看到窗口)
        frame.setLayout(null);
        
        //设置坐标
        frame.setBounds(100 ,100, 500, 400);
        frame.setBackground(new Color(0xff5566));
        
        //设置panel的坐标 相对于外层frame的坐标
        panel.setBounds(50, 50, 400, 300);
        panel.setBackground(new Color(155, 50, 99));
        
        //frame.add(panel)
        frame.add(panel);
        
        //设置可以见
        frame.setVisible(true);
        
        //监听 监听事件
        
        //因为参数是一个windowListener()的接口,需要实现太多方法
        //采用适配器模式
        //通过实例化   一个实现了这个接口的的类,就是通过ctrl+t可以查看接口的类
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

3.布局管理

3.1 流式布局

flowlayout

frame.setLayout(new FlowLayout(FlowLayout.LEFT));
frame.setLayout(new FlowLayout());

注意frame使用居右或者居左的时候注意

注意frame的layout写法
​
frame.setLayout(new FlowLayout(FlowLayout.LEFT));
与前面的color不同
​
frame.setBackground(Color.GREEN);
frame.setBackground(new Color(11,22,99));
​
因为color类中是final修饰的常量直接  类名调用
farame是构造器中的常量。所以是先写构造器,再按类名.常量

public static void main(String[] args) {
        //流式布局(从左到右)
        Frame frame = new Frame("这是个布局的窗口");
        
        //button 元素
        Button button1 = new Button("标题1");
        Button button2 = new Button("标题2");
        Button button3 = new Button("标题3");
        Button button4 = new Button("标题4");
        
        //布局flow流式布局(默认为center)
        
        //frame.setLayout(new FlowLayout());//默认居中
        frame.setLayout(new FlowLayout(FlowLayout.LEFT));
        //frame.setLayout(new FlowLayout(FlowLayout.RIGHT));
        //这个不知是什么
        //frame.setLayout(new FlowLayout(FlowLayout.LEADING));
        //frame.setLayout(new FlowLayout(FlowLayout.TRAILING));
        
        //添加按钮进frame 一般添加进panel
        frame.add(button1);
        frame.add(button2);
        frame.add(button3);
        frame.add(button4);
        
        //frame可见性
        frame.setVisible(true);
        //frame 大小
        frame.setSize(400, 200);
        
        //关闭窗口
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
​

3.2东西南北中 (上下结构)

boderlayout

frame.add(east,BorderLayout.EAST);

注意

没有流式布局中需要setlayut

直接在frame中添加了add(组件,对象)

Button east = new Button("east");
frame.add(east,BorderLayout.EAST);
​
borderlayout类是一个实现类,实现了接口layoutmanager2

public static void main(String[] args) {
        //东西南北中
        Frame frame = new Frame();
        
        
        //按钮元素
        Button east = new Button("east");
        Button west = new Button("west");
        Button north = new Button("north");
        Button south = new Button("south");
        Button center = new Button("center");
        
        frame.setVisible(true);
        frame.setSize(500, 500);
        
        //frame 添加 button
        frame.add(east,BorderLayout.EAST);
        frame.add(west,BorderLayout.WEST);
        frame.add(north,BorderLayout.NORTH);
        frame.add(south,BorderLayout.SOUTH);
        frame.add(center,BorderLayout.CENTER);
        
        //关闭按钮
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }

3.3表格布局grid

frame.setLayout(new GridLayout(3,2));

frame.park()//java函数,最优秀的排列

pack函数源码

public static void main(String[] args) {
        //grid
        
        Frame frame = new Frame();
        
        //元素button
        Button btn1 = new Button("btn1");
        Button btn2 = new Button("btn2");
        Button btn3 = new Button("btn3");
        Button btn4 = new Button("btn4");
        Button btn5 = new Button("btn5");
        Button btn6 = new Button("btn6");
        
        //添加元素button进来
        frame.add(btn1);
        frame.add(btn2);
        frame.add(btn3);
        frame.add(btn4);
        frame.add(btn5);
        frame.add(btn6);
        
        //设置布局
        frame.setLayout(new GridLayout(3,2));
        frame.pack(); //java函数
        
        //设置窗口可见性
        frame.setVisible(true);
        frame.setSize(500, 500);
        
        //关闭窗口
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

 

模块名称:CompleteUI 作者:贱人 版本号:1.0.2016.127 说明:未经作者授权,禁止用于商业用途. @备注: 最全面的软件自绘界面 .版本 2 .子程序 A2W, 字节集, 公开 .参数 lpa, 文本型 .参数 bNoEndTag, 逻辑型, 可空 .子程序 MakeRCF, RectF, 公开 .参数 左, 整数型 .参数 顶, 整数型 .参数 宽, 整数型 .参数 高, 整数型 .参数 rcf, RectF, 参考 可空 .子程序 RGB2ARGB, 整数型, 公开 .参数 RGB颜色, 整数型 .参数 透明度, 整数型, 可空 .子程序 W2A, 文本型, 公开 .参数 lpw, 字节集 .子程序 超级延时_Cui, , 公开 .参数 微秒, 整数型 .子程序 窗口_取矩形, RectF, 公开, 根据窗口句柄返回窗口矩形GetWinRectF .参数 hWnd, 整数型 .子程序 窗口_消息循环, , 公开 .子程序 窗口_消息循环_对话框, , 公开, 注:父窗口句柄 为空时 以信息框的形式循环 不为空时 以对话框的形式循环 .参数 窗口句柄, 整数型 .参数 父窗口句柄, 整数型, 可空 .子程序 窗口_置鼠标指针, , 公开 .参数 鼠标指针, 整数型, 可空 .参数 从文件中加载, 字节集, 可空 .子程序 窗口_总在最前, , 公开 .参数 句柄, 整数型 .参数 总在最前, 逻辑型, 可空 .子程序 创建图片缩放, 整数型, 公开 .参数 图片, 字节集 .参数 缩放宽度, 整数型, 可空, 默认为原宽度 .参数 缩放高度, 整数型, 可空, 默认为原高度 .子程序 创建自字节集, 整数型, 公开 .参数 图片, 字节集 .子程序 发送消息_Cui, , 公开 .参数 组件句柄, 整数型 .参数 消息, 整数型 .参数 参数一, 整数型 .参数 参数二, 整数型 .子程序 画笔_创建自颜色, 整数型, 公开 .参数 ARGB颜色, 整数型, 可空 .参数 画笔宽度, 小数型, 可空, 默认为1 .参数 计算单位, 整数型, 可空 .子程序 画刷_创建自颜色, 整数型, 公开 .参数 ARGB颜色, 整数型, 可空 .子程序 扩展_绑定控件, 整数型, 公开, 绑定一个控件 拦截事件 .参数 句柄, 整数型, , 句柄 .参数 控件句柄, 整数型, 可空 .子程序 扩展_创建, 整数型, 公开 .参数 句柄, 整数型 .参数 左边, 整数型 .参数 顶边, 整数型 .参数 宽度, 整数型 .参数 高度, 整数型 .参数 标题, 文本型, 可空 .参数 可视, 逻辑型, 可空 .参数 禁止, 逻辑型, 可空 .子程序 扩展_内容, 文本型, 公开 .参数 句柄, 整数型 .参数 文本, 文本型, 可空 .子程序 扩展_取MDC, 整数型, 公开 .参数 句柄, 整数型, , 句柄 .子程序 扩展_是否穿透, 逻辑型, 公开 .参数 句柄, 整数型, , 句柄 .参数 穿透, 逻辑型, 可空 .子程序 扩展_鼠标指针, 整数型, 公开 .参数 句柄, 整数型, , 句柄 .参数 类型, 整数型, 可空, #鼠标指针_ .参数 是否动态载入, 逻辑型, 可空, 默认为假.如果为真时,参数一(类型)须为函数 LoadCursor/LoadCursorFromFile 调用所返回的值 .子程序 扩展_刷新显示, , 公开 .参数 句柄, 整数型, , 句柄 .参数 渐变幅度, 整数型, 可空, 默认为10 .参数 是否渐显, 逻辑型, 可空 .子程序 扩展_提示文本, 文本型, 公开, 扩展_置提示文本 .参数 句柄, 整数型, , 句柄 .参数 提示文本, 文本型, 可空, 提示文本 .参数 文本颜色, 整数型, 可空, 文本颜色 .参数 背景颜色, 整数型, 可空, 背景颜色 .子程序 扩展_置焦点, 逻辑型, 公开 .参数 句柄, 整数型, , 句柄 .子程序 扩展_组件回调, , 公开 .参数 句柄, 整数型 .参数 子程序指针, 子程序指针 .子程序 扩展_组件绘制, , 公开 .参数 句柄, 整数型 .参数 子程序指针, 子程序指针
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值