项目名称:背单词软件


完整代码链接:完整代码+txt文件
提取码:i6gd
有注释,看懂没什么问题


问题描述:

用户登录软件后可选择多个功能,最重要的功能:背单词、查单词、修改用户信息。
背单词:点击背单词的按钮之后,会让用户选择记忆模式,随后进行背单词。
查单词:查单词允许用户增删改查单词并同步到txt文件。
修改用户信息:修改用户信息允许用户改密码、忘记密码。
另外软件登录页面和主页面需要有背景图片。

解决方案:

1、界面设计
界面用Swing组件,对组件的点击以及滑动用AWT的事件处理
2、文本文件的输入输出
用File类、PrintWriter类、Scanner类解决
在此碰到了一个更新文本文件的问题的解决方案:更新文本文件的数据
3、弹窗的设计
让此窗口消失,弹窗设为可见

主要的功能和面板实现:

1、登录界面

package exercise;import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;public class LoginFrame {public LoginFrame(User user){JFrame jFrame = new JFrame("Login");jFrame.setLayout(new FlowLayout());JLabel accountLabel = new JLabel("Account:");JPanel panel = new JPanel();panel.setLayout(new GridLayout(2,1));JPanel panel1 = new JPanel();JTextField accountTextField = new JTextField(18);JLabel passwordLabel = new JLabel("Password:");JPasswordField passwordTextField = new JPasswordField(18) ;JButton enterButton = new JButton("Enter");JButton registeredButton =  new JButton("Registered");//给登录界面窗口添加背景图片ImageIcon imageIcon = new ImageIcon("src\\222.png");JLabel jLabel = new JLabel(imageIcon);jFrame.getLayeredPane().add(jLabel,new Integer(Integer.MIN_VALUE));jLabel.setBounds(20,0,imageIcon.getIconWidth(),imageIcon.getIconHeight());Container container = jFrame.getContentPane();((JPanel)container).setOpaque(false);//点击登录界面的确定按钮,若密码正确则将进入主页面,否则重新输入enterButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {if(user.getPassword().equals(passwordTextField.getText()) && user.getAccount().equals(accountTextField.getText())){new Menu(user);jFrame.setVisible(false);}else{new PasswordErrorFrame();}}});//点击注册按钮进入到注册页面,此页面消失registeredButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {new RegisteredFrame(user);jFrame.setVisible(false);}});panel.add(accountLabel);panel.add(accountTextField);panel.add(passwordLabel);panel.add(passwordTextField);panel1.add(enterButton);panel1.add(registeredButton);jFrame.add(panel);jFrame.add(panel1);jFrame.setBounds(550,250,400,150);jFrame.setVisible(true);}
}

2、注册界面

package exercise;import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.security.cert.PolicyNode;public class RegisteredFrame {public RegisteredFrame(User user){JFrame jFrame = new JFrame("Registered");jFrame.setLayout(new GridLayout(4,1));JPanel jPanel1 = new JPanel(new FlowLayout());JPanel jPanel2 = new JPanel(new FlowLayout());JPanel jPanel3 = new JPanel(new FlowLayout());JPanel jPanel4 = new JPanel(new FlowLayout());JLabel accountLabel = new JLabel("Account:");JTextField accountTextField = new JTextField(18);JLabel passwordLabel = new JLabel("Password:");JPasswordField passwordTextField = new JPasswordField(18);JLabel checkPasswordLabel = new JLabel("Re-check password:");JPasswordField checkPasswordTextField = new JPasswordField(18);JButton enterButton = new JButton("Enter");JButton returnButton  = new JButton("Return");//输入完信息后点击确定按钮,检测两次输入的密码是否一致,若一致则注册成功,弹窗注册成功信息,否则弹出密码不一致窗口enterButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {if(checkPasswordTextField.getText().equals(passwordTextField.getText()) && (passwordTextField.getText().length()!=0 && checkPasswordTextField.getText().length()!=0) ){//注册成功之后,同步更改用户名和密码user.setAccount(accountTextField.getText());user.setPassword(passwordTextField.getText());//弹出注册成功的窗口new RegisteredState(user,true,jFrame);}else{//弹出密码不一致窗口new RegisteredState(user,false,jFrame);}}});//点击返回键,返回到登录界面,此页面消失returnButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {jFrame.setVisible(false);new LoginFrame(user);}});jPanel1.add(accountLabel);jPanel1.add(accountTextField);jPanel2.add(passwordLabel);jPanel2.add(passwordTextField);jPanel3.add(checkPasswordLabel);jPanel3.add(checkPasswordTextField);jPanel4.add(enterButton);jPanel4.add(returnButton);jFrame.add(jPanel1);jFrame.add(jPanel2);jFrame.add(jPanel3);jFrame.add(jPanel4);jFrame.setVisible(true);jFrame.setBounds(550,250,400,150);}
}

3. 软件的主菜单界面

package exercise;import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;public class Menu {public Menu(User user) {JFrame frame = new JFrame("背单词软件");frame.setLayout(new FlowLayout());JPanel panel = new JPanel(new GridLayout(1,4));JButton wordListButton = new JButton("WordList");JButton userButton = new JButton("User");JButton button = new JButton("Memorize");JButton returnButton = new JButton("Rreturn Login");//为主页面添加背景ImageIcon imageIcon = new ImageIcon("src\\2.gif");JLabel jLabel = new JLabel(imageIcon);frame.getLayeredPane().add(jLabel,new Integer(Integer.MIN_VALUE));jLabel.setBounds(0,0,imageIcon.getIconWidth(),imageIcon.getIconHeight());Container container = frame.getContentPane();((JPanel)container).setOpaque(false);//设置主页面的三个板块的字体颜色和字体样式wordListButton.setForeground(Color.blue);userButton.setForeground(Color.blue);button.setForeground(Color.blue);returnButton.setForeground(Color.blue);wordListButton.setFont(new Font("微软雅黑",Font.BOLD,16));userButton.setFont(new Font("微软雅黑",Font.BOLD,16));button.setFont(new Font("微软雅黑",Font.BOLD,16));returnButton.setFont(new Font("微软雅黑",Font.BOLD,16));/*WordList界面点击WordList,进入到单词表的窗口,此页面消失*/wordListButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {try{new WordList(user);frame.setVisible(false);}catch (Exception exception){exception.printStackTrace();}}});returnButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {new LoginFrame(user);frame.setVisible(false);}});/*User界面点击User,进入到单词表的窗口,此页面消失*/userButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {new UserFrame(user);frame.setVisible(false);}});/*背单词点击Memorize,进入到单词表的窗口,此页面消失*/button.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {frame.setVisible(false);new SelectMemorizeModel(user,frame);}});panel.add(wordListButton);frame.add(button);panel.add(userButton);frame.add(panel);frame.add(returnButton);frame.setVisible(true);//     frame.setSize(700,800);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setBounds(650,250,300,300);}
}

4. 软件的单词表界面

package exercise;import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;public class WordList {public WordList(User user) throws IOException {JFrame jFrame = new JFrame("User`s WordList");jFrame.setLayout(new FlowLayout());JList list = new JList();Panel panel = new Panel();JButton returnButton = new JButton("return menu");JButton addButton = new JButton("add new word");JScrollPane jScrollPane = new JScrollPane(list);//设置下滑组件的属性jScrollPane.setSize(350,300);jScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);jScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);//给单词表添加背景ImageIcon imageIcon = new ImageIcon("src\\wordlist.webp");JLabel jLabel = new JLabel(imageIcon);jFrame.getLayeredPane().add(jLabel,new Integer(Integer.MIN_VALUE));jLabel.setBounds(0,0,imageIcon.getIconWidth(),imageIcon.getIconHeight());Container container = jFrame.getContentPane();((JPanel)container).setOpaque(false);//点击return按钮返回到主页面returnButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {new Menu(user);jFrame.setVisible(false);}});//点击add new word按钮添加单词addButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {new AddFrame(user,jFrame);}});//将文件中的单词显示到界面上String[] wordList = new String[300000];list.setListData(StoreWordList(wordList));//设置选中时候的颜色宽度list.setPreferredSize(new Dimension(350,300));//设置列表可以多选list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);//点击列表中的一个word弹出删、改、取消操作窗口list.addListSelectionListener(new ListSelectionListener() {@Overridepublic void valueChanged(ListSelectionEvent e) {if(!e.getValueIsAdjusting()){ListModel<String> listModel = list.getModel();new Operation(user,listModel.getElementAt(list.getSelectedIndex()),jFrame);}}});panel.add(jScrollPane);jFrame.add(returnButton,BorderLayout.NORTH);jFrame.add(panel,BorderLayout.CENTER);jFrame.add(addButton,BorderLayout.SOUTH);jFrame.setBounds(600,200,400,300);jFrame.setVisible(true);}//将文件中的单词储存在字符串数组中并且返回private String[] StoreWordList(String[] wordList) throws IOException{int count = 0;File file = new File("WordList.txt");Scanner scanner = new Scanner(file);while(scanner.hasNext()){wordList[count ++] = scanner.nextLine();}scanner.close();return wordList;}}

5.软件的选择记忆模式界面

package exercise;import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;/*Introduction:此类为选择记忆模式类,逻辑如下:一个单选框,选择随机还是顺序,再点击确认进入到背单词的界面中*/public class SelectMemorizeModel {public SelectMemorizeModel(User user,JFrame superFrame){JFrame jFrame = new JFrame("select model");jFrame.setLayout(new GridLayout(2,1));Panel panel1 = new Panel(new FlowLayout());Panel panel2 = new Panel(new FlowLayout());JButton button1 = new JButton("Enter");JRadioButton jButton1 = new JRadioButton("random");JRadioButton jButton2 = new JRadioButton("ordered");JButton button2 = new JButton("Cancel");JLabel jLabel = new JLabel("select model:");ButtonGroup gp = new ButtonGroup();//回到主页面button2.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {superFrame.setVisible(true);jFrame.setVisible(false);}});//将两个单选按钮加入到一个按钮组gp.add(jButton1);gp.add(jButton2);//进入到背单词页面button1.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {if(jButton1.isSelected()){try {new Memorize(user,true);} catch (FileNotFoundException | InterruptedException fileNotFoundException) {fileNotFoundException.printStackTrace();}}else{try {new Memorize(user,false);} catch (FileNotFoundException | InterruptedException fileNotFoundException) {fileNotFoundException.printStackTrace();}}jFrame.setVisible(false);superFrame.setVisible(false);}});panel1.add(jLabel);panel1.add(jButton1);panel1.add(jButton2);panel2.add(button1);panel2.add(button2);jFrame.add(panel1);jFrame.add(panel2);jFrame.setVisible(true);jFrame.setBounds(650,250,250,250);}
}

6.软件的背单词界面

package exercise;import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Random;
import java.util.Scanner;/*Introduction:两个参数,一个user,一个flaguser:用户对象flag:true为随机,false为顺序此类为背单词类,逻辑如下:顺序:从第一个到最后一个从文本中一个一个读随机:创建一个随机数,指定文本的第几个单词*/public class Memorize {//按照顺序背,现在是第 count 个单词static int count = 0;//flag为true就是选中randompublic Memorize(User user,boolean flag) throws FileNotFoundException, InterruptedException {JFrame jFrame = new JFrame("Memorize");JButton enterButton = new JButton("Enter");JButton pauseButton = new JButton("pause");JPanel jPanel1 = new JPanel(new FlowLayout());JPanel jPanel2 = new JPanel();JPanel jPanel3 = new JPanel(new FlowLayout());jFrame.setLayout(new GridLayout(4,1));JLabel engilsh = new JLabel("Word:");JLabel chinese = new JLabel("Chinese mean:");JTextField jTextField = new JTextField(8);enterButton.setVisible(true);String answer = new String();//顺序if(flag == false) {File file = new File("WordList.txt");Scanner scanner = new Scanner(file);for (int i = 0; i < Memorize.count; i++) {if (scanner.hasNext()) {scanner.nextLine();}}if (scanner.hasNext()) {String eg = scanner.next();engilsh.setText("Word:" + eg);} else {new AllIsOkDialog(user, jFrame, flag);}String ch = scanner.next();answer = ch;//点击确认,系统判定并弹窗是否回答正确enterButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {if(jTextField.getText().equals(ch)){new YesDialog(user,jFrame,flag);}else{new NoDialog(user,jFrame,flag);}}});}//随机else{File file = new File("WordList.txt");Scanner scanner = new Scanner(file);int id =(int) ((Math.random())* (user.wordListNumber) + 1);for(int i = 0; i < id - 1; i++){if (scanner.hasNext()) {scanner.nextLine();}}if (scanner.hasNext()) {String eg = scanner.next();engilsh.setText("Word:" + eg);} else {new AllIsOkDialog(user, jFrame, flag);}//answerString ch = scanner.next();answer = ch;//点击确认,系统判定并弹窗是否回答正确enterButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {if(jTextField.getText().equals(ch)){new YesDialog(user,jFrame,flag);}else{new NoDialog(user,jFrame,flag);}}});}//点击终止返回到主页面pauseButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {new Menu(user);jFrame.setVisible(false);}});jPanel1.add(engilsh);jPanel3.add(chinese);jPanel3.add(jTextField);jPanel2.add(enterButton);jPanel2.add(pauseButton);jFrame.add(jPanel1);jFrame.add(jPanel3);jFrame.add(jPanel2);jFrame.setVisible(true);jFrame.setBounds(650,250,250,250);}
}

7.软件的用户信息界面

package exercise;import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;public class UserFrame {public UserFrame(User user){JFrame jFrame = new JFrame("User Information");Panel panel = new Panel(new FlowLayout());JLabel accountLabel = new JLabel("account:" + user.getAccount());JLabel boundPhoneLabel = new JLabel("boundphone:" + user.getBoundPhone());JButton button = new JButton("return");JButton button1 = new JButton("change password");JButton button2 = new JButton("forget password");//返回到主页面button.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {new Menu(user);jFrame.setVisible(false);}});//进入修改密码界面button1.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {jFrame.setVisible(false);new changePassword(user);}});//进入忘记密码界面button2.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {new ForgetPasswordFrame(user);jFrame.setVisible(false);}});/*ImageIcon imageIcon = new ImageIcon("src\\2.gif");JLabel jLabel = new JLabel(imageIcon);jFrame.getLayeredPane().add(jLabel,new Integer(Integer.MIN_VALUE));jLabel.setBounds(0,0,imageIcon.getIconWidth(),imageIcon.getIconHeight());Container container = jFrame.getContentPane();((JPanel)container).setOpaque(false);*/panel.add(accountLabel);panel.add(boundPhoneLabel);panel.add(button1);panel.add(button2);panel.add(button);jFrame.add(panel);jFrame.setBounds(600,250,400,100);jFrame.setVisible(true);}
}

大一下学期基于GUI的背单词软件(JAVA版)相关推荐

  1. 计算机英语在线学习,英语单词记忆法超强记忆_免费背单词软件电脑版

    英语单词记忆法超强记忆_免费背单词软件电脑版 下载地址: 内容预览 如何背英语单词personify.mp4 如何背英语单词dote.mp4 如何背英语单词coddle.mp4 如何背英语单词drow ...

  2. 计算机考研英语听力,考研英语2背单词软件电脑版哪个最好用_听力背单词

    考研英语2背单词软件电脑版哪个最好用_听力背单词 下载地址: 内容预览 考研英语二背单词软件aside.mp4 考研英语二背单词软件bare.mp4 考研英语二背单词软件cast.mp4 考研英语二背 ...

  3. java背单词软件_图灵单词王手机背单词软件大学版 For JAVA

    研究表明,通常人脑的记忆过程是经验性的而非科学性的,大量的知识因得不到及时的巩固而遗忘,造成大量的无效重复学习,因此人脑对学习过程的管理是盲目而低效率的. 图灵单词王英语单词智能记忆软件根据国际领先的 ...

  4. Android的背单词软件

    基于Android的背单词软件设计与实现 emmmm 本系统带程序说明书   有需要的可以去我上传的资源里面找,找不到的话,评论我,或者站内私信留下邮箱, 我看到机会给你发,也可以主动联系我博客名. ...

  5. ⚡写一个有发音的背单词软件⚡——四六级必过系列

    四六级必过 ⚡导读 演示 爬虫阶段 GUI阶段 朗读单词阶段 封装阶段 ⚡肥学有话说 ⚡导读 你还在为小小英语而发愁吗?,你还在为备考四六级没有动力而难过吗?那么今天教你写一个背单词软件你不会不想学吧 ...

  6. C语言实现背单词软件(系统级别)

    目录 一.软件需求说明书 1 引言 2 任务概述 二.可行性研究报告 1 编写目的 2 所建议的系统(技术可行性) 3 使用方面的可行性 4 结论 三.系统设计说明书 1.面向对象设计 1.1前提说明 ...

  7. 背单词软件 单词风暴 分享id_周一考研高效背单词系列(一):利用单词软件如何背好单词...

    高效背单词 考研单词作为考研路上的第一大难关,相信很多小伙伴都在这上面吃过不少苦,有同学更是看到密密麻麻的大纲词汇就头疼,但只要是学习就是有方法的,今天,我们开始推出高效背单词系列--墨墨背单词. 另 ...

  8. 可以测试成果的背单词软件,实测背单词最好的软件排名,选了4款最管用的单词软件送给你!...

    目前市面上单词软件千千万,哪一款才是我的菜?这个时候通过查看背单词最好的软件排名情况,能让我们快速找到适合自己的背单词软件.每个人基础不一样,比如有的人英语是零基础的,有的人英语是达到四级水平,他们两 ...

  9. 轻轻松松背单词软件测试,MBA联考十佳背单词软件测评报告

    背英语单词是最令人头疼的事儿,如果能选择一套适合的背单词软件,对于单词记忆会有事半功倍的效果,然而目前市场上背单词软件到处都是,我们应该选择什么软件呢,这确实是件另人头疼的事,选到好的,对我们的学习也 ...

最新文章

  1. java struts技术_java技术框架之:struts
  2. 一个有效的OKR是什么样?
  3. hasOwnProperty
  4. 如何处理VirtualBox启动错误消息:The vboxdrv kernel module is not loaded
  5. php 复选框组,php – 选择所有复选框
  6. 销售额分布直方图和茎叶图
  7. java和python和php_Java、Python和PHP三者的区别
  8. 大数据时代投资者应如何利用数据资源盈利
  9. RGB与YUV的转换
  10. java 定时缓存的实现
  11. 【MIKE21】MIKE21笔记-HD
  12. GoLang之iface 和 eface 的区别是什么(3)
  13. Python语言为何如此流行?
  14. 用键盘输入一位整数,当输入1~7时,显示对应的英文星期名称的缩写。
  15. 如何将一个向量投影到一个平面上_向量的各种积
  16. pygraphviz win7安装报错解决
  17. 达梦数据库报错“[警告]Error Code:-70037,字符串不完整”
  18. 解决电脑C盘空间不足,发现微信和qq文件占用了大量内存
  19. [软考]净现值NPV详细解释及应用,实例讲解收集(信息系统项目管理师-立项管理)...
  20. 《深度学习进阶 自然语言处理》第五章:RNN通俗介绍

热门文章

  1. ApiCloud 检出错误的解决
  2. 各厂家售后技术支持热线收集
  3. 鸿蒙harmonyOS在DevEco Studio 打Log日志
  4. 如何在桌面上显示我的计算机,怎么在桌面显示我的电脑 - 卡饭网
  5. Bootstrap table设置th,td内容水平、垂直居中
  6. 孙鑫VC学习笔记:第七讲
  7. 北京内推 | 智源人工智能研究院招聘数据智能/视觉方向算法工程师/研究员
  8. HTML网页规划与设计【冬季奥林匹克运动会——带报告5200字】HTML+CSS+JavaScript
  9. 中秋--吃月饼,还不如就看看吧
  10. Python爬虫入门教程27:爬取某电商平台数据内容并做数据可视化