【JAVA】穷词——基于嵌入式的数据库derby+BeautyEye的单词字典应用

news2024/10/7 20:29:19

文章目录

    • 1. 题目
    • 2. 项目结构层次
    • 3. 环境以及技术栈说明
    • 4. 项目报告
      • 4.1软件功能描述
      • 4.2项目类图
        • 4.2.1 `src`层级下的类图
        • 4.2.2 `data`层级下的类图
        • 4.2.3 `gui`层级下的类图
        • 4.2.4 `resource`层级下的类图
        • 4.2.5 `view`层级下的类图
        • 4.2.6 `DelWord`的类图
        • 4.2.7 `CustomMessageDialog`的类图
        • 4.2.8 `RoundBorder`的类图
        • 4.2.9 `AddWordView`的类图
        • 4.2.10 `BackgroundPanel`的类图
        • 4.2.11 `DeleteWordView`的类图
        • 4.2.12 `HandleAddWord`的类图
        • 4.2.13 `HandleDelWord`的类图
        • 4.2.14 `HandleQueryAllWord`的类图
        • 4.2.15 `HandleQueryOneWord`的类图
        • 4.2.16 `HandleRandomQueryWord`的类图
        • 4.2.17 `HandleUpdateWord`的类图
        • 4.2.18 `IntergrationView`的类图
        • 4.2.19 `QueryAllWordView`的类图
        • 4.2.20 `QueryOneWordView`的类图
        • 4.2.21 `RandomQueryView`的类图
        • 4.2.22 `UpdateWordView`的类图
      • 4.3 运行效果截图
        • 4.3.1 页面UI
        • 4.3.2 运行样例
      • 4.4 技术说明
      • 4.5 改进说明
    • 5. 全部源码(很多注释)
      • 5.1 AddWord.java
      • 5.2 ConnectDatabase.java
      • 5.3 CreateDatabaseAndTable.java
      • 5.4 DelWord.java
      • 5.5 QueryAllWord.java
      • 5.6 QueryOneWord.java
      • 5.7 RandomQueryWord.java
      • 5.8 UpdateWord.java
      • 5.9 Word.java
      • 5.10 AppWindow.java
      • 5.11 CustomMessageDialog.java
      • 5.12 FontLoader.java
      • 5.13 RoundBorder.java
      • 5.14 AddWordView.java
      • 5.15 BackgroundPanel.java
      • 5.16 DelWordView.java
      • 5.17 HandleAddWord.java
      • 5.18 HandleDelWord.java
      • 5.19 HandleQueryAllWord.java
      • 5.20 HandleQueryOneWord.java
      • 5.21 HandleRandomQueryWord.java
      • 5.22 HandleUpdateWord.java
      • 5.23 IntegrationView.java
      • 5.24 QueryAllWordView.java
      • 5.25 QueryOneWordView.java
      • 5.26 RandomQueryView.java
      • 5.27 UpdateWordView.java
    • 结语

1. 题目

应用面向对象技术,参考《Java 面向对象程序设计》第3版第17章《基于嵌入式数据库的单词字典》程序,改进一个系统。


2. 项目结构层次

简单目录说明:

  • 该项目所有的依赖库在FianlDesign/lib文件下包括BeautyEyeApache Derby
  • FinalDesign/src文件夹主要是存放.java源文件的
  • FinalDesign/img文件夹存放该项目所需的图片.png
  • FianlDesign/font文件夹存放外部字体,该项目所用的字体统一为 阿里妈妈黑体
├─.idea
│  │  .gitignore
│  │  misc.xml
│  │  modules.xml
│  │  workspace.xml
│  │  
│  └─libraries
│          .xml
│          
├─fonts
│      Alimama.otf
│      Alimama.ttf
│      
├─img
│      addVoca.png
│      BCG.png
│      deleteVoca.png
│      queryAllVoca.png
│      queryOneVoca.png
│      queryRandomVoca.png
│      updateVoca.png
│      穷词logo.png
│      
├─lib
│      beautyeye_lnf.jar
│      derby.jar
│      
├─MyEnglishBook
│  │  db.lck
│  │  README_DO_NOT_TOUCH_FILES.txt
│  │  service.properties
│  │  
│  ├─log
│  │      log.ctrl
│  │      log1.dat
│  │      logmirror.ctrl
│  │      README_DO_NOT_TOUCH_FILES.txt
│  │      
│  ├─seg0
│  │      c10.dat
│  │      ..........
│  │      README_DO_NOT_TOUCH_FILES.txt
│  │      
│  └─tmp
├─out
│  └─production
│      └─FinalDesign
│                      
└─src
    ├─data
    │      AddWord.java
    │      ConnectDatabase.java
    │      CreateDatabaseAndTable.java
    │      DelWord.java
    │      QueryAllWord.java
    │      QueryOneWord.java
    │      RandomQueryWord.java
    │      UpdateWord.java
    │      Word.java
    │      
    ├─gui
    │      AppWindow.java
    │      
    ├─resource
    │      CustomMessageDialog.java
    │      FontLoader.java
    │      RoundBorder.java
    │      
    └─view
            AddWordView.java
            BackgroundPanel.java
            DelWordView.java
            HandleAddWord.java
            HandleDelWord.java
            HandleQueryAllWord.java
            HandleQueryOneWord.java
            HandleRandomQueryWord.java
            HandleUpdateWord.java
            IntegrationView.java
            QueryAllWordView.java
            QueryOneWordView.java
            RandomQueryView.java
            UpdateWordView.java


3. 环境以及技术栈说明

JDK请使用1.8版本的,若版本不一很可能会引发两个依赖库BeautyEyeDerby的冲突,具体展示如下图
在这里插入图片描述
该项目涉及的技术栈:

  1. Apache Derby()
  2. BeautyEye
  3. JAVA Swing

使用的集成开放环境是idea


4. 项目报告

4.1软件功能描述

  • 项目名称: 穷词-基于嵌入式的数据库的单词字典

  • 实验内容: 使用derby+BeautyEye来完成一个单词字典的软件开发

  • 软件功能描述: 用户可以使用该软件来达到使用本地字典的功能,随着时间的推移和数据库中不断新增的记录,这个字典会越来越完善,如今具有添加单词修改单词删除单词查询一个单词浏览全部单词随机查看单词。这六个功能,页面UI整体是以武侠为主线。

4.2项目类图

先展示的是src层级下的各个大类的类图

4.2.1 src层级下的类图

在这里插入图片描述

4.2.2 data层级下的类图

4.2.3 gui层级下的类图

4.2.4 resource层级下的类图

在这里插入图片描述

4.2.5 view层级下的类图

在这里插入图片描述

接下来展示各个子类的类图,若该子类的类图只有自己则不会展示

4.2.6 DelWord的类图

在这里插入图片描述

4.2.7 CustomMessageDialog的类图

4.2.8 RoundBorder的类图

4.2.9 AddWordView的类图

在这里插入图片描述

4.2.10 BackgroundPanel的类图

在这里插入图片描述

4.2.11 DeleteWordView的类图

在这里插入图片描述

4.2.12 HandleAddWord的类图

在这里插入图片描述

4.2.13 HandleDelWord的类图

在这里插入图片描述

4.2.14 HandleQueryAllWord的类图

在这里插入图片描述

4.2.15 HandleQueryOneWord的类图

在这里插入图片描述

4.2.16 HandleRandomQueryWord的类图

在这里插入图片描述

4.2.17 HandleUpdateWord的类图

在这里插入图片描述

4.2.18 IntergrationView的类图

在这里插入图片描述

4.2.19 QueryAllWordView的类图

在这里插入图片描述

4.2.20 QueryOneWordView的类图

在这里插入图片描述

4.2.21 RandomQueryView的类图

在这里插入图片描述

4.2.22 UpdateWordView的类图

在这里插入图片描述

4.3 运行效果截图

4.3.1 页面UI

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

4.3.2 运行样例

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

4.4 技术说明

这个软件总体是按照MVC模式来进行设计的。

  1. 符合单一原则(Single Responsibility Principle一个类只负责一个职责,如AddWordView等职责都是创建添加单词页面视图等,而HandleAddWord等职责都是负责控制页面视图和提交到数据库等;
  2. 符合开闭原则(Open Close Principle)对拓展开放对修改关闭;
  3. 符合里氏替换原则(Liskov Substitution Principle),没有子类覆盖父类的抽象方法,只有实现其抽象方法,并且子类可以增加自己特有的方法。
  4. 符合依赖倒置原则(Dependence Inversion Principle)虽然这个项目没有使用抽象类或者接口,但是有对接口进行实现。
  5. 符合迪米特法则(Law Of Demeter),一个类不会与与它无关的类进行交流沟通。
  6. 符合组合/聚合复用原则(Composition/Aggregation Reuse Principle )——松耦合,个别类使用了合成和聚合来达到实现功能的目的而不是使用集成。

4.5 改进说明

  1. 使用国人开发的Beautyeye外部Swing库来进行页面的UI改进前端。
  2. 使用derby内嵌式数据库来作为后端。
  3. 重新排版了各个视图的输入框、按钮、标签等,使得其看起来更加优美
  4. 优化了触发逻辑,查询之前检查输入框是否为空、查找失败后反馈信息、删除成功清空输入框等等
  5. 使用Midjourney来设计的产品logo武侠背景图
  6. 自己造CustomMessageDialog\FontLoader\RoundBorder等轮子来达到优化页面的目的
  7. 自建一个MaskLayer类来达到切换选项卡时启动遮罩层的目的(目前已废弃,由于切换选项卡时有些输入框并没有被遮罩层覆盖)
    原MaskLayer类
    package src.resource;
    
    import javax.swing.*;
    import java.awt.*;
    
    public class MaskLayer extends JComponent {
        private static final Color MASK_COLOR = new Color(0, 0, 0, 150);
    
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
    
            // 绘制半透明磨砂板
            Graphics2D g2d = (Graphics2D) g.create();
            g2d.setColor(MASK_COLOR);
            g2d.fillRect(0, 0, getWidth(), getHeight());
            g2d.dispose();
        }
    }
    
    原IntergrationView类
    package src.view;//包名
    
    import src. resource.MaskLayer;
    import src.resource.FontLoader;
    import src.resource.RoundBorder;
    
    import javax.swing.*;//导入javax.swing包中的所有类
    import java.awt.*;//导入java.awt包中的所有类
    import java.awt.event.ActionEvent;
    
    public class AddWordView extends JPanel {//添加单词界面
        private MaskLayer maskLayer;//遮罩层
        private Timer timer;//计时器
        JTextField inputWord;     //输入单词
        JTextField inputMeaning;  //输入单词的解释
        JCheckBox Verb, Noun, adj;     //输入单词的词性
        JButton submit;           //提交按钮
        JLabel wordLabel, meaningLabel, partLabel;//单词标签,解释标签,词性标签
        HandleAddWord handleAddWord;  //负责处理添加单词
        JPanel inputPanel, checkBoxPanel, submitPanel;//输入面板,复选框面板,提交面板
    
        AddWordView() {//添加单词界面,构造方法
            initView();//初始化界面
            registerListener();//注册监听器
            setLayout(new BorderLayout()); // 设置布局为边界布局
    
            add(maskLayer, BorderLayout.CENTER); // 将 MaskLayer 添加到中间位置
            maskLayer = new MaskLayer();//创建遮罩层
            maskLayer.setBackground(new Color(0, 0, 0, 150));//设置遮罩层背景颜色
            maskLayer.setBounds(0, 0, 800, 560);//设置遮罩层位置和大小
    
            // 添加其他组件到 maskLayer 上
            maskLayer.add(inputPanel);
            maskLayer.add(submitPanel);
            timer = new Timer(500, new AbstractAction() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    maskLayer.hideMaskLayer();
                    timer.stop();
                }
            });
        }
    
        private void initView() {
            setBackground(new Color(0, 0, 0, 0));//设置背景透明
    
            Box boxH, boxHThree, boxHFour;                 //行式盒
            Box boxVOne, boxVTwo;      //列式盒
            boxH = Box.createHorizontalBox();//创建行式盒
            boxVOne = Box.createVerticalBox();//创建列式盒1
            boxVTwo = Box.createVerticalBox();//创建列式盒2
            boxHThree = Box.createHorizontalBox();//创建列式盒3
            boxHFour = Box.createHorizontalBox();//创建列式盒4
    
            boxH.setPreferredSize(new Dimension(400, 167));//设置行式盒大小
            boxHFour.setPreferredSize(new Dimension(400, 180));//设置行式盒4大小
            boxVOne.setPreferredSize(new Dimension(100, 167));//设置列式盒1大小
            boxVTwo.setPreferredSize(new Dimension(300, 167));//设置列式盒2大小
    
            //初始化组件
            inputWord = new JTextField(30);//输入单词输入框
            inputWord.setFont(FontLoader.getCustomFont(15));//设置输入单词输入框字体
            inputMeaning = new JTextField(30);//输入单词的解释输入框
            inputMeaning.setFont(FontLoader.getCustomFont(15));//设置输入单词的解释输入框字体
            Verb = new JCheckBox("动词");//动词复选框
            Verb.setFont(FontLoader.getCustomFont(17));//设置动词复选框字体
            Verb.setBackground(new Color(0, 0, 0, 0));//设置动词复选框背景透明
            Verb.setForeground(Color.BLACK);//设置动词复选框字体颜色
            Noun = new JCheckBox("名词");//名词复选框
            Noun.setFont(FontLoader.getCustomFont(17));//设置名词复选框字体
            Noun.setBackground(new Color(0, 0, 0, 0));//设置名词复选框背景透明
            Noun.setForeground(Color.DARK_GRAY);//设置名词复选框字体颜色
            adj = new JCheckBox("形容词");//形容词复选框
            adj.setFont(FontLoader.getCustomFont(17));//设置形容词复选框字体
            adj.setBackground(new Color(0, 0, 0, 0));//设置形容词复选框背景透明
            adj.setForeground(Color.WHITE);//设置形容词复选框字体颜色
            submit = new JButton("点击此处添加单词") {
                @Override
                //重写paintComponent方法,使按钮当前图层透明
                protected void paintComponent(Graphics g) {
                    // TODO Auto-generated method stub
                    Graphics2D g2d = (Graphics2D) g.create();
                    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
                    super.paintComponent(g2d);
                    g2d.dispose();
                }
            };
            submit.setFont(FontLoader.getCustomFont(20));//设置提交按钮字体
            submit.setBorderPainted(false); //不绘制边框
            submit.setForeground(Color.BLACK); //设置字体颜色
            submit.setContentAreaFilled(false); //不绘制按钮区域
    
    
            wordLabel = new JLabel("单词:");//单词标签
            wordLabel.setFont(FontLoader.getCustomFont(30));//设置单词标签字体
            meaningLabel = new JLabel("解释:");//解释标签
            meaningLabel.setFont(FontLoader.getCustomFont(30));//设置解释标签字体
            partLabel = new JLabel("词性:");//词性标签
            partLabel.setFont(FontLoader.getCustomFont(30));//设置词性标签字体
            //往列式盒添加组件,分为两列
            boxVOne.add(wordLabel);//单词标签
            boxVOne.add(Box.createVerticalStrut(20));//创建垂直间距
            boxVOne.add(meaningLabel);//解释标签
            boxVOne.add(Box.createVerticalStrut(20));//创建垂直间距
            boxVOne.add(partLabel);//词性标签
    
            checkBoxPanel = new JPanel();
            checkBoxPanel.setBackground(new Color(0, 0, 0, 0));
            checkBoxPanel.add(boxHThree);
    
            boxHThree.add(Verb);
            boxHThree.add(Box.createHorizontalStrut(10));//创建水平间距
            boxHThree.add(Noun);
            boxHThree.add(Box.createHorizontalStrut(10));//创建水平间距
            boxHThree.add(adj);
    
            boxVTwo.add(inputWord);//单词输入框
            boxVTwo.add(Box.createVerticalStrut(10));//创建垂直间距
            boxVTwo.add(inputMeaning);//单词解释输入框
            boxVTwo.add(Box.createVerticalStrut(10));//创建垂直间距
            boxVTwo.add(checkBoxPanel);//词性复选框
    
            boxH.add(boxVOne);
            boxH.add(Box.createHorizontalStrut(10));//创建水平间距
            boxH.add(boxVTwo);
    
            inputPanel = new JPanel();
            inputPanel.setBackground(new Color(0, 0, 0, 0));
            inputPanel.setBorder(new RoundBorder(Color.black));
            inputPanel.add(boxH);
    
            boxHFour.add(submit);
            submitPanel = new JPanel();
            submitPanel.setBackground(new Color(0, 0, 0, 0));
            submitPanel.setLayout(new BoxLayout(submitPanel, BoxLayout.Y_AXIS));
            submitPanel.add(Box.createVerticalStrut(120));//创建垂直间距
            submitPanel.add(boxHFour);
    
            add(inputPanel);
            add(submitPanel);
        }
    
        private void registerListener() {//注册监听器
            handleAddWord = new HandleAddWord();//创建监听器对象,负责处理添加单词
            handleAddWord.setView(this);//设置监听器对象的界面,即AddWordView对象
            submit.addActionListener(handleAddWord);//注册监听器
        }
    }
    

5. 全部源码(很多注释)

超长代码警告!!!

5.1 AddWord.java

package src.data;//包名
import java.sql.*;//导入java.sql包中的所有类
public class AddWord {//添加单词
   int isOK ; //isOK=1表示添加成功,isOK=0表示添加失败
   public int insertWord(src.data.Word word) {//插入单词方法
      Connection con = ConnectDatabase.connectDatabase();//连接MyEnglishBook数据库
      if(con == null)//如果连接失败,返回0
         return 0;
      try { 
          String SQL ="insert into word_table values(?,?)";//插入单词SQL语句
          PreparedStatement sta  = con.prepareStatement(SQL);//创建PreparedStatement对象
          sta.setString(1,word.getEnglishWord());//设置SQL语句中的第一个问号的值
          sta.setString(2,word.getMeaning());//设置SQL语句中的第二个问号的值
          isOK = sta.executeUpdate();  //执行SQL语句
          con.close();//关闭数据库连接
      }
      catch(SQLException e) {
          isOK = 0; //word_table表中word字段是主键,即不允许单词重复
      }
      return isOK;
   }
}

5.2 ConnectDatabase.java

package src.data;//包名
import java.sql.*;//导入java.sql包中的所有类

public class ConnectDatabase{//连接数据库
   public static Connection connectDatabase() {
      Connection con = null;
      try{Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
      }
      catch(Exception e){}
      try{  
        String uri ="jdbc:derby:MyEnglishBook;create=true";
        con=DriverManager.getConnection(uri);//连接数据库代码
      }
      catch(Exception e){}
      return con;
   }
}

5.3 CreateDatabaseAndTable.java

package src.data;// 包名
import java.sql.*;// 导入java.sql包中的所有类
public class CreateDatabaseAndTable{// 创建数据库和表
   Connection con;// 数据库连接对象
   public  CreateDatabaseAndTable(){
      try{Class.forName("org.apache.derby.jdbc.EmbeddedDriver");// 加载驱动
      }
      catch(Exception e){
          System.out.println("驱动加载失败"+e);// 如果驱动加载失败,将触发异常
      }

      try{ //创建名字是MyEnglishBook的数据库: 
         String uri ="jdbc:derby:MyEnglishBook;create=true";// 数据库连接字符串
         con=DriverManager.getConnection(uri); //连接数据库代码
      }
      catch(Exception e){
          System.out.println("数据库连接失败"+e);// 如果数据库连接失败,将触发异常
      }// 如果数据库已经存在,将触发异常,不再创建该数据库

      try {//创建名字是word_table的表:
          Statement sta = con.createStatement();//创建Statement对象
          String SQL="create table word_table"+
          "(word varchar(50) primary key,meaning varchar(200))";//创建表的SQL语句
          sta.executeUpdate(SQL);   //创建表
          con.close();//关闭数据库连接
      }
      catch(SQLException e) { //如果表已经存在,将触发SQL异常,不再创建该表
          System.out.println("表已经存在"+e);
      }
   }
}

5.4 DelWord.java

package src.data;//包名
import java.sql.*;//导入java.sql包中的所有类
public class DelWord extends ConnectDatabase {//删除单词
   int isOK ; //isOK=1表示删除成功,isOK=0表示删除失败
   public int delWord(Word word) {//删除单词方法
      Connection con = ConnectDatabase.connectDatabase();//连接MyEnglishBook数据库
      if(con == null)//如果连接失败,返回0
         return 0;
      try { //删除单词SQL语句
          String SQL ="delete from word_table where word = ? ";
          PreparedStatement sta  = con.prepareStatement(SQL);//创建PreparedStatement对象
          sta.setString(1,word.getEnglishWord());//设置SQL语句中的第一个问号的值
          isOK = sta.executeUpdate();//执行SQL语句
          con.close();//关闭数据库连接
      }
      catch(SQLException e) {
          isOK = 0; //word_table表中word字段是主键,即不允许单词重复
      }
      return isOK;
   }
}

5.5 QueryAllWord.java

package src.data;//包名
import java.sql.*;//导入java.sql包中的所有类
public class QueryAllWord {//查询全部单词
   public Word[] queryAllWord() { //查询全部单词方法
      Connection con = ConnectDatabase.connectDatabase();//连接MyEnglishBook数据库
      if(con == null)//如果连接失败,返回null
         return null;
      Word [] word  = null;//Word数组
      Statement sql; //Statement对象是用于执行静态SQL语句并返回它所生成结果的对象
      ResultSet rs;//ResultSet对象是用于保存获取的结果集的对象
      try { //查询全部单词SQL语句若不加order by子句,结果集中的记录顺序是不确定的
        sql=con.createStatement
         (ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);//创建Statement对象
        rs=sql.executeQuery("select * from word_table");//执行SQL语句
        rs.last(); //结果集指针移到最后一条记录
        int recordAmount =rs.getRow();//结果集中的全部记录
        word = new Word[recordAmount];//Word数组的长度
        for(int i=0;i<word.length;i++){
          word[i] = new Word();//Word数组的每个元素
        }
        rs.beforeFirst();//结果集指针移到第一条记录之前
        int i=0;//Word数组的下标
        while(rs.next()) { //遍历结果集
          word[i].setEnglishWord(rs.getString(1));//设置Word数组的每个元素的单词
          word[i].setMeaning(rs.getString(2));//设置Word数组的每个元素的单词解释
          i++;
        }
        con.close();
      }
      catch(SQLException e) {}
      return word;//返回Word数组
   }   
}

5.6 QueryOneWord.java

package src.data;
import java.sql.*;
public class QueryOneWord {//查询单词
   public Word queryOneWord(Word word) {//查询单词方法
      Connection con = ConnectDatabase.connectDatabase();//连接MyEnglishBook数据库
      if(con == null)
         return null;
      Word  foundWord  = null;//查询到的单词
      Statement sql; //创建Statement对象
      ResultSet rs;//创建ResultSet对象
      String str =
      "select * from word_table where word ='"+word.getEnglishWord()+"'"; //查询单词SQL语句
      try { //执行SQL语句
        sql=con.createStatement();
        rs=sql.executeQuery(str);
        if(rs.next()){ //如果查询到单词
          foundWord = new Word();//查询到的单词
          foundWord.setEnglishWord(rs.getString(1));//设置查询到的单词
          foundWord.setMeaning(rs.getString(2));//设置查询到的单词解释
        }
        con.close();
      }
      catch(SQLException e) {}
      return foundWord;
   }   
}

5.7 RandomQueryWord.java

package src.data;//包名
import java.sql.*;//导入java.sql包中的所有类
import java.util.*;//导入java.util包中的所有类
public class RandomQueryWord {//随机抽取单词
   int count =0 ;//随机抽取的数目
   public void setCount(int n){
       count = n;
   }//设置随机抽取的数目
   public int getCount(){
      return count;
   }//得到随机抽取的数目
   public Word[] randomQueryWord() { //随机抽取单词方法
      Connection con = ConnectDatabase.connectDatabase();//连接MyEnglishBook数据库
      if(con == null)
         return null;
      Word [] word  = null;//存放随机抽取的单词
      Statement sql; 
      ResultSet rs;
      try { 
        sql=con.createStatement
        (ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);//创建Statement对象
        rs=sql.executeQuery("select * from word_table");//执行SQL语句
        rs.last(); //结果集指针移到最后一条记录
        int recordAmount =rs.getRow();//结果集中的记录数目
        count = Math.min(count,recordAmount);//随机抽取的数目不能超过结果集中的记录数目
        word = new Word[count];//Word数组的长度
        for(int i=0;i<word.length;i++){
           word[i] = new Word();
        }
        //得到1至recordAmount之间count个互不相同的随机整数(存放在数组index中):
        int [] index = getRandomNumber(recordAmount,count);
        int m = 0;
        for(int randomNumer:index){ // randomNumer依次取数组index每个单元的值
             rs.absolute(randomNumer);//查询游标移动到第randomNumer行
             word[m].setEnglishWord(rs.getString(1));
             word[m].setMeaning(rs.getString(2));
             m++;
        }
        con.close();
      }
      catch(SQLException e) { 
         System.out.println(e);
      }
      return word;
   } 
   public int [] getRandomNumber(int max,int count) {//得到1至max之间count个互不相同的随机整数
     // 得到1至max之间的amount个互不相同的随机整数(包括1和max):
     int [] randomNumber = new int[count];
     Set<Integer> set=new HashSet<Integer>(); //set不允许有相同的元素
     int size =set.size();
     Random random = new Random();
     while(size<count){
         int number = random.nextInt(max)+1;
         set.add(number); //number放入集合set中
         size =set.size();//集合set的大小
     }
     Iterator<Integer> iter=set.iterator();
     int i = 0;
     while(iter.hasNext()) {  //把集合中的随机数放入数组
         Integer te=iter.next();
         randomNumber[i] = te.intValue();
         i++;
     }
     return  randomNumber;
   }  
}

5.8 UpdateWord.java

package src.data;//包名
import java.sql.*;//导入java.sql包中的所有类
public class UpdateWord {//更新单词
   int isOK  ; 
   public int updateWord(Word word) {//更新单词方法
      Connection con = ConnectDatabase.connectDatabase();//连接MyEnglishBook数据库
      if(con == null)
         return 0;
      try { 
          String SQL ="update word_table set meaning = ? where word = ? ";//更新单词SQL语句
          PreparedStatement sta  = con.prepareStatement(SQL);
          sta.setString(1,word.getMeaning());//设置SQL语句中的第一个问号的值
          sta.setString(2,word.getEnglishWord());//设置SQL语句中的第二个问号的值
          isOK = sta.executeUpdate();//执行SQL语句
          con.close();
      }
      catch(SQLException e) {
          isOK = 0; 
      }
       return isOK;
   }
}

5.9 Word.java

package src.data;
public class Word{
   String englishWord; //单词
   String meaning;    //单词的解释
   public void setEnglishWord(String englishWord){
      this.englishWord = englishWord;
   }//设置单词
   public String getEnglishWord() {
      return englishWord;
   }//获取单词
   public void setMeaning(String meaning){
      this.meaning = meaning;
   }//设置单词解释
   public String getMeaning() {
      return meaning;
   }//获取单词解释
}

5.10 AppWindow.java

package src.gui;

import org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper;
import src.view.IntegrationView;
import src.data.CreateDatabaseAndTable;

import java.awt.*;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.plaf.BorderUIResource;

public class AppWindow {//应用程序窗口
    public static void main(String[] args) {
       //加载Beautyeye
        try {
            org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();//设置BeautyEyeLNF
            BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;//
            UIManager.put("RootPane.setupButtonVisible", false);//隐藏设置按钮
            UIManager.put("ToolBar.isPaintPlainBackground", Boolean.TRUE);
            //自定义JToolBar ui的border
            Border bd = new org.jb2011.lnf.beautyeye.ch8_toolbar.BEToolBarUI.ToolBarBorder(
                    UIManager.getColor("ToolBar.shadow")     //Floatable时触点的颜色
                    , UIManager.getColor("ToolBar.highlight")//Floatable时触点的阴影颜色
                    , new Insets(16, 40, 0, 20));              //border的默认insets
            UIManager.put("ToolBar.border", new BorderUIResource(bd));
            //改变InsetsUIResource参数的值即可实现
            UIManager.put("TabbedPane.tabAreaInsets"
                    , new javax.swing.plaf.InsetsUIResource(8, 5, 0, 0));
        } catch (Exception e) {
            System.out.println("BeautyEyeLNF not found!");//未找到BeautyEyeLNF
        }
        new CreateDatabaseAndTable();//创建数据库和表
        IntegrationView win = new IntegrationView(); //创建应用程序窗口
    }
}

5.11 CustomMessageDialog.java

package src.resource;

import javax.swing.*;
import java.awt.*;

public class CustomMessageDialog extends JDialog {

    public CustomMessageDialog(Frame parent, String message, String title, int messageType) {
        super(parent, title, true);
        JPanel contentPane = new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {//重写paintComponent方法,实现自定义的背景
                // Set the desired background color or image
                g.setColor(Color.BLUE);
                g.fillRect(0, 0, getWidth(), getHeight());
            }
        };
        contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
        contentPane.setLayout(new BorderLayout());

        // Add the message label to the panel
        JLabel messageLabel = new JLabel(message);
        messageLabel.setForeground(Color.WHITE);
        messageLabel.setHorizontalAlignment(SwingConstants.CENTER);
        contentPane.add(messageLabel, BorderLayout.CENTER);

        // Set the custom panel as the content pane of the dialog
        setContentPane(contentPane);

        // Set the dialog size based on the message length
        int messageLength = message.length();
        int dialogWidth = Math.min(400, messageLength * 10);
        int dialogHeight = 150;
        setSize(dialogWidth, dialogHeight);
        setLocationRelativeTo(parent);

        // Set the appropriate message icon
        if (messageType == JOptionPane.ERROR_MESSAGE) {
            setIconImage(new ImageIcon("error_icon.png").getImage());
        } else if (messageType == JOptionPane.INFORMATION_MESSAGE) {
            setIconImage(new ImageIcon("info_icon.png").getImage());
        } else if (messageType == JOptionPane.WARNING_MESSAGE) {
            setIconImage(new ImageIcon("warning_icon.png").getImage());
        }

        // Set the dialog to dispose on close
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }

}

5.12 FontLoader.java

package src.resource;

import java.awt.*;
import java.io.File;
import java.io.IOException;

public class FontLoader {
    private static Font customFont;

    public static void loadFont() {
        try {
            File fontFile = new File("fonts/Alimama.ttf");
            customFont = Font.createFont(Font.TRUETYPE_FONT, fontFile);
        } catch (IOException | FontFormatException e) {
            e.printStackTrace();
        }
    }

    public static Font getCustomFont(float size) {
        if (customFont == null) {
            loadFont();
        }
        return customFont.deriveFont(size);
    }
}

5.13 RoundBorder.java

package src.resource;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.RenderingHints;
import javax.swing.border.Border;

public class RoundBorder implements Border {
    private Color color;

    private int arcH = 15;
    private int arcW = 15;

    public RoundBorder() {
        this(Color.BLACK);
        // 如果实例化时,没有传值
        // 默认是黑色边框
    }

    public RoundBorder(Color color) {
        this.color = color;
    }

    public Insets getBorderInsets(Component c) {

        // top:可以调节光标与边枉的距离, 间接影响高度
        // left:可以调节光标与边枉的距离
        // bottom:可以调节光标与边枉的距离, 间接影响高度
        // right:可以调节光标与边枉的距离
        return new Insets(10, 15, 10, 15);
    }

    public boolean isBorderOpaque() {
        return false;
    }

    // 实现Border(父类)方法
    @Override
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
        //        g.setColor(color);
        //        g.drawRoundRect(0, 0, c.getWidth() - 1, c.getHeight() - 1, arcH, arcW);

        Graphics2D g2d = (Graphics2D) g.create();

        g2d.setColor(color);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.drawRoundRect(0, 0, c.getWidth() - 1, c.getHeight() - 1, arcH, arcW);

        g2d.dispose();
    }
}

5.14 AddWordView.java

package src.view;//包名

import src.resource.FontLoader;
import src.resource.RoundBorder;

import javax.swing.*;//导入javax.swing包中的所有类
import java.awt.*;//导入java.awt包中的所有类

public class AddWordView extends JPanel {//添加单词界面
    JTextField inputWord;     //输入单词
    JTextField inputMeaning;  //输入单词的解释
    JCheckBox Verb, Noun, adj;     //输入单词的词性
    JButton submit;           //提交按钮
    JLabel wordLabel, meaningLabel, partLabel;//单词标签,解释标签,词性标签
    HandleAddWord handleAddWord;  //负责处理添加单词
    JPanel inputPanel, checkBoxPanel, submitPanel;//输入面板,复选框面板,提交面板

    AddWordView() {//添加单词界面,构造方法
        initView();//初始化界面
        registerListener();//注册监听器
    }

    private void initView() {
        setBackground(new Color(0, 0, 0, 0));//设置背景透明

        Box boxH, boxHThree, boxHFour;                 //行式盒
        Box boxVOne, boxVTwo;      //列式盒
        boxH = Box.createHorizontalBox();//创建行式盒
        boxVOne = Box.createVerticalBox();//创建列式盒1
        boxVTwo = Box.createVerticalBox();//创建列式盒2
        boxHThree = Box.createHorizontalBox();//创建列式盒3
        boxHFour = Box.createHorizontalBox();//创建列式盒4

        boxH.setPreferredSize(new Dimension(400, 167));//设置行式盒大小
        boxHFour.setPreferredSize(new Dimension(400, 180));//设置行式盒4大小
        boxVOne.setPreferredSize(new Dimension(100, 167));//设置列式盒1大小
        boxVTwo.setPreferredSize(new Dimension(300, 167));//设置列式盒2大小

        //初始化组件
        inputWord = new JTextField(30);//输入单词输入框
        inputWord.setFont(FontLoader.getCustomFont(15));//设置输入单词输入框字体
        inputMeaning = new JTextField(30);//输入单词的解释输入框
        inputMeaning.setFont(FontLoader.getCustomFont(15));//设置输入单词的解释输入框字体
        Verb = new JCheckBox("动词");//动词复选框
        Verb.setFont(FontLoader.getCustomFont(17));//设置动词复选框字体
        Verb.setBackground(new Color(0, 0, 0, 0));//设置动词复选框背景透明
        Verb.setForeground(Color.BLACK);//设置动词复选框字体颜色
        Noun = new JCheckBox("名词");//名词复选框
        Noun.setFont(FontLoader.getCustomFont(17));//设置名词复选框字体
        Noun.setBackground(new Color(0, 0, 0, 0));//设置名词复选框背景透明
        Noun.setForeground(Color.DARK_GRAY);//设置名词复选框字体颜色
        adj = new JCheckBox("形容词");//形容词复选框
        adj.setFont(FontLoader.getCustomFont(17));//设置形容词复选框字体
        adj.setBackground(new Color(0, 0, 0, 0));//设置形容词复选框背景透明
        adj.setForeground(Color.WHITE);//设置形容词复选框字体颜色
        submit = new JButton("点击此处添加单词") {
            @Override
            //重写paintComponent方法,使按钮当前图层透明
            protected void paintComponent(Graphics g) {
                // TODO Auto-generated method stub
                Graphics2D g2d = (Graphics2D) g.create();
                g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
                super.paintComponent(g2d);
                g2d.dispose();
            }
        };
        submit.setFont(FontLoader.getCustomFont(20));//设置提交按钮字体
        submit.setBorderPainted(false); //不绘制边框
        submit.setForeground(Color.BLACK); //设置字体颜色
        submit.setContentAreaFilled(false); //不绘制按钮区域


        wordLabel = new JLabel("单词:");//单词标签
        wordLabel.setFont(FontLoader.getCustomFont(30));//设置单词标签字体
        meaningLabel = new JLabel("解释:");//解释标签
        meaningLabel.setFont(FontLoader.getCustomFont(30));//设置解释标签字体
        partLabel = new JLabel("词性:");//词性标签
        partLabel.setFont(FontLoader.getCustomFont(30));//设置词性标签字体
        //往列式盒添加组件,分为两列
        boxVOne.add(wordLabel);//单词标签
        boxVOne.add(Box.createVerticalStrut(20));//创建垂直间距
        boxVOne.add(meaningLabel);//解释标签
        boxVOne.add(Box.createVerticalStrut(20));//创建垂直间距
        boxVOne.add(partLabel);//词性标签

        checkBoxPanel = new JPanel();
        checkBoxPanel.setBackground(new Color(0, 0, 0, 0));
        checkBoxPanel.add(boxHThree);

        boxHThree.add(Verb);
        boxHThree.add(Box.createHorizontalStrut(10));//创建水平间距
        boxHThree.add(Noun);
        boxHThree.add(Box.createHorizontalStrut(10));//创建水平间距
        boxHThree.add(adj);

        boxVTwo.add(inputWord);//单词输入框
        boxVTwo.add(Box.createVerticalStrut(10));//创建垂直间距
        boxVTwo.add(inputMeaning);//单词解释输入框
        boxVTwo.add(Box.createVerticalStrut(10));//创建垂直间距
        boxVTwo.add(checkBoxPanel);//词性复选框

        boxH.add(boxVOne);
        boxH.add(Box.createHorizontalStrut(10));//创建水平间距
        boxH.add(boxVTwo);

        inputPanel = new JPanel();
        inputPanel.setBackground(new Color(0, 0, 0, 0));
        inputPanel.setBorder(new RoundBorder(Color.black));
        inputPanel.add(boxH);

        boxHFour.add(submit);
        submitPanel = new JPanel();
        submitPanel.setBackground(new Color(0, 0, 0, 0));
        submitPanel.setLayout(new BoxLayout(submitPanel, BoxLayout.Y_AXIS));
        submitPanel.add(Box.createVerticalStrut(120));//创建垂直间距
        submitPanel.add(boxHFour);

        add(inputPanel);
        add(submitPanel);
    }

    private void registerListener() {//注册监听器
        handleAddWord = new HandleAddWord();//创建监听器对象,负责处理添加单词
        handleAddWord.setView(this);//设置监听器对象的界面,即AddWordView对象
        submit.addActionListener(handleAddWord);//注册监听器
    }
}

5.15 BackgroundPanel.java

package src.view;

import java.awt.*;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

/**
 * 有背景图片的Panel类
 */
public class BackgroundPanel extends JPanel {

    /**
     *
     */
    private static final long serialVersionUID = -6352788025440244338L;

    private Image image = (Image) new ImageIcon("img\\BCG.png").getImage();

    // 固定背景图片,允许这个JPanel可以在图片上添加其他组件
    protected void paintComponent(Graphics g) {
        g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), this);
    }
}

5.16 DelWordView.java

package src.view;//包名
import org.jb2011.lnf.beautyeye.ch3_button.BEButtonUI;
import src.resource.FontLoader;

import javax.swing.*;//导入javax.swing包中的所有类
import java.awt.*;

public class DelWordView extends JPanel {//删除单词界面
   JTextField inputWord;  //输入要删除的单词
   JLabel inputWordLabel; //输入单词标签
   JButton delete;        //提交按钮
   HandleDelWord handleDelWord;  //负责处理删除单词
   DelWordView(){//删除单词界面,构造方法
      initView();//初始化界面
      registerListener() ;//注册监听器
   }
   private void initView() {
      setBackground(new Color(0,0,0,0));//设置背景透明

      inputWord = new JTextField(12);//输入要删除的单词
      inputWord.setFont(FontLoader.getCustomFont(15));//设置输入要删除的单词字体
      inputWordLabel = new JLabel("输入要删除的单词");//输入单词标签
      inputWordLabel.setFont(FontLoader.getCustomFont(15));//设置输入单词标签字体
      delete = new JButton("删除单词");//提交按钮
      delete.setFont(FontLoader.getCustomFont(15));//设置提交按钮字体
      delete.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.red));//设置提交按钮颜色
      add(inputWordLabel);//输入单词标签
      add(Box.createHorizontalStrut(20));//水平间距
      add(inputWord);//单词输入框
      add(Box.createHorizontalStrut(20));//水平间距
      add(delete);//提交按钮
   }
   private void registerListener() {//注册监听器
      handleDelWord = new HandleDelWord();//创建监听器对象,负责处理删除单词
      handleDelWord.setView(this);//设置监听器对象的界面,即DelWordView对象,这样监听器对象就可以访问DelWordView对象的成员变量了
      delete.addActionListener(handleDelWord);//注册监听器
   }
}


5.17 HandleAddWord.java

package src.view;

import java.awt.event.*;

import src.data.*;
import src.resource.CustomMessageDialog;

import javax.swing.*;

public class HandleAddWord implements ActionListener {//负责处理添加单词
    AddWordView view;//添加单词界面

    public void actionPerformed(ActionEvent e) {
        //处理添加单词
        String englishWord = view.inputWord.getText();//获取输入的单词
        String meaning = view.inputMeaning.getText();//获取输入的单词的解释
        Boolean partIsVerb = view.Verb.isSelected();//获取单词的词性是否是动词
        Boolean partIsNoun = view.Noun.isSelected();//获取单词的词性是否是名词
        Boolean partIsAdj = view.adj.isSelected();//获取单词的词性是否是形容词
        if (partIsVerb) {//如果单词的词性是动词
            meaning += " v.";//在单词的解释后面加上v.
        }
        if (partIsNoun) {//如果单词的词性是名词
            if (partIsVerb) meaning += "&";
            meaning += " n.";//在单词的解释后面加上n.
        }
        if (partIsAdj) {//如果单词的词性是形容词
            if (partIsVerb || partIsNoun) meaning += "&";
            meaning += " adj.";//在单词的解释后面加上adj.
        }
        if (englishWord.length() == 0 || meaning.length() == 0) //如果输入的单词或者解释为空,就返回
        {
            JOptionPane.showMessageDialog(view, "添加失败,检查是否输入框为空", "Feedback", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        Word word = new Word();//单词对象
        AddWord addWord = new AddWord(); //负责添加单词的对象
        word.setEnglishWord(englishWord);//设置单词
        word.setMeaning(meaning);//设置单词的解释
        int isOK = addWord.insertWord(word);//向数据库中的表添加单词
        if (isOK != 0) {
            UIManager.put("RootPane.setupButtonVisible", false);
            UIManager.put("OptionPane.border", BorderFactory.createEmptyBorder());
            JOptionPane.showMessageDialog(view, "添加成功", "Feedback", JOptionPane.INFORMATION_MESSAGE);
            view.inputWord.setText("");
            view.inputMeaning.setText("");
        } else {
            UIManager.put("RootPane.setupButtonVisible", false);
            UIManager.put("OptionPane.border", BorderFactory.createEmptyBorder());
            JOptionPane.showMessageDialog(view, "添加失败,数据库中可能已存在该单词", "Feedback", JOptionPane.INFORMATION_MESSAGE);
            view.inputWord.setText("");
            view.inputMeaning.setText("");
        }
    }

    public void setView(src.view.AddWordView view) {
        this.view = view;
    }//设置监听器对象的界面,即AddWordView对象
}


5.18 HandleDelWord.java

package src.view;

import java.awt.event.*;

import src.data.*;

import javax.swing.*;

public class HandleDelWord implements ActionListener {//负责处理删除单词
    DelWordView view;//删除单词界面

    public void actionPerformed(ActionEvent e) {
        String englishWord = view.inputWord.getText();//获取输入的单词
        if (englishWord.length() == 0) { //如果输入的单词为空,就返回
            JOptionPane.showMessageDialog(view, "删除失败,请检输入框是否为空", "Feedback", JOptionPane.WARNING_MESSAGE);
            return;
        }
        Word word = new Word();//单词对象
        DelWord del = new DelWord();    //负责删除单词的对象
        word.setEnglishWord(englishWord); //删除单词
        int isOK = del.delWord(word);//从数据库中的表删除单词
        if (isOK != 0) {
            JOptionPane.showMessageDialog(view, "删除成功!", "Feedback", JOptionPane.INFORMATION_MESSAGE);
            view.inputWord.setText("");//清空输入单词的文本框
        } else {
            JOptionPane.showMessageDialog(view, "删除失败,数据库中没有该单词", "Feedback", JOptionPane.WARNING_MESSAGE);
        }
    }

    public void setView(DelWordView view) {
        this.view = view;
    }
}


5.19 HandleQueryAllWord.java

package src.view;
import java.awt.event.*;
import src.data.*;
public class HandleQueryAllWord implements ActionListener {//负责处理查询所有单词
   QueryAllWordView view ;//查询所有单词界面
   public void actionPerformed(ActionEvent e) {//处理查询所有单词
      view.showWord.setText("");//清空显示单词的文本域
      QueryAllWord query = new QueryAllWord();//查询对象
      Word [] result =query.queryAllWord();     //执行查询
      for(int i=0;i<result.length;i++){
         int m = i+1;//序号
         view.showWord.append(m+"."+result[i].getEnglishWord());//显示单词,每个单词前面加上序号
         view.showWord.append("   "+result[i].getMeaning());//显示单词的解释,每个单词的解释前面加上三个空格
         view.showWord.append("\n");   //换行
      }
   }
   public void setView(QueryAllWordView view) {
      this.view = view;
   }
}


5.20 HandleQueryOneWord.java

package src.view;

import java.awt.event.*;

import com.sun.javafx.image.BytePixelSetter;
import src.data.*;

import javax.swing.*;

public class HandleQueryOneWord implements ActionListener {//负责处理查询单词
    QueryOneWordView view;//查询单词界面

    public void actionPerformed(ActionEvent e) {//处理查询单词
        String englishWord = view.inputWord.getText();//获取输入的单词
        if (englishWord.length() == 0) {
            JOptionPane.showMessageDialog(view, "请输入要查询的单词", "提示", JOptionPane.WARNING_MESSAGE);
            return;
        }
        Word word = new Word();//单词对象
        word.setEnglishWord(englishWord);//设置单词
        QueryOneWord query = new QueryOneWord();//负责查询的对象
        Word result = query.queryOneWord(word);    //执行查询操作
        if (result == null) {
            JOptionPane.showMessageDialog(view, "没有找到该单词", "提示", JOptionPane.WARNING_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(view, "查询成功", "提示", JOptionPane.WARNING_MESSAGE);
            view.showWord.setText("");//清空显示单词的文本域
            view.showWord.append(" " + result.getEnglishWord());//显示单词
            view.showWord.append("   " + result.getMeaning());
            view.showWord.append("\n");
        }
    }

    public void setView(QueryOneWordView view) {
        this.view = view;
    }
}



5.21 HandleRandomQueryWord.java

package src.view;
import java.awt.event.*;
import src.data.*;
public class HandleRandomQueryWord implements ActionListener {
   RandomQueryView view ;//查询随机单词界面
   public void actionPerformed(ActionEvent e) {
      view.showWord.setText("");//清空显示单词的文本域
      String n =view.inputQueryNumber.getText().trim();//获取输入的单词
      if(n.length()==0)
        return;
      int count = 0;
      try{
         count = Integer.parseInt(n);//将字符串转换成整数
      }
      catch(NumberFormatException exp){
         view.showWord.setText("请输入正整数");//如果输入的不是整数,就返回
      }
      RandomQueryWord random = new RandomQueryWord();//查询对象
      random.setCount(count); //随机抽取count个单词
      src.data.Word[] result = random.randomQueryWord();         //执行查询
      for(int i=0;i<result.length;i++){
         int m = i+1;
         view.showWord.append(m+"."+result[i].getEnglishWord());//显示单词
         view.showWord.append("   "+result[i].getMeaning());//显示单词的解释
         view.showWord.append("\n");   //换行
      }
   }
   public void setView(RandomQueryView view) {
      this.view = view;
   }
}


5.22 HandleUpdateWord.java

package src.view;

import java.awt.event.*;

import src.data.*;

import javax.swing.*;

public class HandleUpdateWord implements ActionListener {//负责处理更新单词
    UpdateWordView view;//更新单词界面

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == view.lookWord) {
            lookWord();//查找单词
        } else if (e.getSource() == view.submit) {
            updateWord();//更新单词
        }
    }

    private void updateWord() {//方法:更新单词
        String englishWord = view.inputWord.getText();
        String meaning = view.inputNewMeaning.getText();
        if (englishWord.length() == 0 || meaning.length() == 0) {
            JOptionPane.showMessageDialog(view, "更新失败,请检查输入框是否为空", "Feedback", JOptionPane.WARNING_MESSAGE);
            return;
        }
        Word word = new Word();
        UpdateWord update = new UpdateWord();//负责更新的对象
        word.setEnglishWord(englishWord);//设置单词
        word.setMeaning(meaning);//设置单词的解释
        int isOK = update.updateWord(word);   //跟新单词
        if (isOK != 0)
            JOptionPane.showMessageDialog(view, "更新成功!", "Feedback", JOptionPane.WARNING_MESSAGE);
        else
            JOptionPane.showMessageDialog(view, "更新数据库失败", "Feedback", JOptionPane.WARNING_MESSAGE);
    }

    private void lookWord() {//方法:查找单词
        String englishWord = view.inputWord.getText();//获取输入的单词
        if (englishWord.length() == 0) //如果输入的单词为空,就返回
        {
            JOptionPane.showMessageDialog(view, "查询失败,请检输入框是否为空", "Feedback", JOptionPane.WARNING_MESSAGE);
            return;
        }
        Word word = new Word();
        word.setEnglishWord(englishWord);//设置单词
        QueryOneWord query = new QueryOneWord();//负责查询的对象
        Word result = query.queryOneWord(word);//查询单词
        if (result != null) {//如果单词在表里
            JOptionPane.showMessageDialog(view, "查询成功!", "Feedback", JOptionPane.INFORMATION_MESSAGE);
            view.inputNewMeaning.setText(result.getMeaning());//显示单词的解释
        } else//如果单词不在表里
            JOptionPane.showMessageDialog(view, "查询失败,数据库中没有该单词", "Feedback", JOptionPane.WARNING_MESSAGE);
    }

    public void setView(UpdateWordView view) {
        this.view = view;
    }//设置监听器对象的界面,即UpdateWordView对象
}

5.23 IntegrationView.java

package src.view;//包名

import org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper;
import src.resource.FontLoader;

import java.awt.*;//导入java.awt包中的所有类
import javax.swing.*;//导入javax.swing包中的所有类

public class IntegrationView extends JFrame {//集成视图
    JTabbedPane tabbedPane; //用选项卡集成下列各个视图
    AddWordView addWordView;//添加单词视图
    UpdateWordView updateWordView;//修改单词视图
    DelWordView delWordView;//删除单词视图
    QueryOneWordView oneWordView;//查询一个单词视图
    QueryAllWordView queryAllWordView;//浏览全部单词视图
    RandomQueryView queryRandomView;//随机查看单词视图

    public IntegrationView() {
        try {
            BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;
            //BeautyEyeLNFHelper.launchBeautyEyeLNF();
        } catch (IllegalAccessError e) {
            //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }

        //初始化界面
        setBounds(100, 100, 800, 560);//设置窗口位置和大小
        setTitle("穷词");//设置窗口标题
        setVisible(true);
        //setTitle("穷词");//设置窗口标题
        setResizable(false); //设置窗口不可改变大小
        setBackground(new Color(0, 0, 0, 0));//设置窗口背景透明
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置窗口关闭时,程序结束
        ImageIcon icon = new ImageIcon("img\\穷词logo.png");//设置窗口图标
        setIconImage(icon.getImage());//设置窗口图标

        BackgroundPanel backgroundPanel = new BackgroundPanel();
        backgroundPanel.setBounds(0, 0, 800, 560);//设置面板位置和大小
        backgroundPanel.setLayout(null);

        //设置窗口布局
        tabbedPane = new JTabbedPane(JTabbedPane.TOP);//卡在上方,默认是JTabbedPane.TOP
        tabbedPane.setFont(FontLoader.getCustomFont(13));//设置字体
        addWordView = new AddWordView();//添加单词视图
        updateWordView = new UpdateWordView();//修改单词视图
        delWordView = new DelWordView();//删除单词视图
        oneWordView = new QueryOneWordView();//查询一个单词视图
        queryAllWordView = new QueryAllWordView();//浏览全部单词视图
        queryRandomView = new RandomQueryView();//随机查看单词视图
        //设置选项卡图标
        ImageIcon addVoca = new ImageIcon("img\\addVoca.png");
        Image addVocaImg = addVoca.getImage().getScaledInstance(20, 20, Image.SCALE_DEFAULT);
        ImageIcon icon1 = new ImageIcon(addVocaImg);
        ImageIcon delVoca = new ImageIcon("img\\deleteVoca.png");
        Image delVocaImg = delVoca.getImage().getScaledInstance(20, 20, Image.SCALE_DEFAULT);
        ImageIcon icon2 = new ImageIcon(delVocaImg);
        ImageIcon updateVoca = new ImageIcon("img\\updateVoca.png");
        Image updateVocaImg = updateVoca.getImage().getScaledInstance(20, 20, Image.SCALE_DEFAULT);
        ImageIcon icon3 = new ImageIcon(updateVocaImg);
        ImageIcon queryOneVoca = new ImageIcon("img\\queryOneVoca.png");
        Image queryOneVocaImg = queryOneVoca.getImage().getScaledInstance(20, 20, Image.SCALE_DEFAULT);
        ImageIcon icon4 = new ImageIcon(queryOneVocaImg);
        ImageIcon queryAllVoca = new ImageIcon("img\\queryAllVoca.png");
        Image queryAllVocaImg = queryAllVoca.getImage().getScaledInstance(20, 20, Image.SCALE_DEFAULT);
        ImageIcon icon5 = new ImageIcon(queryAllVocaImg);
        ImageIcon queryRandomVoca = new ImageIcon("img\\queryRandomVoca.png");
        Image queryRandomVocaImg = queryRandomVoca.getImage().getScaledInstance(20, 20, Image.SCALE_DEFAULT);
        ImageIcon icon6 = new ImageIcon(queryRandomVocaImg);
        //添加到选项卡
        tabbedPane.addTab("添加单词", icon1, addWordView); //添加单词视图
        tabbedPane.addTab("修改单词", icon3, updateWordView); //修改单词视图
        tabbedPane.addTab("删除单词", icon2, delWordView);//删除单词视图
        tabbedPane.addTab("查询一个单词", icon4, oneWordView); //查询一个单词视图
        tabbedPane.addTab("浏览全部单词", icon5, queryAllWordView);//浏览全部单词视图
        tabbedPane.addTab("随机查看单词", icon6, queryRandomView); //随机查看单词视图
        tabbedPane.validate();//验证
        tabbedPane.setBounds(0, 0, 800, 560);//设置选项卡位置和大小
        tabbedPane.setBackground(new Color(0, 0, 0, 0));//设置选项卡背景透明

        backgroundPanel.add(tabbedPane);//添加到面板
        add(backgroundPanel);//添加到窗口
        validate();//验证
    }
}

5.24 QueryAllWordView.java

package src.view;

import org.jb2011.lnf.beautyeye.ch3_button.BEButtonUI;
import src.resource.FontLoader;

import java.awt.*;
import javax.swing.*;

public class QueryAllWordView extends JPanel {
    JButton inquire;       //查询按钮
    JTextArea showWord;  //显示查询结果
    HandleQueryAllWord handleQueryAllWord;//负责处理查询全部单词

    QueryAllWordView() {
        initView();
        registerListener();
    }

    public void initView() {
        setBackground(new Color(0, 0, 0, 0));//设置背景透明
        setLayout(null);

        inquire = new JButton("查询全部单词");
        inquire.setFont(FontLoader.getCustomFont(15));
        inquire.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.green));
        inquire.setBounds(0, 0, 800, 50);
        add(inquire);

        showWord = new JTextArea();
        showWord.setFont(FontLoader.getCustomFont(15));
        JScrollPane scrollPane = new JScrollPane(showWord);
        scrollPane.setPreferredSize(new Dimension(800, 500));
        scrollPane.setBackground(new Color(0, 0, 0, 0));
        scrollPane.setBounds(0, 50, 746, 350);
        add(scrollPane);
    }

    private void registerListener() {
        handleQueryAllWord = new HandleQueryAllWord();
        handleQueryAllWord.setView(this);
        inquire.addActionListener(handleQueryAllWord);
    }
}


5.25 QueryOneWordView.java

package src.view;
import org.jb2011.lnf.beautyeye.ch3_button.BEButtonUI;
import src.resource.FontLoader;

import javax.swing.*;
import java.awt.*;
public class QueryOneWordView extends JPanel {
   JTextField inputWord;   //输入要查询的单词
   JLabel inputWordLabel;  //输入单词标签
   JButton inquire;        //提交按钮
   JTextArea showWord;  //显示查询结果
   HandleQueryOneWord handleQueryOneWord; //负责处理查询单词
   QueryOneWordView(){
      initView();
      registerListener() ;
   }
   private void initView() {
      setBackground(new Color(0,0,0,0));//设置背景透明
      Box boxV = Box.createVerticalBox();//创建列式盒

      JPanel pNorth = new JPanel();//创建面板

      inputWord = new JTextField(12);//创建输入单词输入框
      inputWord.setFont(FontLoader.getCustomFont(15));//设置输入单词输入框字体
      inquire = new JButton("查询单词");
      inquire.setFont(FontLoader.getCustomFont(15));
      inquire.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.green));
      showWord = new JTextArea();
      showWord.setFont(FontLoader.getCustomFont(15));
      inputWordLabel = new JLabel("输入要查询的单词:");
      inputWordLabel.setFont(FontLoader.getCustomFont(15));
      pNorth.add(inputWordLabel);
      pNorth.add(Box.createHorizontalStrut(20));
      pNorth.add(inputWord);
      pNorth.add(Box.createHorizontalStrut(20));
      pNorth.add(inquire);
      boxV.add(pNorth);
      boxV.add(Box.createVerticalStrut(10));

      showWord.setEditable(false);
      JScrollPane scrollPane = new JScrollPane(showWord);
      scrollPane.setPreferredSize(new Dimension(400, 300));
      scrollPane.setBackground(new Color(0,0,0,0));
      boxV.add(scrollPane);

      add(boxV);
   }
   private void registerListener() {
      handleQueryOneWord = new HandleQueryOneWord();
      handleQueryOneWord.setView(this);
      inquire.addActionListener(handleQueryOneWord);
   }
}

5.26 RandomQueryView.java

package src.view;

import src.resource.FontLoader;

import java.awt.*;
import javax.swing.*;

public class RandomQueryView extends JPanel {
    JTextField inputQueryNumber;//输入要查询的单词数目
    JLabel inputQueryNumberLabel;//输入单词数目标签
    JButton submit;            //查询按钮
    JTextArea showWord;       //显示查询结果
    HandleRandomQueryWord handleRandomQueryWord;  //负责处理随机查询单词

    RandomQueryView() {
        initView();
        registerListener();
    }

    public void initView() {
        setBackground(new Color(0, 0, 0, 0));//设置背景透明
        setLayout(null);

        JPanel pNorth = new JPanel();
        inputQueryNumberLabel = new JLabel("输入随机查询的数目:");
        inputQueryNumberLabel.setFont(FontLoader.getCustomFont(15));
        inputQueryNumber = new JTextField(4);
        inputQueryNumber.setFont(FontLoader.getCustomFont(15));
        showWord = new JTextArea();
        showWord.setFont(FontLoader.getCustomFont(15));
        submit = new JButton("查询");
        submit.setFont(FontLoader.getCustomFont(15));

        pNorth.setBounds(0, 0, 800, 50);
        pNorth.setBackground(new Color(0, 0, 0, 0));
        pNorth.add(inputQueryNumberLabel);
        pNorth.add(inputQueryNumber);
        pNorth.add(submit);

        JScrollPane scrollPane = new JScrollPane(showWord);
        scrollPane.setPreferredSize(new Dimension(800, 500));
        scrollPane.setBackground(new Color(0, 0, 0, 0));
        scrollPane.setBounds(0, 50, 746, 350);

        add(pNorth);
        add(scrollPane);
    }

    private void registerListener() {
        handleRandomQueryWord = new HandleRandomQueryWord();
        handleRandomQueryWord.setView(this);
        submit.addActionListener(handleRandomQueryWord);
    }
}

5.27 UpdateWordView.java

package src.view;

import org.jb2011.lnf.beautyeye.ch3_button.BEButtonUI;
import src.resource.FontLoader;
import src.resource.RoundBorder;

import javax.swing.*;//导入javax.swing包中的所有类
import javax.swing.plaf.BorderUIResource;
import java.awt.*;//导入java.awt包中的所有类

public class UpdateWordView extends JPanel {
    JTextField inputWord;        //输入要更新的单词
    JTextField inputNewMeaning;  //输入单词的新解释
    JButton lookWord;            //提交查看
    JButton submit;              //提交更新按钮
    HandleUpdateWord handleUpdateWord;  //负责处理更新单词
    JLabel inputWordLabel, inputWordMeaningLabel, actionLabel;//输入单词标签,输入新的解释标签,提示信息标签
    JPanel contentPanel;//输入面板,提交面板
    UpdateWordView() {
        initView();
        registerListener();
    }

    private void initView() {
        /*
            * 设置布局
            * 该界面分为左右两部分,左边是标签,右边是输入框和按钮
         */
        setBackground(new Color(0, 0, 0, 0));//设置背景透明
        Box boxH, actionBox;                 //行式盒
        Box boxVOne, boxVTwo;      //列式盒
        boxH = Box.createHorizontalBox();
        actionBox = Box.createHorizontalBox();
        boxVOne = Box.createVerticalBox();
        boxVTwo = Box.createVerticalBox();

        boxH.setPreferredSize(new Dimension(400, 167));//设置行式盒大小
        boxVOne.setPreferredSize(new Dimension(100, 167));//设置列式盒大小
        boxVTwo.setPreferredSize(new Dimension(300, 167));//设置列式盒大小

        //初始化组件
        inputWord = new JTextField(30);
        inputWord.setFont(FontLoader.getCustomFont(15));
        inputNewMeaning = new JTextField(30);
        inputNewMeaning.setFont(FontLoader.getCustomFont(15));
        submit = new JButton("提交新的解释");
        submit.setFont(FontLoader.getCustomFont(20));
        submit.setForeground(Color.black);
        submit.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.lightBlue));
        lookWord = new JButton("查看原有解释");
        lookWord.setFont(FontLoader.getCustomFont(20));
        lookWord.setForeground(Color.black);
        lookWord.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.green));
        inputWordLabel = new JLabel("输入单词:");
        inputWordLabel.setFont(FontLoader.getCustomFont(20));
        actionLabel = new JLabel("选择操作:");
        actionLabel.setFont(FontLoader.getCustomFont(20));
        inputWordMeaningLabel = new JLabel("解       释:");
        inputWordMeaningLabel.setFont(FontLoader.getCustomFont(20));

        //往盒子里添加组件
        boxVOne.add(inputWordLabel);
        boxVOne.add(Box.createVerticalStrut(30));
        boxVOne.add(actionLabel);
        boxVOne.add(Box.createVerticalStrut(30));
        boxVOne.add(inputWordMeaningLabel);
        actionBox.add(lookWord);
        actionBox.add(Box.createHorizontalStrut(0));
        actionBox.add(submit);
        boxVTwo.add(Box.createVerticalStrut(0));
        boxVTwo.add(inputWord);
        boxVTwo.add(Box.createVerticalStrut(14));
        boxVTwo.add(actionBox);
        boxVTwo.add(Box.createVerticalStrut(14));
        boxVTwo.add(inputNewMeaning);
        boxH.add(boxVOne);
        boxH.add(Box.createHorizontalStrut(10));
        boxH.add(boxVTwo);

        //创建一个面板,设置边框
        contentPanel = new JPanel();
        contentPanel.setBackground(new Color(0, 0, 0, 0));
        contentPanel.setBorder(new RoundBorder(Color.black));
        contentPanel.add(boxH);
        add(contentPanel);
    }

    private void registerListener() {
        handleUpdateWord = new HandleUpdateWord();
        handleUpdateWord.setView(this);
        submit.addActionListener(handleUpdateWord);
        lookWord.addActionListener(handleUpdateWord);
    }
}


结语

如果有疑问欢迎大家留言讨论,你如果觉得这篇文章对你有帮助可以给我一个免费的赞吗?我们之间的交流是我最大的动力!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/747522.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Antd List组件增加gutter属性后出现横向滚动,如何解决

第一次使用ant design的List列表组件&#xff0c;设置gutter间隔属性后&#xff0c;页面出现了横向滚动条&#xff0c;查阅文档发现是由于加间隔后导致容器宽度被撑开&#xff0c;ant design官方默认给外层容器加了margin-left和margin-right 解决方法是在外层容器预留一定的pa…

stringstream的使用

写到290题使用stringstream简化步骤&#xff0c;学习一下使用 目录 小问题&#xff1f; 成员函数clear() 那么问题来了&#xff1f;clear在啥时候用呢&#xff1f; 数据类型转换 <sstream>库定义了三种类&#xff1a;istringstream、ostringstream、stringstream &l…

RT1176 LCDIFv2 RGB565引脚不连续

RT1052和RT1176的LCDIF&#xff0c;使用RGB565格式时PIN脚分配是连续的:LCDIF_DATA00~LCDIF_DATA15。 但RT1176的LCDIFv2并不是这样&#xff0c;使用RGB565格式时PIN脚分配不是连续的&#xff0c;而是移位填充8位*324位分配的。 RT1176 LCDIFv2 RGB565LCDIF_DATA00LCDIF_DATA0…

CVE漏洞复现-CVE-2021-36934 Windows 提权漏洞

CVE-2021-36934 Windows 提权漏洞 漏洞描述 7月20日&#xff0c;微软确认了一个新的本地提权漏洞&#xff0c;安全研究成员将其称为HiveNightmare或者SeriousSAM&#xff0c;该漏洞允许低权限的用户访问Windows系统文件。成功利用此漏洞的攻击者可以使用SYSTEM特权运行任意代…

16位ADC芯片SGM58031驱动重点

16位ADC芯片SGM58031驱动重点 文章目录 16位ADC芯片SGM58031驱动重点引脚描述时间要求I2C时序图I2C通讯描述I2C接口I2C地址选择I2C常规呼叫I2C速度模式从模式操作 寄存器指针寄存器转换寄存器配置寄存器低阈值和高阈值寄存器Config1寄存器芯片ID寄存器GN_Trim1寄存器&#xff0…

Linux(驱动编程)(调试技术)(imx6ull)

调试技术 1、在写驱动程序时函数未包含头文件 在linux内核源码driver/char目录下输入命令 grep “XXXX” * -nrw查看次函数在那个.c里用过&#xff0c;然后在vscode界面下按altp搜索这个.c就可以参考这个.c的头文件。 2、编译完驱动跟应用后先 insmod xxx.ko //插入 cat /…

原创 | SQL和 NoSQL的基本操作和查询语句

作者&#xff1a;杨金珊本文约3500字&#xff0c;建议阅读7分钟本文为你介绍SQL和 NoSQL的基本操作和查询语句。 SQL&#xff08;结构化查询语言&#xff09; SQL是用于管理和操作关系型数据库的语言。它遵循结构化模式&#xff0c;将数据组织成具有预定义关系的表格形式。以下…

告别被坑!掌握合合信息AI图像篡改检测工具,轻松识别图片造假

文章目录 一、前言1.1 背景与危害1.2会议探讨1.3 技术先行 二、亮点技术1&#xff1a;AI图像篡改检测技术2.1 传统方法Python实现步骤2.2 合合信息——PS纂改检测体验 三、亮点技术2&#xff1a;生成式图像鉴别3.1 生成式图像安全问题3.2 传统方法Python实现步骤3.2 合合信息—…

03_007linux内存管理架构以虚拟内存空间布局架构

内存管理子系统架构 内存管理子系统架构可以分为:用户空间、内核空间及硬件部分3个层面&#xff0c;具体结构如 下图所示: 1、用户空间:应用程序使用malloc()申请内存资源/free()释放内存资源。 2、内核空间:内核总是驻留在内存中&#xff0c;是操作系统的一部分。内核空间为内…

nginx uwsgi配置django

uwsgi文件 [uwsgi] # 服务端口号&#xff0c;这里没有设置IP值&#xff0c;默认是加载服务器的IP地址 #http :5000 socket:8000 # flask项目地址 chdir /pyprogram/electric # wsgi文件 /home/flask_project/mange.py #module app:app wsgi-file/pyprogram/electric/electr…

CompletionService的基本使用以及原理

文章目录 一、CompletionService的简介二、CompletionService的底层大致原理三、CompletionService的使用场景1. 批量下载文件&#xff1a;2. 多个商品价格查询&#xff1a;3. 并发处理多个API请求&#xff1a; 四、CompletionService的使用demo1. 代码如下&#xff1a;2. 案例…

mac上 如何批量在文件名中插入文字

mac上 如何批量在文件名中插入文字&#xff1f;在使用Mac电脑的时候&#xff0c;我们经常需要对大量文件的名称进行修改&#xff0c;例如需要在大量文件的名称中插入一些相同的文字或者字符的时候&#xff0c;你会用什么方法来完成这项工作呢&#xff1f;相信很多人就面对过类似…

前端vue入门(纯代码)30_路由的props配置

喜欢的东西太贵了&#xff0c;我一咬牙&#xff0c;狠下心决定不喜欢了&#xff01; 【28.Vue Router--路由的props配置】 props配置官网文档 props属性用法和params属性差不多&#xff0c;都是要在src/router/index.js文件中配置 // 该文件专门用于创建整个应用的路由器 i…

Spring 项目的创建和使用1(配置国内源)

目录 一、Spring项目的创建 1. 创建Maven项目 2. 添加Spring依赖&#xff08;重要&#xff09; (1) 必须要设置两个配置文件的国内源配置&#xff08;当前项目配置文件&#xff0c;新项目配置文件&#xff09; (2) 复制上一步中的User setting file 后面的路径在文件资源管理…

SpringBoot集成Flowable工作流

SpringBoot集成Flowable工作流 Flowable是什么&#xff1f;一、添加依赖二、flowable配置三、定义流程文件1.使用流程文件定义工作流2.idea使用插件来定义流程图1.安装插件2.创建bpmn文件并画流程图3.右击流程用模型设计器打开文件 四、测试controller Flowable是什么&#xff…

美女与修狗儿【 InsCode Stable Diffusion 美图活动一期】

女朋友最近买了一只小泰迪&#xff0c;于是给她和修狗儿做一幅画 一、Stable Diffusion 模型在线使用地址 https://inscode.csdn.net/inscode/Stable-Diffusion 二、模型版本及相关配置 模型&#xff1a;chilloutmix-Ni.safetensors[7234b76e42采样方法&#xff1a;Euler a…

算法拾遗三十五indexTree和AC自动机

算法拾遗三十五indexTree和AC自动机 indexTree&#xff08;树状数组&#xff09;indexTree规则 IndexTree二维AC自动机 indexTree&#xff08;树状数组&#xff09; 给定数组下标统一从1开始 如果要求L。。R范围上任意区间的和&#xff0c;我们通常的解法是定义一个help&…

msvcp140.dll重新安装的解决方法,msvcp140.dll丢失修复教程

计算提示msvcp140.dll丢失需要怎么重新安装呢&#xff1f;下面小编就把msvcp140.dll丢失重新安装的修复教程分享给大家。msvcp140.dll是Microsoft Visual C Redistributable文件的一部分&#xff0c;它是一个动态链接库文件。该文件包含了一些用于C程序开发的函数和类的定义&am…

【Vue2.0源码学习】模板编译篇-模板解析阶段(HTML解析器)

文章目录 1. 前言2. HTML解析器内部运行流程3. 如何解析不同的内容3.1 解析HTML注释3.2 解析条件注释3.3 解析DOCTYPE3.4 解析开始标签3.5 解析结束标签3.6 解析文本 4. 如何保证AST节点层级关系5. 回归源码5.1 HTML解析器源码5.2 parseEndTag函数源码 6. 总结 1. 前言 上篇文…

如何应对ChatGPT这一波AI浪潮

最近我在写一系列文章&#xff0c;其中包括《ChatGPT 实战系列》和《WPS Office AI实战系列》。想通过这些文章提供实践指导&#xff0c;既自己动手实践了&#xff0c;也能与大家分享我的实践结果&#xff0c;这是一个学习的过程。在实践过程中&#xff0c;我发现有些实用的方面…