diff --git a/01_Intellij_Java_universal_20240419/01_Intellij_Java_universal_20240419.iml b/01_Intellij_Java_universal_20240419/01_Intellij_Java_universal_20240419.iml
new file mode 100644
index 0000000..3620b19
--- /dev/null
+++ b/01_Intellij_Java_universal_20240419/01_Intellij_Java_universal_20240419.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/01_Intellij_Java_universal_20240419/untitled/file2.txt b/01_Intellij_Java_universal_20240419/untitled/file2.txt
deleted file mode 100644
index 2ef2887..0000000
--- a/01_Intellij_Java_universal_20240419/untitled/file2.txt
+++ /dev/null
@@ -1 +0,0 @@
-7153-767-7764-9819-6754-3453-9423-86-5411-7717-9489-5214-5481-6695-8273
\ No newline at end of file
diff --git a/01_Intellij_Java_universal_20240419/untitled/src/javaAssignment_20240528/Customer.java b/01_Intellij_Java_universal_20240419/untitled/src/javaAssignment_20240528/Customer.java
index e1b816b..736535b 100644
--- a/01_Intellij_Java_universal_20240419/untitled/src/javaAssignment_20240528/Customer.java
+++ b/01_Intellij_Java_universal_20240419/untitled/src/javaAssignment_20240528/Customer.java
@@ -6,36 +6,31 @@
package javaAssignment_20240528;
-public class Customer implements Runnable{
+public class Customer implements Runnable {
// 用户姓名
private String customerName;
// 存取次数
- private int customerNum;
+ private int customerNum = 3;
// 构造函数
- public Customer (String customerName){
- this.customerName = customerName;
- }
+ // public Customer (String customerName){
+ // this.customerName = customerName;
+ // }
// 重写 run 方法
@Override
- public void run (){
+ public void run() {
// 重复指定次数
- for (int i = 0; i < this.customerNum; i++){
+ for (int i = 0; i < this.customerNum; i++) {
// 输出用户存款信息
- System.out.println("User: " + this.customerName + " Deposit 100");
+ System.out.println("User: " + Thread.currentThread().getName() + " Deposit 100");
// 调用存款方法
deposit(100);
}
}
// 存款方法
- private synchronized void deposit (int amount){
+ private synchronized void deposit(int amount) {
Bank.Funds(amount);
}
-
- // 设置存款次数
- public void setDepositNum(int num){
- this.customerNum = num;
- }
-}
+}
\ No newline at end of file
diff --git a/01_Intellij_Java_universal_20240419/untitled/src/javaAssignment_20240528/test.java b/01_Intellij_Java_universal_20240419/untitled/src/javaAssignment_20240528/test.java
index 8febc67..3882605 100644
--- a/01_Intellij_Java_universal_20240419/untitled/src/javaAssignment_20240528/test.java
+++ b/01_Intellij_Java_universal_20240419/untitled/src/javaAssignment_20240528/test.java
@@ -39,22 +39,17 @@ public class test {
* Class
* 1. Bank.java
* 2. Customer.java
- *
+ */
// 通过 Bank 类实例化 b_1 对象
Bank b_1 = new Bank("Best Nigger Bank");
// 通过 Customer 实例化两个用户对象
- Customer c_1 = new Customer("Todd");
- Customer c_2 = new Customer("KoDick");
-
- // 调用其中的方法设置每个人的存款次数
- c_1.setDepositNum(3);
- c_2.setDepositNum(3);
+ Customer c_1 = new Customer();
// 通过 Thread 实例化两个线程类
- Thread t_1 = new Thread(c_1);
- Thread t_2 = new Thread(c_2);
+ Thread t_1 = new Thread(c_1, "Todd");
+ Thread t_2 = new Thread(c_1, "Todd Copy");
// 在开始存款前输出一次银行当前的余额
System.out.println("Now Bank Balance: " + b_1.getBankBalance());
@@ -74,6 +69,6 @@ public class test {
// 输出当前银行余额
System.out.println("Now Bank Balance: " + b_1.getBankBalance());
- */
+ /**/
}
}
diff --git a/01_Intellij_Java_universal_20240419/untitled/src/javaAssignment_20240614/function_01.java b/01_Intellij_Java_universal_20240419/untitled/src/javaAssignment_20240614/function_01.java
new file mode 100644
index 0000000..827d1ef
--- /dev/null
+++ b/01_Intellij_Java_universal_20240419/untitled/src/javaAssignment_20240614/function_01.java
@@ -0,0 +1,62 @@
+/*
+ * Function: Java 课程实验 六 - 题目 01
+ * Date: 2024 06 14
+ * Code by: JRNitre
+ * */
+
+package javaAssignment_20240614;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+public class function_01 extends Frame implements ActionListener{
+
+ Label userLabel, passLabel;
+ TextField userField;
+ JPasswordField passField;
+ Button loginButton;
+
+ public function_01() {
+ // 设置窗口属性
+ setTitle("User Login");
+ setSize(300, 200);
+ // setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ setLayout(new FlowLayout());
+
+ // 添加组件
+ userLabel = new Label("User Id:");
+ add(userLabel);
+ userField = new TextField(15);
+ add(userField);
+
+ passLabel = new Label("Password:");
+ add(passLabel);
+ passField = new JPasswordField(15);
+ add(passField);
+
+ loginButton = new Button("Login");
+ loginButton.addActionListener(this);
+ add(loginButton);
+
+ setVisible(true);
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ if (e.getSource() == loginButton) {
+ String username = userField.getText();
+ String password = new String(passField.getPassword());
+ if (isValidUser(username, password)) {
+ dispose(); // 关闭当前窗口
+ JOptionPane.showMessageDialog(null, "Login Done!");
+ } else {
+ JOptionPane.showMessageDialog(null, "Error!");
+ }
+ }
+ }
+
+ private boolean isValidUser(String username, String password) {
+ return "user".equals(username) && "pass".equals(password);
+ }
+}
diff --git a/01_Intellij_Java_universal_20240419/untitled/src/javaAssignment_20240614/function_02.java b/01_Intellij_Java_universal_20240419/untitled/src/javaAssignment_20240614/function_02.java
new file mode 100644
index 0000000..c10840a
--- /dev/null
+++ b/01_Intellij_Java_universal_20240419/untitled/src/javaAssignment_20240614/function_02.java
@@ -0,0 +1,96 @@
+/*
+ * Function: Java 课程实验 六 - 题目 02
+ * Date: 2024 06 14
+ * Code by: JRNitre
+ * */
+
+package javaAssignment_20240614;
+
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import javax.swing.*;
+
+public class function_02 extends JFrame {
+ JLabel num1Label, num2Label, resultLabel;
+ JTextField num1Field, num2Field, resultField;
+ JComboBox operationComboBox;
+ JButton calculateButton;
+
+ public function_02() {
+ super("计算器");
+
+ // 初始化组件
+ num1Label = new JLabel("数字1:");
+ num2Label = new JLabel("数字2:");
+ resultLabel = new JLabel("结果:");
+ num1Field = new JTextField(10);
+ num2Field = new JTextField(10);
+ resultField = new JTextField(10);
+ resultField.setEditable(false); // 结果字段不可编辑
+ operationComboBox = new JComboBox<>(new String[]{"+", "-", "*", "/"});
+ calculateButton = new JButton("计算");
+
+ // 添加动作监听器
+ calculateButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ calculate();
+ }
+ });
+
+ // 设置布局
+ setLayout(new GridLayout(4, 2));
+
+ // 添加组件到窗口
+ add(num1Label);
+ add(num1Field);
+ add(num2Label);
+ add(num2Field);
+ add(new JLabel()); // 空白占位
+ add(operationComboBox);
+ add(resultLabel);
+ add(resultField);
+ add(new JLabel()); // 空白占位
+ add(calculateButton);
+
+ // 设置窗口属性
+ setSize(300, 150);
+ setDefaultCloseOperation(EXIT_ON_CLOSE);
+ setLocationRelativeTo(null); // 居中显示
+ setVisible(true);
+ }
+
+ private void calculate() {
+ try {
+ double num1 = Double.parseDouble(num1Field.getText());
+ double num2 = Double.parseDouble(num2Field.getText());
+ String operation = (String) operationComboBox.getSelectedItem();
+ double result = 0;
+
+ switch (operation) {
+ case "+":
+ result = num1 + num2;
+ break;
+ case "-":
+ result = num1 - num2;
+ break;
+ case "*":
+ result = num1 * num2;
+ break;
+ case "/":
+ if (num2 != 0)
+ result = num1 / num2;
+ else {
+ JOptionPane.showMessageDialog(this, "除数不能为0!");
+ return;
+ }
+ break;
+ }
+
+ resultField.setText(String.valueOf(result));
+ } catch (NumberFormatException ex) {
+ JOptionPane.showMessageDialog(this, "请输入有效的数字!");
+ }
+ }
+}
diff --git a/01_Intellij_Java_universal_20240419/untitled/src/javaAssignment_20240614/function_03.java b/01_Intellij_Java_universal_20240419/untitled/src/javaAssignment_20240614/function_03.java
new file mode 100644
index 0000000..fad2d14
--- /dev/null
+++ b/01_Intellij_Java_universal_20240419/untitled/src/javaAssignment_20240614/function_03.java
@@ -0,0 +1,62 @@
+/*
+ * Function: Java 课程实验 六 - 题目 03
+ * Date: 2024 06 14
+ * Code by: JRNitre
+ * */
+
+package javaAssignment_20240614;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+
+public class function_03 {
+
+ public function_03(){
+ SwingUtilities.invokeLater(() -> {
+ createAndShowGUI();
+ });
+ }
+
+ private static void createAndShowGUI() {
+ JFrame frame = new JFrame("选项事件处理");
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.setLayout(new FlowLayout());
+
+ JTextArea textArea = new JTextArea("选顶事件ItemEvent的使用方法", 6, 20);
+ textArea.setEditable(false);
+ frame.add(textArea);
+
+ JRadioButton redButton = new JRadioButton("红色");
+ JRadioButton blueButton = new JRadioButton("蓝色");
+
+ ButtonGroup group = new ButtonGroup();
+ group.add(redButton);
+ group.add(blueButton);
+
+ ItemListener itemListener = new ItemListener() {
+ @Override
+ public void itemStateChanged(ItemEvent e) {
+ if (e.getStateChange() == ItemEvent.SELECTED) {
+ Object source = e.getSource();
+
+ if (source == redButton) {
+ textArea.setForeground(Color.RED);
+ } else if (source == blueButton) {
+ textArea.setForeground(Color.BLUE);
+ }
+ }
+ }
+ };
+
+ redButton.addItemListener(itemListener);
+ blueButton.addItemListener(itemListener);
+
+ frame.add(redButton);
+ frame.add(blueButton);
+
+ frame.pack();
+ frame.setVisible(true);
+ }
+}
diff --git a/01_Intellij_Java_universal_20240419/untitled/src/javaAssignment_20240614/test.java b/01_Intellij_Java_universal_20240419/untitled/src/javaAssignment_20240614/test.java
new file mode 100644
index 0000000..e612c03
--- /dev/null
+++ b/01_Intellij_Java_universal_20240419/untitled/src/javaAssignment_20240614/test.java
@@ -0,0 +1,49 @@
+/*
+ * Function: Java 课程实验 六
+ * Date: 2024 06 14
+ * Code by: JRNitre
+ * */
+
+package javaAssignment_20240614;
+
+public class test {
+ public static void main (String[] args){
+
+ /*
+ * 设计实现一个用户登录页面,当单击登录按钮用户名密码正确跳转到计算页面。
+ *
+ * Class: function_01.java
+ *
+
+ function_01 f_1 = new function_01();
+
+ */
+
+ /* ( つ•̀ω•́)つ :-D */
+
+ /*
+ * 设计实现一个计算页面,实现两个数的加法、减法、乘法和除法运算。
+ *
+ * Class: function_02.java
+ *
+
+ function_02 f_2 = new function_02();
+
+ */
+
+ /* ( つ•̀ω•́)つ :-D */
+
+ /*
+ * 编写一个应用程序,标题为“选项事件处理”的窗口,窗口布局为FlowLayout。
+ * 设计两个单选按钮,一个文本区。
+ * 单击单选按钮时,将文本区中的文字设置成为相应颜色的字体。
+ *
+ * Class: function_03.java
+ *
+
+ function_03 f_3 = new function_03();
+
+ */
+
+ }
+}
diff --git a/01_Intellij_Java_universal_20240419/untitled/src/javaPackage_20240524/function.java b/01_Intellij_Java_universal_20240419/untitled/src/javaPackage_20240524/function.java
index 402715f..ff7659f 100644
--- a/01_Intellij_Java_universal_20240419/untitled/src/javaPackage_20240524/function.java
+++ b/01_Intellij_Java_universal_20240419/untitled/src/javaPackage_20240524/function.java
@@ -1,10 +1,14 @@
package javaPackage_20240524;
+import java.io.*;
import java.security.SecureRandom;
public class function {
+ // 数组长度
private int ArrayMaxLength;
+ private String fileName;
+
public int[] createRandomArray(int num, int min, int max){
this.ArrayMaxLength = num;
int[] array = new int[this.ArrayMaxLength];
@@ -12,7 +16,76 @@ public class function {
for (int i = 0; i < this.ArrayMaxLength; i++){
array[i] = min + secureRandom.nextInt(max - min + 1);
}
+ System.out.println("Create Random Array Done!");
return array;
}
+ public void createFile (String fileName){
+ this.fileName = fileName;
+ File file = new File(fileName);
+ try {
+ if (file.createNewFile()){
+ System.out.println("Create file Done!");
+ } else {
+ System.out.println("Create file Error!");
+ }
+ } catch (IOException ioe){
+ System.out.println("Create file Error!");
+ ioe.printStackTrace();
+ }
+ }
+
+ public void writeFile (String data){
+ try {
+ BufferedWriter writer = new BufferedWriter(new FileWriter(this.fileName));
+ writer.write(data);
+ writer.close();
+ System.out.println("Writer Done!");
+ } catch (IOException ioe){
+ System.out.println("Writer Error!");
+ }
+ }
+
+ public int[] readeFileToInt(){
+ try {
+ BufferedReader reader = new BufferedReader(new FileReader(this.fileName));
+ String line = reader.readLine();
+
+ String[] arrayStr = line.split("-");
+
+ int[] arrayInt = new int[this.ArrayMaxLength];
+ for (int i = 0; i < this.ArrayMaxLength; i++){
+ arrayInt[i] = Integer.parseInt(arrayStr[i]);
+ }
+ System.out.println("Reader File Done!");
+ return arrayInt;
+ } catch (IOException ioe){
+ System.out.println("Reader File Error!");
+ return new int[0];
+ }
+ }
+
+ public void bubbleSort(int[] array){
+ int m = array.length;
+
+ for (int i = 0; i < m; i++){
+ for (int j = 0; j < m - i - 1; i++){
+ if (array[j] > array[j+1]){
+ int temp = array[j];
+ array[j] = array[j + 1];
+ array[j + 1] = temp;
+ }
+ }
+ }
+
+ System.out.println("Sort Done!");
+
+ for (int k = 0; k < m; k++){
+ System.out.print(array[k]);
+ if (k != m - 1){
+ System.out.print(" - ");
+ }
+ }
+ }
+
}
diff --git a/01_Intellij_Java_universal_20240419/untitled/src/javaPackage_20240524/test.java b/01_Intellij_Java_universal_20240419/untitled/src/javaPackage_20240524/test.java
index 776aa33..a965183 100644
--- a/01_Intellij_Java_universal_20240419/untitled/src/javaPackage_20240524/test.java
+++ b/01_Intellij_Java_universal_20240419/untitled/src/javaPackage_20240524/test.java
@@ -7,8 +7,21 @@ public class test {
* 2. 利用 BufferedWriter 类将其写入文件 file2.txt 中
* 3. 读取该文件中的数据并升序排序
*/
- function f_1 = new function();
+ function f_1 = new function();
- f_1.createRandomArray(15, 20, 9999);
+ int array[] = f_1.createRandomArray(15, 20, 9999);
+
+ f_1.createFile("file2.txt");
+ StringBuilder s_1 = new StringBuilder();
+ for (int i = 0; i < array.length; i++){
+ s_1.append(array[i]);
+ if (i != array.length - 1){
+ s_1.append("-");
+ }
+ }
+
+ f_1.writeFile(s_1.toString());
+
+ f_1.bubbleSort(f_1.readeFileToInt());
}
}
diff --git a/01_Intellij_Java_universal_20240419/untitled/src/javaPackage_20240531/bank.java b/01_Intellij_Java_universal_20240419/untitled/src/javaPackage_20240531/bank.java
new file mode 100644
index 0000000..bf2d123
--- /dev/null
+++ b/01_Intellij_Java_universal_20240419/untitled/src/javaPackage_20240531/bank.java
@@ -0,0 +1,19 @@
+package javaPackage_20240531;
+
+public class bank {
+ private static int money;
+
+ private String bankNmae;
+
+ public bank (String name){
+ this.bankNmae = name;
+ }
+
+ public int getMoney(){
+ return money;
+ }
+
+ public static synchronized void add (int n){
+ money += n;
+ }
+}
diff --git a/01_Intellij_Java_universal_20240419/untitled/src/javaPackage_20240531/customer.java b/01_Intellij_Java_universal_20240419/untitled/src/javaPackage_20240531/customer.java
new file mode 100644
index 0000000..993cec3
--- /dev/null
+++ b/01_Intellij_Java_universal_20240419/untitled/src/javaPackage_20240531/customer.java
@@ -0,0 +1,19 @@
+package javaPackage_20240531;
+
+public class customer implements Runnable{
+
+ private static final int num = 3;
+
+ @Override
+ public void run(){
+ for (int i = 0; i < num; i++){
+ System.out.println("User: " + Thread.currentThread().getName() + " add 100");
+ customerAdd(100);
+ }
+ }
+
+ public synchronized void customerAdd(int n){
+ bank.add(n);
+ }
+
+}
diff --git a/01_Intellij_Java_universal_20240419/untitled/src/javaPackage_20240531/test.java b/01_Intellij_Java_universal_20240419/untitled/src/javaPackage_20240531/test.java
new file mode 100644
index 0000000..85a796d
--- /dev/null
+++ b/01_Intellij_Java_universal_20240419/untitled/src/javaPackage_20240531/test.java
@@ -0,0 +1,28 @@
+package javaPackage_20240531;
+
+public class test {
+ public static void main (String[] args){
+ /*
+ * 1. 设某家银行可接受用户的存款,每进行一次存款,便可计算出存款的总额。
+ * 2. 现有两名顾客,每人分3次、每次存入100元。
+ */
+
+ bank b = new bank("Bank");
+ customer c = new customer();
+
+ Thread t_1 = new Thread(c, "todd");
+ Thread t_2 = new Thread(c, "Copy todd");
+
+ System.out.println("Now Bank: " + b.getMoney());
+
+ t_1.start();
+ t_2.start();
+
+ try {
+ t_1.join();
+ t_2.join();
+ } catch (Exception e){}
+
+ System.out.println("Now Bank: " + b.getMoney());
+ }
+}
diff --git a/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/.idea/.gitignore b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/.idea/.gitignore
new file mode 100644
index 0000000..359bb53
--- /dev/null
+++ b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/.idea/.gitignore
@@ -0,0 +1,3 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
diff --git a/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/.idea/encodings.xml b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/.idea/encodings.xml
new file mode 100644
index 0000000..d114ec5
--- /dev/null
+++ b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/.idea/encodings.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/.idea/misc.xml b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/.idea/misc.xml
new file mode 100644
index 0000000..07115cd
--- /dev/null
+++ b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/.idea/modules.xml b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/.idea/modules.xml
new file mode 100644
index 0000000..432e247
--- /dev/null
+++ b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/.idea/uiDesigner.xml b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/.idea/vcs.xml b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/.idea/vcs.xml
new file mode 100644
index 0000000..b2bdec2
--- /dev/null
+++ b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/CourseExperiment.iml b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/CourseExperiment.iml
new file mode 100644
index 0000000..b2f27ce
--- /dev/null
+++ b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/CourseExperiment.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/lib/mysql-connector-j-8.4.0.jar b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/lib/mysql-connector-j-8.4.0.jar
new file mode 100644
index 0000000..8294fe0
Binary files /dev/null and b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/lib/mysql-connector-j-8.4.0.jar differ
diff --git a/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/ElmAdminEntry.java b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/ElmAdminEntry.java
new file mode 100644
index 0000000..812ae0a
--- /dev/null
+++ b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/ElmAdminEntry.java
@@ -0,0 +1,118 @@
+
+import View.AdminView;
+import View.Display;
+import po.Admin;
+
+import java.io.IOException;
+import java.util.Scanner;
+import java.util.stream.StreamSupport;
+
+public class ElmAdminEntry {
+ public static void main(String[] args){
+ new ElmAdminEntry().work();
+ }
+
+ public void work(){
+
+ Integer mistake = 0;
+ Integer maxMistake = 3;
+ Integer errorCode = 0;
+ Integer mainExitCode = 0;
+
+ Scanner sca = new Scanner(System.in);
+ AdminView adminView = new AdminView();
+ Display dis = new Display('+', '-', 30);
+
+ while (mistake < maxMistake && mainExitCode == 0){
+ dis.titleLine("¼ ǫ̂ϵͳ", true);
+ if (mistake != 0){
+ System.out.println("+ ǰ: " + mistake + " ʣ: " + (maxMistake - mistake));
+ }
+ System.out.print("+ ˻: ");
+ String userInputAdminName = sca.next();
+ System.out.print("+ : ");
+ String userInputAdminPassworld = sca.next();
+
+ Admin admin = adminView.login(userInputAdminName, userInputAdminPassworld);
+
+ if (admin != null){
+ int key = -1;
+ while (key != 10){
+
+ dis.titleLine("Admin - " + admin.getAdminName(), true);
+ dis.showItem("[0] ̼б", true);
+ dis.showItem("[1] ̼", true);
+ dis.showItem("[2] ½̼", true);
+ dis.showItem("[3] ɾ̼", true);
+ dis.showItem("[4] 鿴ԱϢ", true);
+ dis.showItem("[5] ùԱ", true);
+ dis.showItem("[10] ˳ϵͳ", true);
+ dis.showLine(true);
+
+ System.out.print("+ ӦIJ: ");
+ key = sca.nextInt();
+
+ switch (key){
+ case 0:
+ break;
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ // TODO nextLine
+ dis.titleLine("ԱϢ", true);
+ System.out.println("+ Ա ID:\t" + admin.getAdminId());
+ System.out.println("+ Ա:\t" + admin.getAdminName());
+ System.out.println("+ Ա:\t" + admin.getAdminPassword());
+ sca.nextLine();
+ break;
+ case 5:
+ dis.titleLine("ùԱ", true);
+ System.out.print("+ 뵱ǰ: ");
+ String newPassword = sca.next();
+
+ if (!(newPassword.equals(admin.getAdminPassword()))){
+ dis.titleLine("ERROR", true);
+ System.out.println("벻һ!");
+ break;
+ }
+
+ // TODO У
+ System.out.println("+ : ");
+ newPassword = sca.next();
+
+ admin.setAdminPassword(newPassword);
+ adminView.updatePassword(admin);
+ break;
+
+ case 10:
+ errorCode = 2;
+ mainExitCode = 1;
+ break;
+ default:
+ dis.titleLine("ERROR", true);
+ System.out.println("+ Ϸ!");
+ break;
+ }
+ }
+ } else {
+ mistake++;
+ }
+ if (mistake >= maxMistake){
+ errorCode = 1;
+ }
+ }
+
+ if (errorCode == 1){
+ dis.titleLine("ERROR", true);
+ System.out.println("+ ࣬˳ϵͳ!");
+ System.exit(0);
+ }
+ if (errorCode == 2){
+ dis.titleLine("ʾ", true);
+ System.out.println("+ ϵͳ˳");
+ System.exit(0);
+ }
+
+ }
+}
diff --git a/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/View/AdminView.java b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/View/AdminView.java
new file mode 100644
index 0000000..9eb60b0
--- /dev/null
+++ b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/View/AdminView.java
@@ -0,0 +1,22 @@
+package View;
+
+import dao.AdminDaoImpl;
+import po.Admin;
+
+import java.util.Scanner;
+
+public class AdminView {
+ public Admin login(String name, String passworld){
+ Admin admin = null;
+
+ admin = new AdminDaoImpl().getAdminByNameByPass(name, passworld);
+
+ return admin;
+ }
+
+ public void updatePassword(Admin admin){
+ System.out.println("+ ...");
+
+ new AdminDaoImpl().updateAdminPassword(admin);
+ }
+}
diff --git a/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/View/Display.java b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/View/Display.java
new file mode 100644
index 0000000..b044d4d
--- /dev/null
+++ b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/View/Display.java
@@ -0,0 +1,70 @@
+package View;
+
+public class Display {
+
+ private char displayNode;
+ private char displayLine;
+
+ private Integer displayWidth;
+
+ public Display (char node, char line, Integer width){
+ displayNode = node;
+ displayLine = line;
+ displayWidth = width;
+ }
+
+ public void setWidth(Integer width){
+ displayWidth = width;
+ }
+
+ public void titleLine (String title, boolean newLine){
+ StringBuilder str = new StringBuilder();
+
+ Integer space = (displayWidth - title.length() - 2) / 2;
+
+ str.append(displayNode);
+ for (int i = 0; i < space; i++){
+ str.append(displayLine);
+ }
+ str.append(title);
+ for (int i = 0; i < space; i++){
+ str.append(displayLine);
+ }
+ str.append(displayNode);
+
+ System.out.print(str.toString());
+ if (newLine){
+ System.out.println();
+ }
+ }
+
+ public void showItem(String item, boolean newLine){
+ StringBuilder str = new StringBuilder();
+
+ str.append(displayNode).append(" ");
+ str.append(item);
+
+ Integer space = displayWidth - 1 - ("+ ".length() + item.length());
+
+ System.out.print(str.toString());
+ if (newLine){
+ System.out.println();
+ }
+ }
+
+ public void showLine(boolean newLine){
+ StringBuilder str = new StringBuilder();
+
+ str.append(displayNode);
+ for (int i = 0; i < displayWidth - 2; i++){
+ str.append(displayLine);
+ }
+ str.append(displayNode);
+
+ System.out.print(str.toString());
+ if (newLine){
+ System.out.println();
+ }
+ }
+
+}
diff --git a/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/dao/AdminDao.java b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/dao/AdminDao.java
new file mode 100644
index 0000000..51fde0c
--- /dev/null
+++ b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/dao/AdminDao.java
@@ -0,0 +1,9 @@
+package dao;
+
+import po.Admin;
+
+public interface AdminDao {
+ Admin getAdminByNameByPass(String adminName, String password);
+
+ void updateAdminPassword(Admin admin);
+}
diff --git a/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/dao/AdminDaoImpl.java b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/dao/AdminDaoImpl.java
new file mode 100644
index 0000000..01eb623
--- /dev/null
+++ b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/dao/AdminDaoImpl.java
@@ -0,0 +1,76 @@
+package dao;
+
+import jdbc.JDBC;
+import po.Admin;
+
+import java.sql.*;
+
+public class AdminDaoImpl implements AdminDao{
+// @Override
+// public Admin getAdminByNameByPass(String adminName, String password){
+// Map map = AdminMap.ADMIN_MAP;//ȡйԱ
+// Collection values = map.values();//ȡmapֵļ
+//
+// //ֵļϣжǷƺƥ䣬Уʾ¼ɹ
+// Admin admin = null;
+// for(Admin tmp : values ) {
+// if(tmp.getAdminName().equals(adminName) && tmp.getAdminPassworld().equals(password)) {
+// admin = tmp;
+// break;
+// }
+// }
+//
+// return admin;
+// }
+
+ @Override
+ public Admin getAdminByNameByPass(String adminName, String password) {
+ Admin admin = null;
+ try {
+ // ݿ
+ Connection conn = JDBC.getConnection();
+ Statement stmt = conn.createStatement();
+
+ String sql = "SELECT * FROM admin WHERE adminName = '" + adminName + "' AND adminPassword = '" + password + "'";
+
+ ResultSet rs = stmt.executeQuery(sql);
+
+ if (rs.next()) {
+ admin = new Admin();
+ admin.setAdminId(rs.getInt("adminId"));
+ admin.setAdminName(rs.getString("adminName"));
+ admin.setAdminPassword(rs.getString("adminPassword"));
+ }
+
+ conn.close();
+ stmt.close();
+ rs.close();
+ } catch (SQLException e) {
+ System.err.println("Database error occurred: " + e.getMessage());
+ } catch (Exception e) {
+ System.err.println("Unexpected error: " + e.getMessage());
+ }
+ return admin;
+ }
+
+ @Override
+ public void updateAdminPassword(Admin admin) {
+ // TODO ¹
+ try {
+ Connection conn = JDBC.getConnection();
+ Statement stmt = conn.createStatement();
+ System.out.println("+ ӵݿ");
+
+ String sql = "UPDATE admin SET adminPassword = ?";
+ PreparedStatement pst = conn.prepareStatement(sql);
+ pst.setString(1, admin.getAdminPassword());
+ pst.executeUpdate();
+ System.out.println("+ ");
+
+ stmt.close();
+ conn.close();
+ } catch (Exception e) {
+ System.err.println("Unexpected error: " + e.getMessage());
+ }
+ }
+}
diff --git a/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/data/AdminMap.java b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/data/AdminMap.java
new file mode 100644
index 0000000..9b77e0a
--- /dev/null
+++ b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/data/AdminMap.java
@@ -0,0 +1,15 @@
+package data;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import po.Admin;
+
+public class AdminMap {
+ public static final Map ADMIN_MAP = new HashMap<>();
+
+ static {
+ ADMIN_MAP.put(1, new Admin(1, "jrnitre", "123"));
+ }
+
+}
diff --git a/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/jdbc/JDBC.java b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/jdbc/JDBC.java
new file mode 100644
index 0000000..001d6e0
--- /dev/null
+++ b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/jdbc/JDBC.java
@@ -0,0 +1,23 @@
+package jdbc;
+
+import po.Admin;
+
+import java.beans.Expression;
+import java.sql.*;
+
+public class JDBC {
+
+ private static final String URL = "jdbc:mysql://124.220.110.170:3306/jrnitre";
+ private static final String user = "jrnitre";
+ private static final String Password = "npgt1365";
+
+ public static Connection getConnection() {
+ try {
+ Class.forName("com.mysql.cj.jdbc.Driver");
+ return DriverManager.getConnection(URL, user, Password);
+ } catch (ClassNotFoundException | SQLException e) {
+ e.printStackTrace();
+ throw new RuntimeException("ݿʧ", e);
+ }
+ }
+}
diff --git a/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/po/Admin.java b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/po/Admin.java
new file mode 100644
index 0000000..d3529ea
--- /dev/null
+++ b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/po/Admin.java
@@ -0,0 +1,45 @@
+package po;
+
+public class Admin {
+ // 管理员 ID
+ private Integer adminId;
+ // 管理员名
+ private String adminName;
+ // 管理员密码
+ private String adminPassword;
+
+ public Admin (Integer id, String name, String passworld){
+ super();
+ adminId = id;
+ adminName = name;
+ adminPassword = passworld;
+ }
+
+ public Admin (){
+ super();
+ }
+
+ public Integer getAdminId(){
+ return adminId;
+ }
+
+ public String getAdminName(){
+ return adminName;
+ }
+
+ public String getAdminPassword(){
+ return adminPassword;
+ }
+
+ public void setAdminId(Integer id){
+ adminId = id;
+ }
+
+ public void setAdminName(String name){
+ adminName = name;
+ }
+
+ public void setAdminPassword(String password){
+ adminPassword = password;
+ }
+}
diff --git a/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/po/Business.java b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/po/Business.java
new file mode 100644
index 0000000..5a78bfd
--- /dev/null
+++ b/02_Intellij_Java_CourseExperiment_20240611/CourseExperiment/src/po/Business.java
@@ -0,0 +1,4 @@
+package po;
+
+public class Business {
+}