Swing 开发之图书管理系统(五)管理员页面布局与用户信息页

  • Swing 开发之图书管理系统(五)管理员页面布局与用户信息页
    • 1.管理员页面布局
    • 2.用户信息页

Swing 开发之图书管理系统(五)管理员页面布局与用户信息页

系统:Win10
IDE:IntelliJ IDEA 2017.3.7
JDK:1.8.0_121
数据库:MySQL 5.7.17
数据库工具:Navicat Premium 11.2.7

1.管理员页面布局

管理员页面主要由两部分组成

  • 一部分是上面头部,由左边的头像、姓名、角色(管理员还是普通成员)和右边的退出按钮组成
  • 一部分是由图书借阅、图书归还、用户管理、系统管理、图书管理五部分组成


主页面的代码如下:

/*** 主界面*/
@SuppressWarnings("serial")
public class MainView extends JFrame {private User user;private JPanel mainWin;private JLabel status;private JLabel userName;private JLabel avatar;private JLabel titleBack;private JLabel button1;private JLabel button2;private JLabel button3;private JLabel button4;private JLabel button5;private JLabel exit;/*** 主界面* user 登录上来的用户*/public MainView(User user) {this.user = user;mainWin = new JPanel() {@Overrideprotected void paintComponent(Graphics g) {// TODO Auto-generated method stub// 加载背景图片String bgPath = "images/MainView/background.png";Image image = new ImageIcon(ClassLoader.getSystemResource(bgPath)/*图片的路径*/).getImage();g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), this);}};userName = new JLabel();avatar = new JLabel();titleBack = new JLabel();button1 = new JLabel("借阅管理");button2 = new JLabel("图书管理");// 用户管理button3 = new JLabel("用户管理");button4 = new JLabel("系统管理");button5 = new JLabel("图书管理");status = new JLabel();exit = new JLabel();Init();}private void Init() {// 设置标题this.setTitle("图书管理系统");// 设置窗口大小this.setSize(1102, 679);// 注册关闭事件this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 窗口居中CenterView.CenterByWindow(this);// 设置容器布局方式为空布局mainWin.setLayout(null);// 不允许用户调整窗口大小this.setResizable(false);// 设置logoUtils.setLogo(this);// 设置用户名参数userName.setBounds(70, 0, 600, 30);userName.setFont(new Font("微软雅黑", 1, 27));status.setBounds(70, 40, 100, 30);status.setFont(new Font("微软雅黑", 3, 17));// 显示用户名称userName.setText(user.getName());// 显示是否管理员if (user.getAdmin()) {status.setText("管理员");} else {status.setText("普通用户");button2.setVisible(false);}// 设置头像参数setJLabelImageAndSize(5, 5, 60, 60, avatar, user.getAvatarSrc());// 创建蚀刻式边框avatar.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));// 退出登录setJLabelImageAndSize(910, 10, 170, 57, exit, "images/MainView/exit/exit1.png");// 设置名片背景参数setJLabelImageAndSize(0, 0, 1098, 80, titleBack, "images/MainView/titleBackground.png");// 图书借阅setJLabelImageAndSize(70, 120, 275, 210, button1, "images/MainView/1/default.png");// 图书归还setJLabelImageAndSize(70, 350, 275, 210, button2, "images/MainView/2/default.png");// 用户管理setJLabelImageAndSize(415, 120, 275, 210, button3, "images/MainView/3/default.png");// 系统管理setJLabelImageAndSize(415, 350, 275, 210, button4, "images/MainView/4/default.png");// 图书管理setJLabelImageAndSize(760, 120, 275, 440, button5, "images/MainView/5/default.png");// 各个按钮添加监听avatar.addMouseListener(new MainView_avatar_MouseListener(this, user));exit.addMouseListener(new MainView_exit_MouseListener(this, exit));button1.addMouseListener(new MainView_Button1_MouseListener(this));button2.addMouseListener(new MainView_Button2_MouseListener(this));button3.addMouseListener(new MainView_Button3_MouseListener(this));button4.addMouseListener(new MainView_Button4_MouseListener(this));button5.addMouseListener(new MainView_Button5_MouseListener(this));mainWin.add(status);mainWin.add(avatar);mainWin.add(userName);mainWin.add(button1);mainWin.add(button2);mainWin.add(button3);mainWin.add(button4);mainWin.add(button5);mainWin.add(exit);mainWin.add(titleBack);this.add(mainWin);//设置窗口可见this.setVisible(true);}public void setJLabelImageAndSize(int x, int y, int width, int height, JLabel label, String imagePath) {// 实例化ImageIcon对象ImageIcon image = new ImageIcon(ClassLoader.getSystemResource(imagePath));// 得到Image对象Image img = image.getImage();// 创建缩放版本img = img.getScaledInstance(width, height, Image.SCALE_DEFAULT);// 替换为缩放版本image.setImage(img);// JLabel设置图像label.setIcon(image);// JLabel设置坐标和大小label.setBounds(x, y, width, height);}/*** 重写窗口的事件中转方法,程序是从这个方法processWindowEvent进入到窗口关闭事件的*/@Overrideprotected void processWindowEvent(WindowEvent e) {// 这里需要对进来的WindowEvent进行判断,因为,不仅会有窗口关闭的WindowEvent进来,还可能有其他的WindowEvent进来if (e.getID() == WindowEvent.WINDOW_CLOSING) {int option = JOptionPane.showConfirmDialog(null, "是否关闭系统?", "提示", JOptionPane.OK_CANCEL_OPTION);if (option == JOptionPane.OK_OPTION) {// 用户选择关闭程序,以上代码提示后确认传给父类处理super.processWindowEvent(e);} else {//用户选择不退出程序,这里把关闭事件截取return;}} else {// 如果是其他事件,交给父类处理super.processWindowEvent(e);}}// 获取头像public JLabel getAvatar() {return avatar;}// 获取Button1public JLabel getButton1() {return button1;}// 获取Button2public JLabel getButton2() {return button2;}// 获取Button3public JLabel getButton3() {return button3;}// 获取Button4public JLabel getButton4() {return button4;}// 获取Button5public JLabel getButton5() {return button5;}public String getPassword() {return this.user.getPassword();}// 获取当前登录用户public User getUser() {return this.user;}
}

2.用户信息页

点击用户头像会弹出一个个人信息的页面,上面是个人的账号和头像,下面的是姓名、性别、学院、电话等信息,然后下面有一个修改密码按钮,点击修改密码按钮会弹出一个修改密码的界面

个人信息页代码

/*** 个人信息页面*/
@SuppressWarnings("serial")
public class PersonalInfoView extends JDialog {private JPanel PersonalWin; // 本窗口private int WindowsHeight; // 父窗口高度private int windowsWidth; // 父窗口宽度private JLabel avatarLabel; // 头像框private JButton changePwdBtn; // 点击更改密码private JButton closeBtn; // 关闭private JLabel nameLabel; // 姓名private JTextField nameField; // 姓名输入框private JLabel sexLabel; // 性别private JPanel sexPanel; // 性别面板private JRadioButton radioButton1, radioButton2, radioButton3;// 性别单选private ButtonGroup buttonGroup; // 按钮组private JLabel collegeLabel; // 学院private JTextField collegeField; // 学院输入框private JLabel phoneLabel; // 电话private JTextField phoneField; // 电话输入框User user;MainView mv;public PersonalInfoView(MainView mv, User user) {super(mv, "个人信息", true);this.user = user;this.mv = mv;PersonalWin = new JPanel() {// 定义一张图片,新建一个ImageIcon对象并调用getImage方法获得一个Image对象String path = "images/PersonalInfoView/background.png";private Image image = new ImageIcon(ClassLoader.getSystemResource(path)/*图片的路径*/).getImage();// 这里系统要调用这个paintComponent方法来画这张图片,这里系统传入了一个Graphics对象(画笔),// 我们需要用这个对象来画背景图片protected void paintComponent(Graphics g) {// 调用画笔的drawImage方法,参数是要画的图片,初始坐标,结束坐标,和在哪里画// this代表是LoginWin这个“画布”对象g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), this);}};WindowsHeight = mv.getHeight();windowsWidth = mv.getWidth();// 头像部分avatarLabel = new JLabel();// 姓名部分nameLabel = new JLabel("姓名:");nameField = new JTextField(user.getName());nameField.setEnabled(false);// 性别部分sexLabel = new JLabel("性别:");sexPanel = new JPanel();sexPanel.setLayout(new GridLayout(1, 3));radioButton1 = new JRadioButton("未知");radioButton2 = new JRadioButton("男");radioButton3 = new JRadioButton("女");buttonGroup = new ButtonGroup();buttonGroup.add(radioButton1);buttonGroup.add(radioButton2);buttonGroup.add(radioButton3);if (user.getSex() == 0) {radioButton1.setSelected(true);} else if (user.getSex() == 1) {radioButton2.setSelected(true);} else if (user.getSex() == 2) {radioButton3.setSelected(true);}radioButton1.setEnabled(false);radioButton2.setEnabled(false);radioButton3.setEnabled(false);sexPanel.add(radioButton1);sexPanel.add(radioButton2);sexPanel.add(radioButton3);// 学院部分collegeLabel = new JLabel("学院:");collegeField = new JTextField(user.getCollege());collegeField.setEnabled(false);// 电话部分phoneLabel = new JLabel("电话:");phoneField = new JTextField(user.getPhone());phoneField.setEnabled(false);// 按钮部分closeBtn = new JButton("关闭");changePwdBtn = new JButton("修改密码");Init();}private void Init() {// TODO Auto-generated method stubthis.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);this.setSize(windowsWidth - 700, WindowsHeight - 200);PersonalWin.setLayout(null);PersonalWin.setFocusable(true);//不允许用户调整窗口大小this.setResizable(false);CenterView.CenterByWindow(this);// 头像avatarLabel.setBounds(108, 15, 185, 200);// 实例化ImageIcon 对象ImageIcon image = new ImageIcon(ClassLoader.getSystemResource(user.getAvatarSrc()));// 得到Image对象Image img = image.getImage();// 创建缩放版本img = img.getScaledInstance(165, 165, Image.SCALE_DEFAULT);// 替换为缩放版本image.setImage(img);// JLabel设置图像avatarLabel.setIcon(image);// 设置图像居中avatarLabel.setHorizontalAlignment(JLabel.CENTER);avatarLabel.setBorder(BorderFactory.createTitledBorder(user.getAccount()));// 姓名nameLabel.setFont(new Font("微软雅黑", 1, 17));nameLabel.setBounds(70, 235, 60, 30);nameField.setBounds(130, 235, 190, 30);// 性别sexLabel.setFont(new Font("微软雅黑", 1, 17));sexLabel.setBounds(70, 275, 60, 30);sexPanel.setBounds(130, 275, 190, 30);// 姓名collegeLabel.setFont(new Font("微软雅黑", 1, 17));collegeLabel.setBounds(70, 315, 60, 30);collegeField.setBounds(130, 315, 190, 30);// 姓名phoneLabel.setFont(new Font("微软雅黑", 1, 17));phoneLabel.setBounds(70, 355, 60, 30);phoneField.setBounds(130, 355, 190, 30);// 修改密码按钮changePwdBtn.setBounds(80, 405, 80, 30);// 关闭按钮closeBtn.setBounds(260, 405, 60, 30);PersonalInfoView_ActionListener listen = new PersonalInfoView_ActionListener(this, mv, user);changePwdBtn.addActionListener(listen);closeBtn.addActionListener(listen);// 添加头像PersonalWin.add(avatarLabel);// 添加个人信息PersonalWin.add(nameLabel);PersonalWin.add(nameField);PersonalWin.add(sexLabel);PersonalWin.add(sexPanel);PersonalWin.add(collegeLabel);PersonalWin.add(collegeField);PersonalWin.add(phoneLabel);PersonalWin.add(phoneField);// 添加按钮PersonalWin.add(changePwdBtn);PersonalWin.add(closeBtn);// 去掉按钮文字周围的焦点框changePwdBtn.setFocusPainted(false);closeBtn.setFocusPainted(false);this.add(PersonalWin);this.setVisible(true);}// 获取修改密码按钮public JButton getChangePwdBtn() {return changePwdBtn;}// 获取关闭按钮public JButton getCloseBtn() {return closeBtn;}}

弹出的修改密码界面如下,需要输入原密码和新密码,还需要确认新密码,如果两次输入新密码不一致会告警提示,如果旧密码输入错误也会告警提示

修改密码页面的代码

/*** 个人详情页面的修改密码界面* 修改自己密码时,needOldPwd为true*/
@SuppressWarnings("serial")
public class ChangePwdView extends JDialog {private JPanel changePwdViewPanel;private JLabel originalPwdLabel; // 原密码private JLabel newPwdLabel; // 新密码private JLabel confirmPwdLabel; // 确认密码private MyPasswordField originalPwd; // 原密码输入框private MyPasswordField newPwd; // 新密码输入框private MyPasswordField confirmPwd; // 确认密码输入框User user;// 保存按钮private JButton savePwdBtn; // 保存// 取消按钮private JButton closeBtn;// 是否需要输入旧密码 - 管理员重置其他用户密码不需要旧密码boolean needOldPwd;/*** @param parentView    父级窗口* @param user          原密码用户* @param needOldPwd    是否需要旧密码*/public ChangePwdView(JDialog parentView, User user, boolean needOldPwd) {super(parentView, true);// 实例化一个面板组件changePwdViewPanel = new JPanel();this.user = user;this.needOldPwd = needOldPwd;originalPwdLabel = new JLabel("原密码:");newPwdLabel = new JLabel("新密码:");confirmPwdLabel = new JLabel("确认密码:");savePwdBtn = new JButton("保存");closeBtn = new JButton("取消");originalPwd = new MyPasswordField();originalPwd.setPlaceholder("       请输入原密码");newPwd = new MyPasswordField();newPwd.setPlaceholder("       请输入新密码");confirmPwd = new MyPasswordField();confirmPwd.setPlaceholder("       请确认新密码");// 需要输入旧密码if (needOldPwd) {// 旧密码标签与输入框originalPwdLabel.setFont(new Font("微软雅黑", 0, 17));originalPwdLabel.setBounds(60, 38, 100, 20);originalPwd.setBounds(150, 35, 180, 30);// 如果如要输入旧密码,则将该标签和输入框添加进来,否则不添加changePwdViewPanel.add(originalPwdLabel);changePwdViewPanel.add(originalPwd);// 新密码标签与输入框newPwdLabel.setFont(new Font("微软雅黑", 0, 17));newPwdLabel.setBounds(60, 88, 100, 20);newPwd.setBounds(150, 85, 180, 30);// 确认新密码标签与输入框confirmPwdLabel.setFont(new Font("微软雅黑", 0, 17));confirmPwdLabel.setBounds(60, 138, 100, 20);confirmPwd.setBounds(150, 135, 180, 30);// 保存和取消按钮savePwdBtn.setBounds(60, 200, 80, 30);closeBtn.setBounds(250, 200, 80, 30);// 设置大小this.setSize(400, 300);} else { // 不需要输入旧密码// 新密码标签与输入框newPwdLabel.setFont(new Font("微软雅黑", 0, 17));newPwdLabel.setBounds(60, 38, 100, 20);newPwd.setBounds(150, 35, 180, 30);// 确认新密码标签与输入框confirmPwdLabel.setFont(new Font("微软雅黑", 0, 17));confirmPwdLabel.setBounds(60, 88, 100, 20);confirmPwd.setBounds(150, 85, 180, 30);// 保存和取消按钮savePwdBtn.setBounds(60, 150, 80, 30);closeBtn.setBounds(250, 150, 80, 30);// 设置大小this.setSize(400, 250);}changePwdViewPanel.setLayout(null);changePwdViewPanel.setFocusable(true);// 添加监听ChangePwdView_Listener listen = new ChangePwdView_Listener(this, user);savePwdBtn.addActionListener(listen);closeBtn.addActionListener(listen);// 添加其他组件changePwdViewPanel.add(newPwdLabel);changePwdViewPanel.add(newPwd);changePwdViewPanel.add(confirmPwdLabel);changePwdViewPanel.add(confirmPwd);changePwdViewPanel.add(savePwdBtn);changePwdViewPanel.add(closeBtn);// 去掉按钮文字周围的焦点框savePwdBtn.setFocusPainted(false);closeBtn.setFocusPainted(false);this.add(changePwdViewPanel);// 设置标题this.setTitle("修改密码  ");// 设置默认关闭操作this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);// 设置居中显示CenterView.CenterByWindow(this);// 设置可见this.setVisible(true);}// 获取旧密码的输入框public MyPasswordField getOriginalPwd() {return originalPwd;}// 获取新密码的输入框public MyPasswordField getNewPwd() {return newPwd;}// 获取确认新密码的输入框public MyPasswordField getConfirmPwd() {return confirmPwd;}// 获取是否需要输入旧密码public boolean getNeedOldPwd() {return needOldPwd;}// 在按钮监听中获取保存按钮public JButton getSavePwdBtn() {return savePwdBtn;}// 在按钮监听中获取取消按钮public JButton getCloseBtn() {return closeBtn;}}

【Swing 开发之图书管理系统】(五)管理员页面布局与用户信息页相关推荐

  1. 图书管理系统之管理员普通用户信息管理(五)

    图书管理系统之管理员普通用户信息管理(五) 相关源码下载连接:https://download.csdn.net/download/baidu_39378193/85033291 思路: 作为超级管理 ...

  2. 图书管理系统之普通用户、超级管理员页面布局(四)

    图书管理系统之普通用户.超级管理员页面布局(四) 相关源码下载连接:https://download.csdn.net/download/baidu_39378193/85033291 前言: 在上一 ...

  3. 图书管理系统jsp代码_【程序源代码】使用Java开发的图书管理系统

    关键字:java 管理系统  正文 | 内容 01 - [概述] 使用Java开发的图书管理系统,读者可以注册登录,登录时会判断账号类型再分别跳到各自对应的页面,读者可以查找,借阅,还书,查看历史借阅 ...

  4. Java Swing Mysql实现图书管理系统源码附带高清视频指导运行教程

    Java swing实现的图书管理系统 实现的功能有管理员登录管理图书类别.信息.用户管理.新订书籍等等. 基础开发环境 开发工具:Eclipse(MyEclipse.idea.sts) 我这里用的是 ...

  5. 基于SSM框架开发的图书管理系统

    基于SSM框架开发的图书管理系统 项目需求 数据库设计 图书管理数据库代码 建立一个普通的JavaWeb项目 首先创建动态web项目 导入spring+MyBatis+SpringMVC的jar包文件 ...

  6. C#Windows窗体开发的图书管理系统

    C#Windows窗体开发的图书管理系统,有文档,供学习参考使用,主要功能:涵盖数据库增删查改,登录注册,上传图片 注意:系统采用VS运行,系统经过测试运行代码无任何问题. 现有:6910649369 ...

  7. 小区物业管理系统-物业管理员页面

    小区物业管理系统-物业管理员页面 主页面 添加业主 Public Class PropertyManager_Pro_insert'bug:插入:若删除一个,用count就会插入相同的,导致插入错误D ...

  8. 七天学会ASP.NET MVC (五)——Layout页面使用和用户角色管理

    系列文章 七天学会ASP.NET MVC (一)--深入理解ASP.NET MVC 七天学会ASP.NET MVC (二)--ASP.NET MVC 数据传递 七天学会ASP.NET MVC (三)- ...

  9. WPF 项目开发入门(二) WPF 页面布局

    WPF 项目开发入门(一) 安装运行 WPF 项目开发入门(二) WPF 页面布局 WPF 项目开发入门(三)WPF 窗体与页面 WPF 项目开发入门(四) MVVM 模式 与 TreeView树组件 ...

最新文章

  1. 跳过51单片机,直接学STM32有什么严重后果?
  2. js删除与php后台交互,js动态添加删除,后台取数据(示例代码)_javascript技巧
  3. centos FTP服务器的架设和配置
  4. 老李推荐: 第8章4节《MonkeyRunner源码剖析》MonkeyRunner启动运行过程-启动AndroidDebugBridge 2...
  5. CCR源码分析-CCR架构
  6. 事务的隔离级别 数据库
  7. C/C++ 基础算法2
  8. [好惆怅啊]TCL编码转换的问题
  9. linux修改对外访问ip_linux 同一个ip 绑定两个不同的域名 访问两个不同的项目
  10. 《电子元器件的可靠性》——3.1节可靠性试验的意义
  11. php阴历阳历换算(1950开始)
  12. Android 调用 系统选择器 选择 图片 或 文件(ACTION_PICK、ACTION_GET_CONTENT)
  13. python+gdal+numpy计算ndvi
  14. Windows监控——性能指标详解
  15. PHP 调用百度翻译api翻译数据
  16. Python爬取豆瓣电影短评
  17. 【darknet源码解析-24】shortcut_layer.h 和 shortcut_layer.c 解析
  18. Ancient Messages HDU - 3839
  19. PreCreateWindow作用
  20. 毕业设计 基于Web停车场管理系统的设计与实现

热门文章

  1. 团队目标WBS及具体任务分工
  2. 2016年福建两化深度融合与新型CIO创新发展论坛 信息化催生福建“五新”
  3. python判断闰年_Python 判断闰年
  4. JS.代码格式化(整理、美化)
  5. 高斯分布与Gamma分布关系
  6. MATLAB求Gamma分布的置信区间
  7. 给你30s,如何跟面试官讲清楚跳表
  8. 为什么超三成制造企业上市公司选择用友U9 cloud?
  9. 洛谷P2699 【数学1】小浩的幂次运算
  10. Java开发实战项目分享之学成在线v1.0项目总结