目录
1.系统运行环境
运行环境:Java8 + MySQL8
开发工具:eclipse/idea
2.系统功能介绍
(下面介绍的功能肯定都有,没有介绍的功能肯定没有!)
系统采用模拟MVC三层进行开发,这样方便项目进行修改或者二次开发!
数据库:三张表
功能:两种角色管理员和用户
普通用户登录:账单基本数据进行增删改查
查询供应商报表
管理员登录:可以管理账单、供应商、用户基本信息:
账单模块增删改查
供应商管理增删改查
用户信息维护
3.项目结构略讲
3.1乱码问题
系统开发时的编码为UTF-8,因此导入eclipse时,也需要eclipse工作空间的编码为UTF-8
修改编码:点击Window->Preference->General->workplace,然后选择默认编码方式 UTF-8。
错误做法:开始将系统导入,出现乱码的问题,然后去修改eclipse的编码,这样有的 时候并不能修乱码的问题!需要将项目删除掉,然后修改eclipse的工作空 间编码,再次导入系统才能修改掉乱码!
3.2 如何将UTF-8编码系统修改为GBK编码的系统?
需要靠我们勤劳的双手,嘿嘿嘿......
将系统文件复制一份,然后将eclipse的工作空间编码修改为GBK,导入系统;eclipse里面文件与原来文件进行一一比对,修改
Ctrl +c 和ctrl + v
除此之外,我目前还不知道如何一步修改,嘿嘿嘿......
3.3 项目结构
com.system.bean包:实体包,在有些情况下也写成entity或者pojo,相当于model持 久层
com.system.dao包:操作数据库的JDBC包,相当于model持久层
com.system.util包:工具包
com.system.view包:swing类包,相当于view视图层
com.system.service包:业务处理包,相当于model持久层
com.system.test包:测试包,和项目无关
mvc设计模式中:m是指业务模型,v是指用户界面,c则是控制器
你想问:这不是没有控制器层?
我:阿巴阿巴......确实没有
3.4 项目修改
在com.system.util包下面的DB类中,里面包含的一些数据库连接的基本信息,PASS变量需要修改成自己的数据库密码
3.5 项目运行
在com.system.view包下面的Login类,main函数就在这个类里面,然后点击右键就可以运行
3.6代码片段
public class Login extends JFrame {
private JPanel contentPane;
private JPanel panel;
private JLabel lblNewLabel;
private JLabel lblNewLabel_2;
private JPanel panel_1;
private JLabel lblNewLabel_3;
private JLabel lblNewLabel_4;
private JLabel lblNewLabel_5;
private JLabel lblNewLabel_6;
private JTextField usernamesField;
private JPasswordField passwordField;
private JButton btnNewButton_1;
private JComboBox comboBox;
/**
* Launch the application.
* 创作:码不停手
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Login frame = new Login();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Login() {
setTitle("超市管理系统");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 744, 537);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
panel = new JPanel();
panel.setBackground(Color.BLACK);
panel.setBounds(0, 0, 394, 498);
contentPane.add(panel);
panel.setLayout(null);
JLabel lblNewLabel_1 = new JLabel("New label");
lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_1.setIcon(new ImageIcon(Login.class.getResource("/images/login.jpg")));
lblNewLabel_1.setBounds(0, 0, 392, 405);
panel.add(lblNewLabel_1);
lblNewLabel_2 = new JLabel("超市账单管理系统");
lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_2.setFont(new Font("微软雅黑", Font.BOLD, 18));
lblNewLabel_2.setForeground(Color.WHITE);
lblNewLabel_2.setBounds(92, 427, 184, 43);
panel.add(lblNewLabel_2);
panel_1 = new JPanel();
panel_1.setBackground(Color.WHITE);
panel_1.setBounds(393, 0, 335, 498);
contentPane.add(panel_1);
panel_1.setLayout(null);
lblNewLabel_3 = new JLabel("用户登录");
lblNewLabel_3.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_3.setForeground(Color.BLACK);
lblNewLabel_3.setFont(new Font("微软雅黑", Font.BOLD, 18));
lblNewLabel_3.setBounds(63, 50, 184, 43);
panel_1.add(lblNewLabel_3);
lblNewLabel_4 = new JLabel("姓名:");
lblNewLabel_4.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_4.setFont(new Font("微软雅黑", Font.BOLD, 14));
lblNewLabel_4.setBounds(41, 122, 63, 22);
panel_1.add(lblNewLabel_4);
lblNewLabel_5 = new JLabel("密码:");
lblNewLabel_5.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_5.setFont(new Font("微软雅黑", Font.BOLD, 14));
lblNewLabel_5.setBounds(41, 188, 63, 22);
panel_1.add(lblNewLabel_5);
lblNewLabel_6 = new JLabel("身份:");
lblNewLabel_6.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_6.setFont(new Font("微软雅黑", Font.BOLD, 14));
lblNewLabel_6.setBounds(41, 248, 63, 22);
panel_1.add(lblNewLabel_6);
usernamesField = new JTextField();
usernamesField.setBounds(103, 118, 184, 33);
panel_1.add(usernamesField);
usernamesField.setColumns(10);
passwordField = new JPasswordField();
passwordField.setBounds(103, 184, 184, 33);
panel_1.add(passwordField);
String[] a = new String[] { "普通员工", "管理员" };
comboBox = new JComboBox(a);
comboBox.setBounds(103, 244, 184, 33);
panel_1.add(comboBox);
JButton btnNewButton = new JButton("登录");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String username = usernamesField.getText();
String password = passwordField.getText();
String type = (String) comboBox.getSelectedItem();
if (username.equals("") || password.equals("")) {
JOptionPane.showMessageDialog(null, "用户名或密码不能为空!");
} else {
User user = check(username, password, type);
if (user != null) {
JOptionPane.showMessageDialog(null, "登录成功!");
setVisible(false);
new Bg(type).setVisible(true);
} else {
JOptionPane.showMessageDialog(null, "登录失败,请检查用户名、密码或权限");
}
}
}
});
btnNewButton.setFont(new Font("微软雅黑", Font.BOLD, 14));
btnNewButton.setBounds(41, 334, 78, 33);
panel_1.add(btnNewButton);
btnNewButton_1 = new JButton("重置");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
usernamesField.setText("");
passwordField.setText("");
}
});
btnNewButton_1.setFont(new Font("微软雅黑", Font.BOLD, 14));
btnNewButton_1.setBounds(233, 334, 78, 33);
panel_1.add(btnNewButton_1);
}
private User check(String username, String password, String type) {
UserDao userDao = new UserDaoImpl();
User user = userDao.login(username, password, type);
return user;
}
}