目录
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项目结构
![](https://img-blog.csdnimg.cn/20210830083545874.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA56CB5LiN5YGc5omL,size_20,color_FFFFFF,t_70,g_se,x_16)
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 JTextField usernameField;
private JPasswordField passwordField;
/**
* 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, 754, 470);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel panel = new JPanel();
panel.setBackground(SystemColor.controlHighlight);
panel.setBounds(0, 0, 738, 130);
contentPane.add(panel);
panel.setLayout(null);
JLabel lblNewLabel = new JLabel("通讯录管理系统");
lblNewLabel.setFont(new Font("微软雅黑", Font.BOLD, 18));
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel.setBounds(275, 43, 212, 37);
panel.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("");
lblNewLabel_1.setIcon(new ImageIcon(Login.class.getResource("/images/\u7535\u8BDD-14.gif")));
lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_1.setBounds(218, 32, 75, 58);
panel.add(lblNewLabel_1);
JPanel panel_1 = new JPanel();
panel_1.setBackground(Color.WHITE);
panel_1.setBounds(0, 128, 738, 303);
contentPane.add(panel_1);
panel_1.setLayout(null);
JLabel lblNewLabel_2 = new JLabel("用户名:");
lblNewLabel_2.setIcon(new ImageIcon(Login.class.getResource("/images/green_pixel_05.gif")));
lblNewLabel_2.setFont(new Font("微软雅黑", Font.BOLD, 18));
lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_2.setBounds(180, 50, 109, 33);
panel_1.add(lblNewLabel_2);
usernameField = new JTextField();
usernameField.setBounds(295, 52, 216, 33);
panel_1.add(usernameField);
usernameField.setColumns(10);
JLabel lblNewLabel_2_1 = new JLabel("密 码:");
lblNewLabel_2_1.setIcon(new ImageIcon(Login.class.getResource("/images/green_pixel_139.gif")));
lblNewLabel_2_1.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_2_1.setFont(new Font("微软雅黑", Font.BOLD, 18));
lblNewLabel_2_1.setBounds(180, 119, 109, 33);
panel_1.add(lblNewLabel_2_1);
passwordField = new JPasswordField();
passwordField.setBounds(295, 121, 216, 33);
panel_1.add(passwordField);
JButton btnNewButton = new JButton("登录");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String username = usernameField.getText();
String password = passwordField.getText();
if ("".equals(username) || "".equals(password)) {
JOptionPane.showMessageDialog(null, "用户名或密码不能为空!");
} else {
UserService userService = new UserServiceImpl();
User user = userService.Login(username, password);
if (user == null) {
JOptionPane.showMessageDialog(null, "登录失败!");
} else {
JOptionPane.showMessageDialog(null, "登录成功!");
setVisible(false);
new BG(user.getId()).setVisible(true);
}
}
}
});
btnNewButton.setFont(new Font("微软雅黑", Font.BOLD, 16));
btnNewButton.setBounds(180, 199, 93, 38);
panel_1.add(btnNewButton);
JButton btnNewButton_1 = new JButton("注册");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
new Register().setVisible(true);
}
});
btnNewButton_1.setFont(new Font("微软雅黑", Font.BOLD, 16));
btnNewButton_1.setBounds(492, 199, 93, 38);
panel_1.add(btnNewButton_1);
}
}