作业二

我调查的项目是英语学习软件的改进,这个项目包含很广,这里,我选择了电脑被单词软件作为开发项目。

1 概述

 

1.1 开发背景

  随着时代的发展,全球化越来越快,英语也就显得很重要,学习英语的人员也是日益增多,传统的查阅字典等方法已经不足以满足人们的需要。电脑的普及使得使用电脑被单词可以为每个人所接受,因此开发电脑背单词软件。

1.2 开发目标

  背单词软件的目的就是建立一个客户平台,用户使用此平台进行单词翻译、单词查询、加入生词库等。

  要求主要实现以下功能模块:

1)   用户能够导入导出词库;

2)   用户可以选择是否显示单词的音标、中文解释等;

3)   用户可以选择屏幕前端显示的单词的更新速度、背景和前景等;

4)   用户可以拖动显示的单词条到屏幕的任何位置;

5)   提供生词本功能,用户可以随时添加生词,并选择生词库作为当前词库。

 

1.3 参考资料

1.4 设计原则

2 需求分析

2.1 需求陈述

  首先是用户登录

  

  登录成功后可进行四种操作,一是查询,二是查看,三是修改密码,四是生词库(查询如下)

  

2.2 操作用例

2.3 功能分析划分

2.5 运行环境

3 总体设计

3.1 系统建模

3.1.1 层次方框图

3.1.2  ER图(实体-联系图)

3.1.3 类图设计

3.2 接口设计

3.2.1 内部接口设计

3.2.2 登录界面设计

3.2.3 用户管理界面设计

3.3 数据库结构设计

  使用access进行数据库设计,主要包括四个表:

3.3.1 数据库E-R图

3.3.2 数据库逻辑设计

2.5 出错处理 

2.6 安全保密设计

4 详细设计

4.1 程序流程图

4.2 伪代码编写

5 实现

5.1 编码

登录:

public void actionPerformed(ActionEvent e) {

        if (e.getSource() == enroll) {

            new EnrollWindow();

        } else if (e.getSource() == login) {

            String log_sno = tsno.getText();

            String log_spwd = ppwd.getText();

            DataBase db = new DataBase();

            if (log_sno==null || log_spwd==null) {

                JOptionPane.showMessageDialog(rootPane, "登陆信息不全,请补充");

            } else {

                if (db.isValidUser(log_sno, log_spwd)) {

                    isLogin = true;

                    JOptionPane.showMessageDialog(rootPane, "欢迎回来," + db.getSname(log_sno) + "。您可以使用您的生词本等个性化功能了!");

                    dic.writeToWordbok.setEnabled(true);

                    dic.wordbook.setEnabled(true);

                    currentSname = db.getSname(log_sno);

                    currentSno = log_sno;

                    p5.removeAll();

                    p5.revalidate();

                    p5.add(new JLabel("欢迎回来,"));

                    p5.add(new JLabel(db.getSname(log_sno)));

                    p5.add(new JLabel("上次学习:"));

                    p5.add(new JLabel("2012-03-10"));

                    p5.add(new JLabel("总共学习:"));

                    p5.add(new JLabel("5 次"));

                } else {

                    JOptionPane.showMessageDialog(rootPane, "信息错误,登陆失败");

                }

            }

        }

    }  

背单词

package 背单词系统;

 

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.event.*;

import javax.swing.table.*;

 

public class Dic extends JPanel implements ActionListener, ListSelectionListener, KeyListener, MouseListener {

    //输入输出的文本域作为数据域

 

    private JTextField inputMessage = new JTextField();

    private JButton jbt = new JButton("搜索");

    private JTextArea outputMessage = new JTextArea();

    private JScrollPane scrollPane1 = new JScrollPane(outputMessage);

    private JList list = new JList();

    private JScrollPane scrollPane2 = new JScrollPane(list);

    private JButton antiSeach = new JButton("反查");

    JButton writeToWordbok = new JButton("加入生词本");

    JButton wordbook = new JButton("查看生词本");

    JTable jTable;

    DefaultTableModel jTableModel;

    private DataBase db;

    private WordData wdb;

    private MainFrame m;

    private JLabel wb_jlb = new JLabel();

    private String currentWord = "";

    private JButton deleteFromWordbook, test;

 

    //输出面板的构造函数

    public Dic(MainFrame m) {

        this.m = m;

        db = new DataBase();

        wdb = new WordData();

        createWordbookTable();

 

        //对本面板的设置

        this.setLayout(null);

        setPreferredSize(new Dimension(500, 350));

        javax.swing.border.LineBorder lineBorder = new javax.swing.border.LineBorder(Color.black, 1);

        add(new JLabel("请输入单词")).setBounds(0, 0, 100, 25);

        //输入主窗口JTextfield 的设置

        inputMessage.setHorizontalAlignment(JTextField.LEFT);

        inputMessage.setFont(new Font("宋体", Font.BOLD, 15));

        inputMessage.setBorder(lineBorder);

        inputMessage.selectAll();

        add(inputMessage).setBounds(100, 0, 300, 25);

        //按钮设置

        add(jbt).setBounds(400, 0, 100, 25);

 

        outputMessage.setFont(new Font("Times", Font.BOLD, 15));

        outputMessage.setBorder(lineBorder);

        outputMessage.setEditable(false);

        outputMessage.setLineWrap(true);

        outputMessage.setWrapStyleWord(true);

        outputMessage.setBackground(new Color(Color.HSBtoRGB(11, 11, 66)));

        //对衍生词输出面板的设置,是一个JList

        list.setBackground(new Color(Color.HSBtoRGB(21, 99, 66)));

        JScrollPane scrollPane2 = new JScrollPane(list);

        add(scrollPane2).setBounds(0, 25, 100, 300);

        add(outputMessage).setBounds(100, 25, 400, 270);

        add(antiSeach).setBounds(100, 295, 133, 28);

        add(writeToWordbok).setBounds(233, 295, 133, 28);

        add(wordbook).setBounds(366, 295, 134, 28);

        writeToWordbok.setEnabled(false);

        wordbook.setEnabled(false);

 

        inputMessage.addActionListener(this);

        jbt.addActionListener(this);

        list.addListSelectionListener(this);

        inputMessage.addKeyListener(this);

        antiSeach.addActionListener(this);

        wordbook.addActionListener(this);

        writeToWordbok.addActionListener(this);

    }

 

    public void actionPerformed(ActionEvent e) {

        if (e.getSource() == inputMessage) {

            try {

                String tmp = inputMessage.getText();

                //判断输入是中文还是英文,选择相对应的搜索方法

                if (Search.isChiString(tmp)) {

                    String answer = Search.c2esearch(tmp, wdb);

                    outputMessage.setText(answer);

                } else {

                    String answer = Search.e2csearch(tmp, wdb);

                    outputMessage.setText(tmp + "\n\n" + answer);

                    currentWord = tmp;

                }

            } catch (Exception ex) {

            }

        } else if (e.getSource() == jbt) {

            try {

                String tmp = inputMessage.getText();

                //判断输入是中文还是英文,选择相对应的搜索方法

                if (Search.isChiString(tmp)) {

                    String answer = Search.c2esearch(tmp, wdb);

                    outputMessage.setText(answer);

                } else {

                    String answer = Search.e2csearch(tmp, wdb);

                    outputMessage.setText(tmp + "\n\n" + answer);

                    if (!Search.getIsSimSearch()) {

                        currentWord = tmp;

                    } else {

                        currentWord = "";

                    }

                }

            } catch (Exception ex) {

            }

        } else if (e.getSource() == antiSeach) {

            String tmp = outputMessage.getSelectedText();

            try {

                inputMessage.setText(tmp);

                //判断输入是中文还是英文,选择相对应的搜索方法

                if (Search.isChiString(tmp)) {

                    String answer = Search.c2esearch(tmp, wdb);

                    outputMessage.setText(answer);

                } else {

                    String answer = Search.e2csearch(tmp, wdb);

                    outputMessage.setText(tmp + "\n\n" + answer);

                }

            } catch (Exception ex) {

            }

        } else if (e.getSource() == wordbook) {

            m.p7.removeAll();

            m.p7.revalidate();

            wb_jlb.setText("生词本 ");

            wb_jlb.setFont(new Font("宋体", Font.BOLD, 15));

            wb_jlb.setHorizontalAlignment(JLabel.CENTER);

            wb_jlb.setOpaque(true);

            wb_jlb.setBackground(new Color(Color.HSBtoRGB(11, 11, 66)));

            m.p7.add(wb_jlb).setBounds(0, 0, 300, 23);

            m.currentSno = m.getCurrentSno();

            createWordbookTable();

            setWordbookTableVisable();

 

            deleteFromWordbook = new JButton("删除生词");

            test = new JButton("生词测试");

            deleteFromWordbook.addActionListener(this);

            m.p7.add(deleteFromWordbook).setBounds(0, 300, 149, 25);

            m.p7.add(test).setBounds(150, 300, 149, 25);

        } else if (e.getSource() == writeToWordbok) {

            if (currentWord==null) {

                JOptionPane.showMessageDialog(this, "您没有选择一个合法的单词");

            } else {

                m.currentSno = m.getCurrentSno();

                db.writeToWorkbook(currentWord, m.currentSno);

                refreshWordbookTable(jTable);

                JOptionPane.showMessageDialog(this, "添加成功!");

            }

        } else if (e.getSource() == deleteFromWordbook) {

            String tempword = null;

            if (jTable.getSelectedRow() < 0) {

                JOptionPane.showMessageDialog(this, "您没有选中一个词");

            }

            tempword = jTable.getValueAt(jTable.getSelectedRow(), 0).toString();

            m.currentSno = m.getCurrentSno();

            db.deleteFromWordBook(tempword, m.currentSno);

            refreshWordbookTable(jTable);

            JOptionPane.showMessageDialog(this, "删除成功!");

        }

    }

 

    public void valueChanged(ListSelectionEvent e) {

        if (e.getSource() == list) {

            //当选中相应的单词,显示其意思

            try {

                Object tmp = list.getSelectedValue();

                String tmps = (String) tmp;

 

                if (Search.isChiString(tmps)) {

                    String answer = Search.c2esearch(tmps, wdb);

                    outputMessage.setText(answer);

                } else {

                    String answer = Search.e2csearch(tmps, wdb);

                    outputMessage.setText(tmps + "\n\n" + answer);

                    currentWord = tmps;

                }

            } catch (Exception ex) {

            }

        }

    }

 

    public void keyReleased(KeyEvent e) {

        if (e.getSource() == inputMessage) {

            //即时搜索功能

            String[] nearAnswer = new String[15];

            String tmp = inputMessage.getText();

            try {//判断输入是中文还是英文,选择相对应的搜索方法

                if (Search.isChiString(tmp)) {

                    nearAnswer = Search.newC2ESearch(tmp, wdb);

                    list.setListData(nearAnswer);

                } else {

                    nearAnswer = Search.newE2CSearch(tmp, wdb);

                    list.setListData(nearAnswer);

                }

            } catch (Exception ex) {

            }

        }

    }

 

    public void mouseClicked(MouseEvent e) {

    }

 

    public void keyTyped(KeyEvent e) {

    }

 

    public void keyPressed(KeyEvent e) {

    }

 

    public void mousePressed(MouseEvent e) {

        throw new UnsupportedOperationException("Not supported yet.");

    }

 

    public void mouseReleased(MouseEvent e) {

        throw new UnsupportedOperationException("Not supported yet.");

    }

 

    public void mouseEntered(MouseEvent e) {

        throw new UnsupportedOperationException("Not supported yet.");

    }

 

    public void mouseExited(MouseEvent e) {

        throw new UnsupportedOperationException("Not supported yet.");

    }

 

    public void createWordbookTable() {

        String[][] testValue = new DataBase().getTestValue(m.currentSno);

        String[] testTitle = {"单词", "用户"};

        jTableModel = new DefaultTableModel(testValue, testTitle);

        jTable = new JTable(jTableModel);

        jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);//将表的重新设置大小功能去掉

        jTable.setRowHeight(20);

        TableColumn firsetColumn = jTable.getColumnModel().getColumn(0);

        TableColumn secondColumn = jTable.getColumnModel().getColumn(1);

        firsetColumn.setPreferredWidth(130);

        secondColumn.setPreferredWidth(130);

    }

 

    public void setWordbookTableVisable() {

        JScrollPane jScrollPane = new JScrollPane(jTable);

        m.p7.add(jScrollPane).setBounds(20, 24, 280, 275);

    }

 

    public void refreshWordbookTable(JTable t) {

        String[][] testValue = new DataBase().getTestValue(m.currentSno);

        String[] testTitle = {"单词", "用户"};

        jTableModel.setDataVector(testValue, testTitle);

        jTableModel.fireTableStructureChanged();

        jTable.setModel(jTableModel);

        TableColumn firsetColumn = jTable.getColumnModel().getColumn(0);

        TableColumn secondColumn = jTable.getColumnModel().getColumn(1);

        firsetColumn.setPreferredWidth(130);

        secondColumn.setPreferredWidth(130);

        jTable.repaint();

        jTable.revalidate();

        jTable.updateUI();

    }

}

5.2 测试要点

5.2.1 登录测试要点

登入测试:在登入测试是在登入页面开始在输入用户名和密码登入时自动区分主页和用户,使主页管理员在进入主页后能使用后台功能。登入测试用例表6-1所示:

表5-1登入测试用例

用例名称

登入测试

基本描述

管理员登录测试就是用户输入的用户名和密码进行管理员登录,系统判断该用户的输入是否合法,对此功能进行测试。

测试方案

分别使用系统承认的主页管理员用户名及密码、注册的游客的用户名和密码和未注册的用户名和密码进行测试。

输入数据

1用户名111和密码1234

2用户名2和密码123456

3用户名aaa和密码321

预期结果

第一组主页管理员用户名及密码成功登录主页,并能使用后台界面

第二组注册游客用户名及密码成功登录主页,但不能使用柜员操作

第三组未注册的用户名和密码不能登入主页,提示错误信息

5.2.2 主界面测试要点

5.3 测试结果和总结

输入正确的用户名和密码

输入正确的用户名和密码

输入错误的用户名、密码

6 维护

6.1 维护方法

6.2 维护文档

6.3 功能拓展方法

posted on 2016-11-30 12:55  zhuqingshan  阅读(217)  评论(1编辑  收藏  举报

导航