Java之------单机版书店管理系统(设计思想和设计模式系列八)登录模块

书店管理系统

书店管理系统可以说是设计模式及设计思想的一个比较经典的例子。

本系列将分为多个部分讲述此输电管理系统。

书店管理系统将分为:用户、图书、进货、销售和库存五个模块,另外还有公共包、工具包和登录包,另外还有一个框架。

对于分层设计,都是表现层可以调用逻辑层,逻辑层调用数据层,数据层调用工具和公共包,方向不可打乱,必须严格按照这种模式。

本篇将做登录模块。


本篇是书店系统的最终篇,书店系统在设计思想和设计模式中可以说是比较经典的例子,虽然图形设计的不是很好,但是技术还是可圈可点的,值得学习。


注:本篇需要使用到的框架在本系列二的用户模块:

链接:点击打开链接


同系列有:

系列一(概述):点击打开链接

系列二(用户):点击打开链接

系列三(工具包和公共类):点击打开链接

系列四(图书):点击打开链接

系列五(进货):点击打开链接

系列六(销售):点击打开链接

系列七(库存):点击打开链接


本篇是登录模块,不涉及数据的处理,因此不需要数据层,它只需要对原本的框架进行一些处理,因此只要逻辑层和表现层即可。


特别提醒:本项目做得不是很完善,第一次登录的时候由于没有存数据因此登陆不进去,建议先使用用户模块新建用户在加上登陆界面来使用,不足之处还请见谅。


逻辑层:

接口:

package cn.hncu.login.business.ebi;

public interface LoginEbi {
	public String login(String name,String pwd);
}
实现类:

package cn.hncu.login.business.ebo;

import cn.hncu.login.business.ebi.LoginEbi;
import cn.hncu.user.business.factory.UserEbiFactory;
import cn.hncu.user.vo.UserModel;

public class LoginEbo implements LoginEbi {

	@Override
	public String login(String name,String pwd) {
		UserModel user=UserEbiFactory.getUserEbi().getUserByName(name);
		if (user==null){
			return "对不起,该用户不存在!";
		}
		if (!user.getPwd().equals(pwd)){
			return "对不起,您输入的密码不正确!";
		}
		return null;
	}
}
工厂类:

package cn.hncu.login.business.factory;

import cn.hncu.login.business.ebi.LoginEbi;
import cn.hncu.login.business.ebo.LoginEbo;

public class LoginEbiFactory {
	public static LoginEbi getLoginEbi(){
		return new LoginEbo();
	}
}

表现层:
登录界面:

/*
 * LoginPanel.java
 *
 * Created on __DATE__, __TIME__
 */

package cn.hncu.login.ui;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import cn.hncu.BookStore;
import cn.hncu.common.UserTypeEnum;
import cn.hncu.login.business.factory.LoginEbiFactory;
import cn.hncu.user.business.factory.UserEbiFactory;
import cn.hncu.user.vo.UserModel;

/**
 *
 * @author  __USER__
 */
public class LoginPanel extends javax.swing.JPanel {
	private BookStore app = null;

	/** Creates new form LoginPanel */
	public LoginPanel(BookStore app) {
		this.app = app;
		this.setOpaque(false);
		initComponents();
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jLabel1 = new javax.swing.JLabel();
		jLabel2 = new javax.swing.JLabel();
		jLabel3 = new javax.swing.JLabel();
		btnLogin = new javax.swing.JButton();
		tfdUserName = new javax.swing.JTextField();
		pwdFd = new javax.swing.JPasswordField();

		setLayout(null);

		jLabel1.setFont(new java.awt.Font("Microsoft YaHei UI", 0, 18));
		jLabel1.setText("\u5bc6   \u7801:");
		add(jLabel1);
		jLabel1.setBounds(250, 270, 70, 40);

		jLabel2.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 24));
		jLabel2.setForeground(new java.awt.Color(51, 255, 51));
		jLabel2.setText("\u767b\u5f55");
		add(jLabel2);
		jLabel2.setBounds(330, 70, 120, 60);

		jLabel3.setFont(new java.awt.Font("Microsoft YaHei UI", 0, 18));
		jLabel3.setText("\u7528\u6237\u540d:");
		add(jLabel3);
		jLabel3.setBounds(250, 190, 60, 30);

		btnLogin.setText("\u767b\u5f55");
		btnLogin.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btnLoginActionPerformed(evt);
			}
		});
		add(btnLogin);
		btnLogin.setBounds(310, 390, 90, 30);
		add(tfdUserName);
		tfdUserName.setBounds(330, 194, 140, 26);
		add(pwdFd);
		pwdFd.setBounds(330, 280, 220, 24);
	}// </editor-fold>
	//GEN-END:initComponents

	private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) {
		//收集参数
		String userName=tfdUserName.getText();
		String pwd=new String(pwdFd.getPassword());
		//调用逻辑层
		String result=LoginEbiFactory.getLoginEbi().login(userName, pwd);
		//返回到结果页面
		if (result!=null){
			JOptionPane.showMessageDialog(null, result);
		}
		
		//下面是登陆成功的情况,点亮相应的图标
		UserModel user=UserEbiFactory.getUserEbi().getUserByName(userName);
		if (user.getType()==UserTypeEnum.ADMIN.getType()){
			app.getjMenuItemUser().setEnabled(true);
			app.getjMenuItemBook().setEnabled(true);
			app.getjMenuItemIn().setEnabled(true);
			app.getjMenuItemOut().setEnabled(true);
			app.getjMenuItemStock().setEnabled(true);
		}
		if (user.getType()==UserTypeEnum.BOOK.getType()){
			app.getjMenuItemBook().setEnabled(true);
		}
		if (user.getType()==UserTypeEnum.OUT.getType()){
			app.getjMenuItemOut().setEnabled(true);
		}
		if (user.getType()==UserTypeEnum.IN.getType()){
			app.getjMenuItemIn().setEnabled(true);
		}
		if (user.getType()==UserTypeEnum.STOCK.getType()){
			app.getjMenuItemStock().setEnabled(true);
		}
		app.setContentPane(new WelcomePanel());
		app.validate();
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JButton btnLogin;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JPasswordField pwdFd;
	private javax.swing.JTextField tfdUserName;
	// End of variables declaration//GEN-END:variables

}
欢迎界面:

/*
 * WelcomePanel.java
 *
 * Created on __DATE__, __TIME__
 */

package cn.hncu.login.ui;

/**
 *
 * @author  __USER__
 */
public class WelcomePanel extends javax.swing.JPanel {

	/** Creates new form WelcomePanel */
	public WelcomePanel() {
		this.setOpaque(false);
		initComponents();
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jLabel1 = new javax.swing.JLabel();

		setLayout(null);

		jLabel1.setFont(new java.awt.Font("楷体", 2, 36));
		jLabel1.setForeground(new java.awt.Color(255, 255, 0));
		jLabel1.setText("Books are the ladder of human progress!");
		add(jLabel1);
		jLabel1.setBounds(40, 170, 720, 90);
	}// </editor-fold>
	//GEN-END:initComponents

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JLabel jLabel1;
	// End of variables declaration//GEN-END:variables

}

本系列完结,感谢阅读到最后。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值