窗口,窗口的内容,弹窗
监听事件:鼠标,键盘的操作
外挂:JAVA,由于Java在JVM上运行,检测不到外挂,只能检测到JVM,如果用C写在硬件上运行,直接检测.exe
破解工具
像button都存放在container容器中,container包含Window和面板Panel
Window包含frame框架和Dialog弹窗Panel包含Applet
窗口是唯一的,而面板是多个。frame.add(panel)
学习GUI了解MVC架构,了解监听。Model View Controller,M是指业务模型,V是指用户界面,C则是控制器,使用MVC的目的是将M和V的实现代码分离
Swing 和 AWT,界面不美观,而且需要JRE环境
D:Javajdk1.8.0_05jrelib中的rt.jar,rt.jar代表runtime,包含所有核心Java 运行环境的已编译calss文件。利用解压软件打开,可以看到在rt.jar中的java文件下有lang,util,awt,math,io,time,sql包。可以看到
utiltimetextsqlsecurityrmi:RMI(Remote Method Invocation,远程方法调用),它大大增强了Java开发分布式应用的能力nio 区别于io:io存在buffer中,线程非阻塞。而io,在读取时,线程阻塞netmathlangiobeansawtapplet,Apple是采用Java编程语言编写的小应用程序,该程序可以包含在 HTML(标准通用标记语言的一个应用)页。 AWT AWT介绍
AWT底层实践,Abstract Window Toolkit。
包含很多类和接口元素:窗口,按钮,文本框java.awt
Swing界面
ctrl,,,自己学会看方法的源码,
component
button、textarea、Labelcontainer:(Window:frame,Dialog)(面板Panel)
第一个
package com.adair.lesson01;import java.awt.*;public class Testframe { public static void main(String[] args) { //看源码 frame frame = new frame("我的一个GUI"); //可见性 frame.setVisible(true); //设置窗口基本属性 frame.setSize(400,400); frame.setBackground(new Color(255, 0, 0)); frame.setLocation(200,200); frame.setResizable(false); //窗口关不了,要结束Java运行即可关闭 }}
package com.adair.lesson01;import java.awt.*;public class Testframe2 { public static void main(String[] args) { Myframe frame1 = new Myframe(100,100,200,200,Color.blue); Myframe frame2 = new Myframe(300,100,200,200,Color.red); Myframe frame3 = new Myframe(100,300,200,200,Color.yellow); Myframe frame4 = new Myframe(300,300,200,200,Color.green); }}class Myframe extends frame {//封装+继承 static int id = 0; public Myframe(int x, int y,int w,int h,Color color){ super("我的"+(++id)); setVisible(true); //由于继承了frame,可以不用再写frame setBounds(x,y,w,h); setBackground(color); }}
Panel介绍
package com.adair.lesson01;import java.awt.*;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.awt.event.WindowListener;public class TestPanel { public static void main(String[] args) { frame frame = new frame(); Panel panel = new Panel(); frame.setLayout(null);//没有的话不显示frame frame.setBounds(100,100,500,500); frame.setBackground(new Color(245, 8, 74, 255)); panel.setBounds(50,50,400,400);//setLocation+setSize panel.setBackground(new Color(15, 23, 17)); frame.add(panel); frame.setVisible(true); //监听事件 frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) {// super.windowClosing(e); System.exit(0); } }); }}
布局管理
流式布局
package com.adair.lesson01;import java.awt.*;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;public class TestFlowLayout { public static void main(String[] args) { frame frame = new frame(); Button button1 = new Button("button1"); Button button2 = new Button("button2"); Button button3 = new Button("button3"); //流式布局 frame.setLayout(new FlowLayout(FlowLayout.LEFT)); frame.setSize(400,400); frame.add(button1); frame.add(button2); frame.add(button3); frame.setVisible(true); }}
东西南北中(视频的布局)
package com.adair.lesson01;import java.awt.*;public class TestBorderLayout { public static void main(String[] args) { frame frame = new frame("TestBorderLayout"); Button east = new Button("East"); Button west = new Button("West"); Button south = new Button("South"); Button north = new Button("North"); Button center = new Button("Center"); frame.add(east,BorderLayout.EAST); frame.add(west,BorderLayout.WEST); frame.add(south,BorderLayout.SOUTH); frame.add(north,BorderLayout.NORTH); frame.add(center,BorderLayout.CENTER); frame.setSize(400,400); frame.setVisible(true); }}
表格布局
package com.adair.lesson01;import java.awt.*;public class TestGridLayout { public static void main(String[] args) { frame frame = new frame("TestGridLayout"); Button button1 = new Button("East"); Button button2 = new Button("West"); Button button3 = new Button("South"); Button button4 = new Button("North"); Button button5 = new Button("Center"); Button button6 = new Button("6"); frame.setLayout(new GridLayout(3,2)); frame.add(button1); frame.add(button2); frame.add(button3); frame.add(button4); frame.add(button5); frame.add(button6); frame.pack();//以最优方式排列 frame.setVisible(true); }}
实战演练(Panel内嵌套button)
package com.adair.lesson01;import java.awt.*;public class TestGridLayout { public static void main(String[] args) { frame frame = new frame("TestGridLayout"); frame.setLayout(new GridLayout(2,1)); Panel panel1 = new Panel(new BorderLayout()); Panel panel2 = new Panel(new GridLayout(2,1)); Panel panel3 = new Panel(new BorderLayout()); Panel panel4 = new Panel(new GridLayout(2,2)); panel1.add(new Button("West-1"),BorderLayout.WEST); panel1.add(new Button("East-1"),BorderLayout.EAST); panel2.add(new Button("panel2-1")); panel2.add(new Button("panel2-2")); panel1.add(panel2,BorderLayout.CENTER); panel3.add(new Button("West-2"),BorderLayout.WEST); panel3.add(new Button("East-2"),BorderLayout.EAST); for (int i = 1; i < 5; i++) { panel4.add(new Button("for"+i)); } panel3.add(panel4,BorderLayout.CENTER); frame.add(panel1); frame.add(panel3); frame.pack();//以最优方式排列 frame.setVisible(true); }}
事件监听