diff --git a/.idea/MarsCodeWorkspaceAppSettings.xml b/.idea/MarsCodeWorkspaceAppSettings.xml
index e2a065b..a2d5776 100644
--- a/.idea/MarsCodeWorkspaceAppSettings.xml
+++ b/.idea/MarsCodeWorkspaceAppSettings.xml
@@ -1,6 +1,7 @@
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
index d19f3f8..caa579b 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -8,6 +8,10 @@
+
+
+
+
diff --git a/C06 Polymorphism/src/shape/Shape.java b/C06 Polymorphism/src/shape/Shape.java
index 6afc876..021857d 100644
--- a/C06 Polymorphism/src/shape/Shape.java
+++ b/C06 Polymorphism/src/shape/Shape.java
@@ -1,7 +1,7 @@
package shape;
import java.awt.*;
-public class Shape {
+public abstract class Shape {
protected Color color;
protected int x,y;
@@ -11,9 +11,7 @@ public class Shape {
public Color getColor() {
return color;
}
- public double getArea(){
- return x*y;
- }
+ public abstract double getArea();
public void setX(int x){
this.x=x;
@@ -29,9 +27,7 @@ public class Shape {
return y;
}
- public double getPerimeter(){
- return x*y;
- }
+ public abstract double getPerimeter();
public void move(int dx,int dy){
x += dx;
diff --git a/C08-SnackGame/C08-SnackGame.iml b/C08-SnackGame/C08-SnackGame.iml
new file mode 100644
index 0000000..c90834f
--- /dev/null
+++ b/C08-SnackGame/C08-SnackGame.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/C08-SnackGame/src/game/Direction.java b/C08-SnackGame/src/game/Direction.java
new file mode 100644
index 0000000..b7c7432
--- /dev/null
+++ b/C08-SnackGame/src/game/Direction.java
@@ -0,0 +1,17 @@
+package game;
+
+import java.awt.*;
+
+public enum Direction {
+ UP(new Point(0,-1)),
+ DOWN(new Point(0,1)),
+ LEFT(new Point(-1,0)),
+ RIGHT(new Point(1,0));
+ private Point offset;
+ Direction(Point offset) {
+ this.offset = offset;
+ }
+ public static Point getOffset(Direction dir) {
+ return dir.offset;
+ }
+}
diff --git a/C08-SnackGame/src/game/Drawable.java b/C08-SnackGame/src/game/Drawable.java
new file mode 100644
index 0000000..a2251f8
--- /dev/null
+++ b/C08-SnackGame/src/game/Drawable.java
@@ -0,0 +1,7 @@
+package game;
+
+import java.awt.*;
+
+public interface Drawable {
+ void draw(Graphics g);
+}
diff --git a/C08-SnackGame/src/game/Food.java b/C08-SnackGame/src/game/Food.java
new file mode 100644
index 0000000..d67fe7b
--- /dev/null
+++ b/C08-SnackGame/src/game/Food.java
@@ -0,0 +1,38 @@
+package game;
+
+import java.awt.*;
+import java.util.Random;
+
+public class Food extends GameElement{
+ private static Random randeom = new Random();
+ public Food(int width,int height) {
+ super(0,0);
+ randomPosition(width,height);
+ }
+
+ /**
+ * 随机设置位置坐标
+ * @param width 可用宽度范围
+ * @param height 可用高度范围
+ */
+ public void randomPosition(int width, int height) {
+ //计算一排或一列最多的格子数
+ int maxX = width/SIZE;
+ int maxY = height/SIZE;
+ //将位置坐标映射到像素点
+ int x = randeom.nextInt(maxX)*SIZE;
+ int y = randeom.nextInt(maxY)*SIZE;
+ //设置坐标
+ position.setLocation(x,y);
+ }
+ @Override
+ public void draw(Graphics g) {
+ //红色填充,黑色边框
+ g.setColor(Color.RED);
+ g.fillOval(position.x,position.y,SIZE,SIZE);
+
+ g.setColor(Color.BLACK);
+ g.drawOval(position.x,position.y,SIZE,SIZE);
+ }
+
+}
diff --git a/C08-SnackGame/src/game/GameElement.java b/C08-SnackGame/src/game/GameElement.java
new file mode 100644
index 0000000..bfcf574
--- /dev/null
+++ b/C08-SnackGame/src/game/GameElement.java
@@ -0,0 +1,15 @@
+package game;
+
+import java.awt.*;
+
+public abstract class GameElement {
+ protected Point position;
+ public static final int SIZE = 20;
+ protected GameElement(int x,int y) {
+ position = new Point(x,y);
+ }
+ public Point getPosition() {
+ return position;
+ }
+ public abstract void draw(Graphics g);
+}
diff --git a/C08-SnackGame/src/game/Movable.java b/C08-SnackGame/src/game/Movable.java
new file mode 100644
index 0000000..744da6e
--- /dev/null
+++ b/C08-SnackGame/src/game/Movable.java
@@ -0,0 +1,5 @@
+package game;
+
+public interface Movable {
+ void move();
+}
diff --git a/C08-SnackGame/src/game/SnakeNode.java b/C08-SnackGame/src/game/SnakeNode.java
new file mode 100644
index 0000000..251657d
--- /dev/null
+++ b/C08-SnackGame/src/game/SnakeNode.java
@@ -0,0 +1,31 @@
+package game;
+
+import java.awt.*;
+
+public class SnakeNode extends GameElement implements Movable{
+ private Direction direction;
+ public SnakeNode(int x, int y, Direction direction) {
+ super(x, y);
+ this.direction = direction;
+ }
+ public void setDirection(Direction direction) {
+ this.direction = direction;
+ }
+
+ @Override
+ public void draw(Graphics g) {
+ //绿色填充,黑色边框
+ g.setColor(Color.GREEN);
+ g.fillRect(position.x, position.y, SIZE, SIZE);
+ // 绘制边框,让蛇身更清晰
+ g.setColor(Color.BLACK);
+ g.drawRect(position.x, position.y, SIZE, SIZE);
+ }
+
+ @Override
+ public void move() {
+ Point offset = Direction.getOffset(direction);
+ position.x += offset.x*SIZE;
+ position.y += offset.y*SIZE;
+ }
+}
diff --git a/C08-SnackGame/src/view/GamePanel.java b/C08-SnackGame/src/view/GamePanel.java
new file mode 100644
index 0000000..1133002
--- /dev/null
+++ b/C08-SnackGame/src/view/GamePanel.java
@@ -0,0 +1,85 @@
+package view;
+
+import game.Direction;
+import game.Food;
+import game.SnakeNode;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+
+
+public class GamePanel extends JPanel {
+ private static final int WIDTH = 600;
+ private static final int HEIGHT = 600;
+ private boolean isRunning;
+ // FIXME 蛇身体节点 未来需要改进
+ private SnakeNode[] snakeBody = new SnakeNode[3];
+ private final Food food;
+
+
+ public GamePanel() {
+ setPreferredSize(new Dimension(WIDTH, HEIGHT));
+ setBackground(Color.WHITE); // 背景色设为白色
+
+ // FIXME 初始化蛇 未来需要改进
+ snakeBody[0] = new SnakeNode(100, 100, Direction.RIGHT);
+ snakeBody[1] = new SnakeNode(80, 100, Direction.RIGHT);
+ snakeBody[2] = new SnakeNode(60, 100, Direction.RIGHT);
+
+ food = new Food(WIDTH, HEIGHT);
+
+
+ // 键盘监听
+ addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyPressed(KeyEvent e) {
+ // TODO 按下按键后需要做处理
+ }
+ });
+ setFocusable(true); // 确保面板能接收键盘事件
+
+ // 游戏循环
+ new Thread(() -> {
+ while (isRunning) {
+ try {
+ Thread.sleep(250);
+ moveSnake(); // 移动蛇
+ checkCollision(); // 检查碰撞
+ repaint(); // 调用paintComponent重绘
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }).start();
+ }
+
+ private void moveSnake() {
+ // TODO
+ }
+
+ private void checkCollision() {
+ // TODO
+ }
+
+ private void gameOver() {
+ isRunning = false;
+ JOptionPane.showMessageDialog(this, "游戏结束!得分:");
+ System.exit(0);
+ }
+
+ // 核心改进:重写paintComponent而非paint,利用Swing双缓冲
+ @Override
+ protected void paintComponent(Graphics g) {
+ super.paintComponent(g); // 先绘制背景(双缓冲关键步骤)
+
+ // 绘制蛇
+ for (SnakeNode node : snakeBody) {
+ node.draw(g);
+ }
+
+ // 绘制食物
+ food.draw(g);
+ }
+}
\ No newline at end of file
diff --git a/C08-SnackGame/src/view/SnakeGame.java b/C08-SnackGame/src/view/SnakeGame.java
new file mode 100644
index 0000000..469511a
--- /dev/null
+++ b/C08-SnackGame/src/view/SnakeGame.java
@@ -0,0 +1,18 @@
+package view;
+
+import javax.swing.*;
+
+public class SnakeGame extends JFrame {
+ public SnakeGame() {
+ setTitle("贪吃蛇");
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ add(new GamePanel()); // 添加游戏面板
+ pack(); // 自动调整窗口大小以适应面板
+ setLocationRelativeTo(null); // 窗口居中
+ setVisible(true);
+ }
+
+ public static void main(String[] args) {
+ new SnakeGame();
+ }
+}
diff --git a/C09-Collection/C09-Collection.iml b/C09-Collection/C09-Collection.iml
new file mode 100644
index 0000000..c90834f
--- /dev/null
+++ b/C09-Collection/C09-Collection.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/C09-Collection/src/Josephus.java b/C09-Collection/src/Josephus.java
new file mode 100644
index 0000000..8fd594a
--- /dev/null
+++ b/C09-Collection/src/Josephus.java
@@ -0,0 +1,24 @@
+import java.util.*;
+public class Josephus {
+ public static void main(String[] args) {
+ Scanner sc = new Scanner(System.in);
+ int n = sc.nextInt();
+ ArrayList arr = new ArrayList<>();
+ for(int i=0;i2) {
+ Iterator it = arr.iterator();
+ while(it.hasNext()) {
+ it.next();
+ cnt++;
+ if(cnt==3) {
+ it.remove();
+ cnt = 0;
+ }
+ }
+ System.out.println(arr);
+ }
+ }
+}
diff --git a/C09-Collection/src/game/Direction.java b/C09-Collection/src/game/Direction.java
new file mode 100644
index 0000000..b7c7432
--- /dev/null
+++ b/C09-Collection/src/game/Direction.java
@@ -0,0 +1,17 @@
+package game;
+
+import java.awt.*;
+
+public enum Direction {
+ UP(new Point(0,-1)),
+ DOWN(new Point(0,1)),
+ LEFT(new Point(-1,0)),
+ RIGHT(new Point(1,0));
+ private Point offset;
+ Direction(Point offset) {
+ this.offset = offset;
+ }
+ public static Point getOffset(Direction dir) {
+ return dir.offset;
+ }
+}
diff --git a/C09-Collection/src/game/Drawable.java b/C09-Collection/src/game/Drawable.java
new file mode 100644
index 0000000..a2251f8
--- /dev/null
+++ b/C09-Collection/src/game/Drawable.java
@@ -0,0 +1,7 @@
+package game;
+
+import java.awt.*;
+
+public interface Drawable {
+ void draw(Graphics g);
+}
diff --git a/C09-Collection/src/game/Food.java b/C09-Collection/src/game/Food.java
new file mode 100644
index 0000000..d67fe7b
--- /dev/null
+++ b/C09-Collection/src/game/Food.java
@@ -0,0 +1,38 @@
+package game;
+
+import java.awt.*;
+import java.util.Random;
+
+public class Food extends GameElement{
+ private static Random randeom = new Random();
+ public Food(int width,int height) {
+ super(0,0);
+ randomPosition(width,height);
+ }
+
+ /**
+ * 随机设置位置坐标
+ * @param width 可用宽度范围
+ * @param height 可用高度范围
+ */
+ public void randomPosition(int width, int height) {
+ //计算一排或一列最多的格子数
+ int maxX = width/SIZE;
+ int maxY = height/SIZE;
+ //将位置坐标映射到像素点
+ int x = randeom.nextInt(maxX)*SIZE;
+ int y = randeom.nextInt(maxY)*SIZE;
+ //设置坐标
+ position.setLocation(x,y);
+ }
+ @Override
+ public void draw(Graphics g) {
+ //红色填充,黑色边框
+ g.setColor(Color.RED);
+ g.fillOval(position.x,position.y,SIZE,SIZE);
+
+ g.setColor(Color.BLACK);
+ g.drawOval(position.x,position.y,SIZE,SIZE);
+ }
+
+}
diff --git a/C09-Collection/src/game/GameElement.java b/C09-Collection/src/game/GameElement.java
new file mode 100644
index 0000000..bfcf574
--- /dev/null
+++ b/C09-Collection/src/game/GameElement.java
@@ -0,0 +1,15 @@
+package game;
+
+import java.awt.*;
+
+public abstract class GameElement {
+ protected Point position;
+ public static final int SIZE = 20;
+ protected GameElement(int x,int y) {
+ position = new Point(x,y);
+ }
+ public Point getPosition() {
+ return position;
+ }
+ public abstract void draw(Graphics g);
+}
diff --git a/C09-Collection/src/game/Movable.java b/C09-Collection/src/game/Movable.java
new file mode 100644
index 0000000..744da6e
--- /dev/null
+++ b/C09-Collection/src/game/Movable.java
@@ -0,0 +1,5 @@
+package game;
+
+public interface Movable {
+ void move();
+}
diff --git a/C09-Collection/src/game/SnakeNode.java b/C09-Collection/src/game/SnakeNode.java
new file mode 100644
index 0000000..556fa9e
--- /dev/null
+++ b/C09-Collection/src/game/SnakeNode.java
@@ -0,0 +1,34 @@
+package game;
+
+import java.awt.*;
+
+public class SnakeNode extends GameElement implements Movable{
+ private Direction direction;
+ public SnakeNode(int x, int y, Direction direction) {
+ super(x, y);
+ this.direction = direction;
+ }
+ public void setDirection(Direction direction) {
+ this.direction = direction;
+ }
+ public Direction getDirection() {
+ return direction;
+ }
+
+ @Override
+ public void draw(Graphics g) {
+ //绿色填充,黑色边框
+ g.setColor(Color.GREEN);
+ g.fillRect(position.x, position.y, SIZE, SIZE);
+ // 绘制边框,让蛇身更清晰
+ g.setColor(Color.BLACK);
+ g.drawRect(position.x, position.y, SIZE, SIZE);
+ }
+
+ @Override
+ public void move() {
+ Point offset = Direction.getOffset(direction);
+ position.x += offset.x*SIZE;
+ position.y += offset.y*SIZE;
+ }
+}
diff --git a/C09-Collection/src/view/GamePanel.java b/C09-Collection/src/view/GamePanel.java
new file mode 100644
index 0000000..70e50fe
--- /dev/null
+++ b/C09-Collection/src/view/GamePanel.java
@@ -0,0 +1,138 @@
+package view;
+
+import game.Direction;
+import game.Food;
+import game.GameElement;
+import game.SnakeNode;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.util.*;
+
+
+public class GamePanel extends JPanel {
+ private static final int WIDTH = 600;
+ private static final int HEIGHT = 600;
+ private boolean isRunning;
+ private LinkedList snakeBody = new LinkedList<>();
+ private final Food food;
+ private int score = 0;
+
+
+ public GamePanel() {
+ setPreferredSize(new Dimension(WIDTH, HEIGHT));
+ setBackground(Color.WHITE); // 背景色设为白色
+ isRunning = true;
+ snakeBody.add(new SnakeNode(100, 100, Direction.RIGHT));
+ snakeBody.add(new SnakeNode(80, 100, Direction.RIGHT));
+ snakeBody.add(new SnakeNode(60, 100, Direction.RIGHT));
+
+ food = new Food(WIDTH, HEIGHT);
+
+
+ // 键盘监听
+ addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyPressed(KeyEvent e) {
+ Direction currentDir = snakeBody.getFirst().getDirection();
+ switch(e.getKeyCode()){
+ case KeyEvent.VK_UP: {
+ if (currentDir != Direction.DOWN)
+ snakeBody.getFirst().setDirection(Direction.UP);
+ break;
+ }
+ case KeyEvent.VK_DOWN: {
+ if (currentDir != Direction.UP)
+ snakeBody.getFirst().setDirection(Direction.DOWN);
+ break;
+ }
+ case KeyEvent.VK_LEFT: {
+ if (currentDir != Direction.RIGHT)
+ snakeBody.getFirst().setDirection(Direction.LEFT);
+ break;
+ }
+ case KeyEvent.VK_RIGHT: {
+ if (currentDir != Direction.LEFT)
+ snakeBody.getFirst().setDirection(Direction.RIGHT);
+ break;
+ }
+ default:
+ System.out.println("位置案件");
+ }
+ }
+ });
+ setFocusable(true); // 确保面板能接收键盘事件
+
+ // 游戏循环
+ new Thread(() -> {
+ while (isRunning) {
+ try {
+ Thread.sleep(50);
+ moveSnake(); // 移动蛇
+ checkCollision(); // 检查碰撞
+ repaint(); // 调用paintComponent重绘
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }).start();
+ }
+
+ private void moveSnake() {
+ //获取蛇头
+ SnakeNode head = snakeBody.getFirst();
+ Point offset = Direction.getOffset(head.getDirection());
+ //(x',y')=(x,y)+offset*SIZE
+ int xNew= head.getPosition().x+offset.x*GameElement.SIZE;
+ int yNew= head.getPosition().y+offset.y*GameElement.SIZE;
+ //在新位置添加蛇头
+ snakeBody.addFirst(new SnakeNode(xNew, yNew, head.getDirection()));
+ //判断是否吃到食物
+ if(head.getPosition().equals(food.getPosition())){
+ //吃到食物
+ food.randomPosition(WIDTH, HEIGHT);
+ score++;
+ }
+ //删除蛇尾
+ else {
+ snakeBody.removeLast();
+ }
+ }
+
+ private void checkCollision() {
+ SnakeNode head = snakeBody.getFirst();
+ Point headPos = head.getPosition();
+ //撞墙
+ if(headPos.x<0||headPos.x>WIDTH||headPos.y<0||headPos.y>HEIGHT)
+ gameOver();
+ //撞自己
+ for(int i=1;i
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/C10-Swing/src/Main.java b/C10-Swing/src/Main.java
new file mode 100644
index 0000000..b30de3d
--- /dev/null
+++ b/C10-Swing/src/Main.java
@@ -0,0 +1,7 @@
+import view.LoginFrame;
+
+public class Main {
+ public static void main(String[] args) {
+ new LoginFrame();
+ }
+}
diff --git a/C10-Swing/src/utils/CaptchaUtils.java b/C10-Swing/src/utils/CaptchaUtils.java
new file mode 100644
index 0000000..1e2178d
--- /dev/null
+++ b/C10-Swing/src/utils/CaptchaUtils.java
@@ -0,0 +1,54 @@
+package utils;
+
+import java.util.Random;
+
+/**
+ * 验证码工具类
+ */
+public class CaptchaUtils { // final修饰类:不能被继承
+ // 【任务1】静态常量:字符集(全局固定)
+ static final String CHAR_SET="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+
+ // 【任务2】静态常量:验证码长度(全局固定)
+ static final int CAPTCHA_LENGTH=4;
+
+ // 【任务3】私有构造方法:禁止创建实例(工具类无需实例化)
+ private CaptchaUtils(){
+ }
+
+ /**
+ * 【任务4】
+ * 静态方法:generateCaptcha 生成随机验证码
+ * @return String 返回生成的随机验证码字符串
+ */
+ public static String generateCaptcha(){
+ Random random = new Random();
+ //生成随机验证码
+ StringBuilder sb = new StringBuilder();
+ for(int i=0;i
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/C11-Swing/src/Main.java b/C11-Swing/src/Main.java
new file mode 100644
index 0000000..b30de3d
--- /dev/null
+++ b/C11-Swing/src/Main.java
@@ -0,0 +1,7 @@
+import view.LoginFrame;
+
+public class Main {
+ public static void main(String[] args) {
+ new LoginFrame();
+ }
+}
diff --git a/C11-Swing/src/common/LoginStatus.java b/C11-Swing/src/common/LoginStatus.java
new file mode 100644
index 0000000..cacb5d3
--- /dev/null
+++ b/C11-Swing/src/common/LoginStatus.java
@@ -0,0 +1,74 @@
+package common;
+
+/**
+ * 登录状态枚举类
+ * 用final保证状态信息不可变,用static提供工具方法
+ */
+ public enum LoginStatus {
+ // 【任务3】枚举实例:状态码和描述
+ // 成功登录
+ SUCCESS(200,"登录成功"),
+ // 密码错误
+ PASSWORD_ERROR(901,"密码错误"),
+ // 验证码错误
+ CAPTCHA_ERROR(902,"验证码错误"),
+ // 用户不存在
+ USER_NOT_FOUND(903,"用户不存在");
+
+
+
+ // 【任务1】定义 final修饰的属性:确保状态信息不可修改
+ private final int code;
+ private final String msg;
+
+
+
+ /**
+ * 【任务2】
+ * 构造函数,用于创建LoginStatus实例
+ * @param code 状态码
+ * @param msg 状态消息
+ */
+ LoginStatus(int code, String msg) {
+ this.code = code;
+ this.msg = msg;
+ }
+
+ // 静态方法:根据状态码获取枚举实例(static工具方法)
+ /**
+ * 【任务4】
+ * 静态方法: getByCode 根据状态码获取对应的登录状态枚举值
+ * @param code 状态码
+ * @return LoginStatus 对应的LoginStatus枚举值,如果找不到匹配的状态码则返回null
+ */
+ public static LoginStatus getByCode(int code){
+ for(LoginStatus status:values()){
+ if(status.code==code){
+ return status;
+ }
+ }
+ return null;
+ }
+
+ // getter方法(final属性无需setter)
+ /**
+ * 【任务5】
+ * 方法: getCode 获取code值
+ *
+ * @return int code值
+ */
+ public int getCode() {
+ return code;
+ }
+
+ /**
+ * 任务【6】
+ * 方法: getMsg 获取消息内容
+ *
+ * @return String 返回当前对象的消息字符串
+ */
+ public String getMsg() {
+ return msg;
+ }
+ }
+
diff --git a/C11-Swing/src/po/AccountPo.java b/C11-Swing/src/po/AccountPo.java
new file mode 100644
index 0000000..67a6546
--- /dev/null
+++ b/C11-Swing/src/po/AccountPo.java
@@ -0,0 +1,22 @@
+package po;
+
+public class AccountPo {
+ private String username;
+ private String password;
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+}
diff --git a/C11-Swing/src/service/AuthService.java b/C11-Swing/src/service/AuthService.java
new file mode 100644
index 0000000..43fbee5
--- /dev/null
+++ b/C11-Swing/src/service/AuthService.java
@@ -0,0 +1,27 @@
+package service;
+
+import common.LoginStatus;
+import po.AccountPo;
+
+public class AuthService {
+ private static AccountPo dbAccount = new AccountPo();
+
+ static {
+ dbAccount.setUsername("admin");
+ dbAccount.setPassword("123456");
+ }
+
+ public LoginStatus login(AccountPo account) {
+ //1.获取用户输入的账号在数据库中查询该账号信息
+ //2.账号不存在
+ //3.账号存在 比较密码是否一致
+ if (dbAccount.getUsername().equals(account.getUsername()) &&
+ dbAccount.getPassword().equals(account.getPassword()))
+ return LoginStatus.SUCCESS;
+ else if (!dbAccount.getUsername().equals(account.getUsername())) {
+ return LoginStatus.USER_NOT_FOUND;
+ }
+ return LoginStatus.PASSWORD_ERROR;
+ }
+}
+
diff --git a/C11-Swing/src/utils/CaptchaUtils.java b/C11-Swing/src/utils/CaptchaUtils.java
new file mode 100644
index 0000000..1e2178d
--- /dev/null
+++ b/C11-Swing/src/utils/CaptchaUtils.java
@@ -0,0 +1,54 @@
+package utils;
+
+import java.util.Random;
+
+/**
+ * 验证码工具类
+ */
+public class CaptchaUtils { // final修饰类:不能被继承
+ // 【任务1】静态常量:字符集(全局固定)
+ static final String CHAR_SET="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+
+ // 【任务2】静态常量:验证码长度(全局固定)
+ static final int CAPTCHA_LENGTH=4;
+
+ // 【任务3】私有构造方法:禁止创建实例(工具类无需实例化)
+ private CaptchaUtils(){
+ }
+
+ /**
+ * 【任务4】
+ * 静态方法:generateCaptcha 生成随机验证码
+ * @return String 返回生成的随机验证码字符串
+ */
+ public static String generateCaptcha(){
+ Random random = new Random();
+ //生成随机验证码
+ StringBuilder sb = new StringBuilder();
+ for(int i=0;i {
+ //点击注册按钮后的事件
+ String username = usernameTextField.getText();
+ String password = passwordField.getText();
+ String captcha = captchaTextField.getText();
+ //System.out.println("用户名" + username + " 密码" + password + " 验证码" + captcha);
+ if(username.equals("")||password.equals("")||captcha.equals("")) {
+ JOptionPane.showMessageDialog(this, "请填写完整信息!", "提示", JOptionPane.INFORMATION_MESSAGE);
+ return;
+ }
+ if(!CaptchaUtils.verifyCaptcha(captcha,captchaLabel.getText())){
+ JOptionPane.showMessageDialog(this, LoginStatus.CAPTCHA_ERROR.getMsg(), "提示", JOptionPane.INFORMATION_MESSAGE);
+ return;
+ }
+ AccountPo account = new AccountPo();
+ account.setUsername(username);
+ account.setPassword(password);
+ LoginStatus loginStatus = authService.login(account);
+ if(loginStatus == LoginStatus.SUCCESS) {
+ //进入主界面
+ MainFrame mainFrame = new MainFrame();
+ this.dispose();
+ }
+ else if(loginStatus == LoginStatus.USER_NOT_FOUND) {
+ JOptionPane.showMessageDialog(this, LoginStatus.USER_NOT_FOUND.getMsg(), "提示", JOptionPane.INFORMATION_MESSAGE);
+ return;
+ }
+ else if(loginStatus == LoginStatus.PASSWORD_ERROR) {
+ JOptionPane.showMessageDialog(this, LoginStatus.PASSWORD_ERROR.getMsg(), "提示", JOptionPane.INFORMATION_MESSAGE);
+ return;
+ }
+ else{
+ JOptionPane.showMessageDialog(this, loginStatus.getMsg(), "提示", JOptionPane.INFORMATION_MESSAGE);
+ }
+ });
+ registerButton.addActionListener(e -> {
+ //点击注册按钮后的事件
+ return;
+ });
+ }
+ private JPanel initPanel(){
+ mainPanel = new JPanel();
+ GridLayout gridLayout = new GridLayout(6,1,10,10);
+ mainPanel.setLayout(gridLayout);
+ //第1层 空白面板 占用
+ mainPanel.add(new JPanel());
+ //第2层 账号面板
+ mainPanel.add(initAcountPanel());
+ //第3层 密码面板
+ mainPanel.add(initPasswordPanel());
+ //第4层 验证码面板
+ mainPanel.add(initCaptchaPanel());
+ //第5层 按钮面板
+ mainPanel.add(initButtonPanel());
+ //第6层 空白面板 占用
+ return mainPanel;
+ }
+ /**
+ * 初始化账户信息面板
+ * @return 包含用户名输入框的面板组件
+ */
+ private JPanel initAcountPanel(){
+ JPanel panel = new JPanel();
+ panel.setLayout(new GridLayout(1,4,10,0));
+ JLabel label = new JLabel("用户名:");
+ //让label居右
+ label.setHorizontalAlignment(SwingConstants.RIGHT);
+ usernameTextField = new JTextField(15);
+ panel.add(label);
+ panel.add(usernameTextField);
+ panel.add(new JPanel());
+ return panel;
+ }
+
+ /**
+ * 初始化密码输入面板
+ * @return 包含密码标签和输入框的JPanel面板
+ */
+ private JPanel initPasswordPanel(){
+ JPanel panel = new JPanel();
+ // 设置网格布局,1行4列,水平间距10像素
+ panel.setLayout(new GridLayout(1,4,10,0));
+ JLabel label = new JLabel("密 码:");
+ // 设置标签文本右对齐
+ label.setHorizontalAlignment(SwingConstants.RIGHT);
+ passwordField = new JPasswordField(15);
+ panel.add(label);
+ panel.add(passwordField);
+ // 添加空白面板占位
+ panel.add(new JPanel());
+ return panel;
+ }
+
+
+ /**
+ * 初始化验证码面板
+ *
+ * @return 包含验证码相关组件的JPanel面板
+ */
+ private JPanel initCaptchaPanel(){
+ // 创建面板并设置网格布局
+ JPanel panel = new JPanel();
+ panel.setLayout(new GridLayout(1,4,10,0));
+
+ // 创建验证码标签
+ JLabel label = new JLabel("验证码:");
+ label.setHorizontalAlignment(SwingConstants.RIGHT);
+
+ // 创建验证码输入框和验证码显示标签
+ captchaTextField = new JTextField(4);
+ captchaLabel = new JLabel(CaptchaUtils.generateCaptcha());
+
+ // 将组件添加到面板中
+ panel.add(label);
+ panel.add(captchaTextField);
+ panel.add(captchaLabel);
+
+ return panel;
+ }
+
+
+ private JPanel initButtonPanel(){
+ JPanel panel = new JPanel();
+ panel.setLayout(new GridLayout(1,4,10,0));
+ loginButton = new JButton("登录");
+ registerButton = new JButton("注册");
+ panel.add(new JPanel());
+ panel.add(loginButton);
+ panel.add(registerButton);
+ panel.add(new JPanel());
+ return panel;
+ }
+
+
+
+}
diff --git a/C11-Swing/src/view/MainFrame.java b/C11-Swing/src/view/MainFrame.java
new file mode 100644
index 0000000..2f99eba
--- /dev/null
+++ b/C11-Swing/src/view/MainFrame.java
@@ -0,0 +1,7 @@
+package view;
+
+import javax.swing.*;
+
+public class MainFrame {
+ JFrame frame = new JFrame();
+}
diff --git a/out/production/C07 StaticAndEnum/CaptchaUtils.class b/out/production/C07 StaticAndEnum/CaptchaUtils.class
new file mode 100644
index 0000000..29097c8
Binary files /dev/null and b/out/production/C07 StaticAndEnum/CaptchaUtils.class differ
diff --git a/out/production/C07 StaticAndEnum/LoginStatus.class b/out/production/C07 StaticAndEnum/LoginStatus.class
new file mode 100644
index 0000000..e29a614
Binary files /dev/null and b/out/production/C07 StaticAndEnum/LoginStatus.class differ
diff --git a/out/production/C07 StaticAndEnum/Test.class b/out/production/C07 StaticAndEnum/Test.class
new file mode 100644
index 0000000..d917c5c
Binary files /dev/null and b/out/production/C07 StaticAndEnum/Test.class differ
diff --git a/out/production/C08-SnackGame/game/Direction.class b/out/production/C08-SnackGame/game/Direction.class
new file mode 100644
index 0000000..8e81cf6
Binary files /dev/null and b/out/production/C08-SnackGame/game/Direction.class differ
diff --git a/out/production/C08-SnackGame/game/Drawable.class b/out/production/C08-SnackGame/game/Drawable.class
new file mode 100644
index 0000000..8207395
Binary files /dev/null and b/out/production/C08-SnackGame/game/Drawable.class differ
diff --git a/out/production/C08-SnackGame/game/Food.class b/out/production/C08-SnackGame/game/Food.class
new file mode 100644
index 0000000..cd45b6b
Binary files /dev/null and b/out/production/C08-SnackGame/game/Food.class differ
diff --git a/out/production/C08-SnackGame/game/GameElement.class b/out/production/C08-SnackGame/game/GameElement.class
new file mode 100644
index 0000000..e2d5fc4
Binary files /dev/null and b/out/production/C08-SnackGame/game/GameElement.class differ
diff --git a/out/production/C08-SnackGame/game/Movable.class b/out/production/C08-SnackGame/game/Movable.class
new file mode 100644
index 0000000..f275f04
Binary files /dev/null and b/out/production/C08-SnackGame/game/Movable.class differ
diff --git a/out/production/C08-SnackGame/game/SnakeNode.class b/out/production/C08-SnackGame/game/SnakeNode.class
new file mode 100644
index 0000000..58b9cd6
Binary files /dev/null and b/out/production/C08-SnackGame/game/SnakeNode.class differ
diff --git a/out/production/C08-SnackGame/view/GamePanel$1.class b/out/production/C08-SnackGame/view/GamePanel$1.class
new file mode 100644
index 0000000..f27e661
Binary files /dev/null and b/out/production/C08-SnackGame/view/GamePanel$1.class differ
diff --git a/out/production/C08-SnackGame/view/GamePanel.class b/out/production/C08-SnackGame/view/GamePanel.class
new file mode 100644
index 0000000..bf1c095
Binary files /dev/null and b/out/production/C08-SnackGame/view/GamePanel.class differ
diff --git a/out/production/C08-SnackGame/view/SnakeGame.class b/out/production/C08-SnackGame/view/SnakeGame.class
new file mode 100644
index 0000000..c6087af
Binary files /dev/null and b/out/production/C08-SnackGame/view/SnakeGame.class differ
diff --git a/out/production/C09-Collection/Josephus.class b/out/production/C09-Collection/Josephus.class
new file mode 100644
index 0000000..fc06148
Binary files /dev/null and b/out/production/C09-Collection/Josephus.class differ
diff --git a/out/production/C09-Collection/game/Direction.class b/out/production/C09-Collection/game/Direction.class
new file mode 100644
index 0000000..8e81cf6
Binary files /dev/null and b/out/production/C09-Collection/game/Direction.class differ
diff --git a/out/production/C09-Collection/game/Drawable.class b/out/production/C09-Collection/game/Drawable.class
new file mode 100644
index 0000000..8207395
Binary files /dev/null and b/out/production/C09-Collection/game/Drawable.class differ
diff --git a/out/production/C09-Collection/game/Food.class b/out/production/C09-Collection/game/Food.class
new file mode 100644
index 0000000..cd45b6b
Binary files /dev/null and b/out/production/C09-Collection/game/Food.class differ
diff --git a/out/production/C09-Collection/game/GameElement.class b/out/production/C09-Collection/game/GameElement.class
new file mode 100644
index 0000000..e2d5fc4
Binary files /dev/null and b/out/production/C09-Collection/game/GameElement.class differ
diff --git a/out/production/C09-Collection/game/Movable.class b/out/production/C09-Collection/game/Movable.class
new file mode 100644
index 0000000..f275f04
Binary files /dev/null and b/out/production/C09-Collection/game/Movable.class differ
diff --git a/out/production/C09-Collection/game/SnakeNode.class b/out/production/C09-Collection/game/SnakeNode.class
new file mode 100644
index 0000000..38520d6
Binary files /dev/null and b/out/production/C09-Collection/game/SnakeNode.class differ
diff --git a/out/production/C09-Collection/view/GamePanel$1.class b/out/production/C09-Collection/view/GamePanel$1.class
new file mode 100644
index 0000000..f35fe32
Binary files /dev/null and b/out/production/C09-Collection/view/GamePanel$1.class differ
diff --git a/out/production/C09-Collection/view/GamePanel.class b/out/production/C09-Collection/view/GamePanel.class
new file mode 100644
index 0000000..2f96e6d
Binary files /dev/null and b/out/production/C09-Collection/view/GamePanel.class differ
diff --git a/out/production/C09-Collection/view/SnakeGame.class b/out/production/C09-Collection/view/SnakeGame.class
new file mode 100644
index 0000000..c6087af
Binary files /dev/null and b/out/production/C09-Collection/view/SnakeGame.class differ
diff --git a/out/production/C10-Swing/Main.class b/out/production/C10-Swing/Main.class
new file mode 100644
index 0000000..2479c1d
Binary files /dev/null and b/out/production/C10-Swing/Main.class differ
diff --git a/out/production/C10-Swing/utils/CaptchaUtils.class b/out/production/C10-Swing/utils/CaptchaUtils.class
new file mode 100644
index 0000000..ac0ea0a
Binary files /dev/null and b/out/production/C10-Swing/utils/CaptchaUtils.class differ
diff --git a/out/production/C10-Swing/view/LoginFrame.class b/out/production/C10-Swing/view/LoginFrame.class
new file mode 100644
index 0000000..a7563a3
Binary files /dev/null and b/out/production/C10-Swing/view/LoginFrame.class differ
diff --git a/out/production/C11-Swing/Main.class b/out/production/C11-Swing/Main.class
new file mode 100644
index 0000000..2479c1d
Binary files /dev/null and b/out/production/C11-Swing/Main.class differ
diff --git a/out/production/C11-Swing/common/LoginStatus.class b/out/production/C11-Swing/common/LoginStatus.class
new file mode 100644
index 0000000..af2400f
Binary files /dev/null and b/out/production/C11-Swing/common/LoginStatus.class differ
diff --git a/out/production/C11-Swing/po/AccountPo.class b/out/production/C11-Swing/po/AccountPo.class
new file mode 100644
index 0000000..0d135e8
Binary files /dev/null and b/out/production/C11-Swing/po/AccountPo.class differ
diff --git a/out/production/C11-Swing/service/AuthService.class b/out/production/C11-Swing/service/AuthService.class
new file mode 100644
index 0000000..91c2e41
Binary files /dev/null and b/out/production/C11-Swing/service/AuthService.class differ
diff --git a/out/production/C11-Swing/utils/CaptchaUtils.class b/out/production/C11-Swing/utils/CaptchaUtils.class
new file mode 100644
index 0000000..ac0ea0a
Binary files /dev/null and b/out/production/C11-Swing/utils/CaptchaUtils.class differ
diff --git a/out/production/C11-Swing/view/LoginFrame$1.class b/out/production/C11-Swing/view/LoginFrame$1.class
new file mode 100644
index 0000000..38828fa
Binary files /dev/null and b/out/production/C11-Swing/view/LoginFrame$1.class differ
diff --git a/out/production/C11-Swing/view/LoginFrame.class b/out/production/C11-Swing/view/LoginFrame.class
new file mode 100644
index 0000000..9c9f5f8
Binary files /dev/null and b/out/production/C11-Swing/view/LoginFrame.class differ
diff --git a/out/production/C11-Swing/view/MainFrame.class b/out/production/C11-Swing/view/MainFrame.class
new file mode 100644
index 0000000..f55e96e
Binary files /dev/null and b/out/production/C11-Swing/view/MainFrame.class differ