Update the doc

This commit is contained in:
icecat 2025-04-01 16:08:40 +08:00
parent 4f9f346777
commit 648cf00b4f
12 changed files with 179 additions and 2 deletions

View File

@ -172,7 +172,7 @@ static类名可调用static修饰的方法对于抽象方法无意义
可以通过子类进行访问 可以通过子类进行访问
4.抽象类的子类 4.抽象类的子类
要么重写所有抽象方法,要么本身就是抽象类 要么重写所有抽象方法,要么本身就是抽象类
@ -422,3 +422,132 @@ class im implements inter{
## 窗体,组件,事件: ## 窗体,组件,事件:
```java
package com.icecat.frame;
/*
.*意思补充,意为加载前者类下所有的包
*/
import javax.swing.*;
public class FrameTest1 {
public static void main(String[] args) {
// 创建窗体对象
JFrame frame = new JFrame();
// 设置窗体尺寸
frame.setSize(1920,1080);
// 设置窗体关闭模式可以直接写数字123.WindowConstants.EXIT_ON_CLOSE=3意思是关闭窗口同时关闭java虚拟机。如果不写默认为隐藏窗口
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
// 设置标题
frame.setTitle("猫瑾醒了吗丶到窗体一游");
// 设置窗体可见 注意:一定要最后设置窗体可见,要让在此之前的图片按钮的功能加载好后最后展示窗体
frame.setVisible(true);
}
}
```
效果展示:
<img src="https://gitee.com/icecat2233/picture/raw/master/20250324154900925.png" alt="image-20250324154858456" style="zoom:50%;" />
### 窗体添加按钮:
```java
package com.icecat.frame;
import javax.swing.*;
/*
JButton构造方法
public JButton():创建一个空白按钮
public JButton(String text):创建一个带文本的按钮
*/
public class JbuttonTest1 {
public static void main(String[] args) {
JFrame frame = new JFrame();
// 设置按钮前需要先取消按钮默认布局
frame.setLayout(null);
// 创建按钮对象
JButton btn = new JButton("不要点我");
// 设置按钮位置以及大小
btn.setBounds(175,225,100,100);
// 将按钮添加到窗体的(面板对象)中
frame.getContentPane().add(btn);
frame.setSize(400,500);
frame.setDefaultCloseOperation(3);
frame.setVisible(true);
}
}
```
### 窗体添加图片,文字:
```java
package com.icecat.frame;
import javax.swing.*;
public class JlableTest1 {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(1200,1000);
frame.setDefaultCloseOperation(3);
frame.setLayout(null);
// Jlable展示文本和图片 先创建Jlabel对象
// 1.展示文本
JLabel jl1 = new JLabel("薇尔莉特");
jl1.setBounds(100,50,60,60);
frame.getContentPane().add(jl1);
JLabel jl2 = new JLabel("小鸟游六花");
jl2.setBounds(160,50,80,60);
frame.getContentPane().add(jl2);
// 2展示图像
JLabel jl1_1jpg = new JLabel(new ImageIcon("D:\\Develop\\Advanced-codes\\day09-codes\\src\\com\\icecat\\可愛い.jpg"));
jl1_1jpg.setBounds(100,110,690,690);
frame.getContentPane().add(jl1_1jpg);
// 展示窗体
frame.setVisible(true);
}
}
```
![image-20250324163631116](https://gitee.com/icecat2233/picture/raw/master/20250324163633329.png)
### 事件监听:
分为两个
#### ActionListener:动作监听
![image-20250324171058759](https://gitee.com/icecat2233/picture/raw/master/20250324171225177.png)
#### KeyListener键盘监听
![image-20250324171222985](https://gitee.com/icecat2233/picture/raw/master/20250324171229810.png)
#### 注意事项
1**其中键盘监听中:**
如何确定键盘录入按键ASCII码
并且第一个keyTyped方法不常用因为有些方法监听不到
2**监听冲突问题**
焦点:程序的注意力集中在了某一组件上
注意:按钮组件比较特殊,创建好后就自动聚焦,但是并不需要,还可能会和键盘监听起冲突问题
可以通过:`setFocusable(false)`来取消焦点
![image-20250327162545003](https://gitee.com/icecat2233/picture/raw/master/20250327162557075.png)
### 适配器设计模式
<img src="https://gitee.com/icecat2233/picture/raw/master/20250327165831119.png" alt="image-20250327163802452" style="zoom:67%;" />
### 模板设计模式
<img src="https://gitee.com/icecat2233/picture/raw/master/20250327165828578.png" alt="image-20250327165742040" style="zoom:67%;" />
**优势:已经定义了通用结构,使用者只需关心自己需要实现的功能即可**

View File

@ -4,6 +4,8 @@
此文档目前仅记录了javaSE内容较为基础适合很初级的人去看后续会继续提交更新的笔记会持续更新 此文档目前仅记录了javaSE内容较为基础适合很初级的人去看后续会继续提交更新的笔记会持续更新
java基础部分结束后后续内容会一个重点一个文档的形式进行更新最新为常用api
![可愛い](https://gitee.com/icecat2233/picture/raw/master/20250321231214432.jpg) ![可愛い](https://gitee.com/icecat2233/picture/raw/master/20250321231214432.jpg)
![image-20250321231558551](https://gitee.com/icecat2233/picture/raw/master/20250321231909450.png) <img src="https://gitee.com/icecat2233/picture/raw/master/20250321231909450.png" alt="image-20250321231558551" style="zoom:67%;" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

46
常用api.md Normal file
View File

@ -0,0 +1,46 @@
# 常用API
## Object类
### toString方法
`public String toString()`默认是返回当前对象再堆内存中的地址信息:类的全类名@十六进制哈希值
#### 用途:
在开发过程中直接输出对象看到对象地址是毫无意义的,更多时候是希望看到对象中的内容数据而不是假地址信息
所以toString()方法存在的意义就是为了被子类重写,以便返回对象的内容信息,而不是地址信息。
### equals方法
`public boolean equals(Object 0)`默认是比较当前对象与另一对象地址值是否相同返回boolean类型
#### 意义:
父类equals方法存在的意义就是为了子类重写以便于子类自己定制比较规则
**IDEA中重写的equals方法**
```java
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Student student = (Student) o;
return age == student.age && Objects.equals(name, student.name);
}
```
### **Objects类中的equals方法**
避免了空指针异常问题
```java
public static boolean equals(Object a, Object b) {
return (a == b) || (a != null && a.equals(b));
}
```
&&或者双||都是执行左边若为false或者true则右侧不执行
![image-20250401155734366](https://gitee.com/icecat2233/picture/raw/master/20250401155745359.png)