java开发学习笔记之图书管理系统

图书管理系统
开发工具:eclipse 、MySQL
我的邮箱[email protected] java开发学习笔记之图书管理系统_第1张图片
java开发学习笔记之图书管理系统_第2张图片
java开发学习笔记之图书管理系统_第3张图片
java开发学习笔记之图书管理系统_第4张图片
java开发学习笔记之图书管理系统_第5张图片
java开发学习笔记之图书管理系统_第6张图片
java开发学习笔记之图书管理系统_第7张图片
数据库
java开发学习笔记之图书管理系统_第8张图片
java开发学习笔记之图书管理系统_第9张图片
java开发学习笔记之图书管理系统_第10张图片

源码:
登录代码

package 登录界面;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import 登录界面.LoginCheck;

class ActionHandle{
	private JFrame frame=new JFrame("欢迎登录图书馆管理系统");
	private JButton submit=new JButton("登陆");
	private JButton reset=new JButton("重置");
	private JLabel nameLab=new JLabel("用户名");
	private JLabel passLab=new JLabel("密码");
	private JLabel infoLab=new JLabel("用户登录系统");
	private JTextField nameText=new JTextField();
	private JPasswordField passText=new JPasswordField();
	public ActionHandle() {
		Font fnt=new Font("serief",Font.BOLD,12);
		infoLab.setFont(fnt);
		submit.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				if(arg0.getSource()==submit) {
					String tname=nameText.getText();
					String tpass=new String(passText.getPassword());
					LoginCheck log=new LoginCheck(tname,tpass);
					if(log.validate()) {
						infoLab.setText("登录成功,欢迎光临!!!");
					}else {
						infoLab.setText("登录失败,错误的用户名或密码!!!");
					}
				}
				if(arg0.getSource()==reset) {
					nameText.setText("");
					passText.setText("");
					infoLab.setText("用户登录系统!!!");
				}
			}
	});
		frame.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent arg0) {
				System.exit(1);
			}
		});
		frame.setLayout(null);
		nameLab.setBounds(5, 10, 60, 20);
		passLab.setBounds(5,50,60,20);
		infoLab.setBounds(5,65,220,30);
		nameText.setBounds(65,10,100,20);
		passText.setBounds(65,50,100,20);
		submit.setBounds(165,10,60,20);
		reset.setBounds(165,50,60,20);
		frame.add(nameLab,BorderLayout.EAST);
		frame.add(passLab,BorderLayout.EAST);
		frame.add(nameText,BorderLayout.CENTER);
		frame.add(passText,BorderLayout.CENTER);
		frame.add(submit,BorderLayout.WEST);
		frame.add(reset,BorderLayout.WEST);
		frame.setSize(400,200);
		frame.setLocation(500,300);
		frame.setVisible(true);
	}
}

public class Body {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new ActionHandle();

	}

}
package 登录界面;

public class LoginCheck {
	private String name;
	private String password;
	public LoginCheck(String name,String password) {
		this.name=name;
		this.password=password;
	}
	public boolean validate() {
		if("LiXingHua".equals(name)&&"mldn".equals(password)) {
			return true;
		}else {
			return false;
		}
	}
}

数据库交互

package 数据库交互;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class Insert {
	public static final String URL="jdbc:mysql://localhost:3306/mysql?";//数据库连接字符串,这里的deom为数据库名
    public static final String NAME="root";//登录名
    public static final String PASSWORD="cww123456";//密码
    public static final String DBDRIVER="org.git.mm.mysql.Driver";

	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		Connection conn=null;
		Statement stmt=null;
		String name="陈伟伟";
		String password="123456";
		int age=21;
		String sex="男";
		String birthday="1998-10-04";
		String sql="INSERT INTO user(name,password,age,sex,birthday)"+"VALUES('"+name+"','"+password+"',"+age+",'"
		+sex+"','"+birthday+"')";
		Class.forName("com.mysql.jdbc.Driver");
		conn=DriverManager.getConnection(URL,NAME,PASSWORD);
		stmt=conn.createStatement();
		stmt.executeUpdate(sql);
		stmt.close();
		conn.close();

	}

}

文件工具类
```bash

package tool;


import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

	public class FileOperate{
		private File file=null;
		public FileOperate(String pathName) {
			this.file=new File(pathName);
		}
		public boolean save(Object obj)throws Exception{
			ObjectOutputStream oos=null;
			boolean flag=false;
			try {
				oos=new ObjectOutputStream(new FileOutputStream(this.file));
				oos.writeObject(obj);
				flag=true;
			}catch(Exception e) {
				throw e;
				}finally {
				if(oos!=null) {
					oos.close();
				}
			}
			return flag;
		}
		public Object load()throws Exception{
			Object obj=null;
			ObjectInputStream ois=null;
			try {
				ois =new ObjectInputStream(new FileInputStream(this.file));
				obj=ois.readObject();
			}catch(Exception e) {
				throw e;
			}finally {
				if(ois!=null) {
					ois.close();
				}
			}
			return obj;
		}
	}


io流

package tool;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class InputData {
	private BufferedReader buf=null;
	public InputData() {
		this.buf=new BufferedReader(new InputStreamReader(System.in));
	}
	public String getString(String info) {
		String temp=null;
		System.out.println(info);
		try {
			temp=this.buf.readLine();
		}catch(IOException e) {
			e.printStackTrace();
		}
		return temp;
	}
	public int getInt(String info,String err) {
		int temp=0;
		String str=null;
		boolean flag=true;
		while(flag) {
			str=this.getString(info);
			if(str.matches("^\\d+$")) {
				temp=Integer.parseInt(str);
				flag=false;
			}else {
				System.out.println(err);
			}
		}
		return temp;
	}
}


 
 

 
 

界面
 

```bash
package model;
import tool.FileOperate;
import 信息类.User;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

 class Login1 extends JFrame implements ActionListener{
	//定义按钮
	JButton btnLogin,btnRegister,btnCancel;
	//创建中间容器
	JPanel pnlSouth,pnlNorth,pnlCenter,pnlCenter1,pnlCenter2;
	//标签
	JLabel lab1,labNum,JLabelPwd;
	//用户名文本框
	JTextField tfNum;
	//密码文本框
	JPasswordField pfPwd;
	Login1(String title){
		super (title);
		//north
		pnlNorth=new JPanel();
		lab1=new JLabel();
		pnlNorth.add(lab1);
		this.add(pnlNorth,BorderLayout.NORTH);
		//center
		pnlCenter=new JPanel();
		pnlCenter1=new JPanel();
		pnlCenter2=new JPanel();
		pnlCenter.setLayout(new BorderLayout());
		labNum=new JLabel("学号:");
		tfNum=new JTextField(20);
		pnlCenter1.add(labNum);
		pnlCenter1.add(tfNum);
		pnlCenter.add(pnlCenter1,BorderLayout.NORTH);
		JLabelPwd=new JLabel("密码:");
		pfPwd=new JPasswordField(20);
		pnlCenter2.add(JLabelPwd);
		pnlCenter.add(pnlCenter2,BorderLayout.SOUTH);
		this.add(pnlCenter, BorderLayout.CENTER);
		//south
		pnlSouth=new JPanel();
		btnLogin=new JButton("登录");
		btnLogin.addActionListener(this);
		btnRegister=new JButton("注册");
		btnRegister.addActionListener(this);
		btnCancel=new JButton("取消");
		btnCancel.addActionListener(this);
		pnlSouth.add(btnLogin);
		pnlSouth.add(btnRegister);
		pnlSouth.add(btnCancel);
		this.add(pnlSouth, BorderLayout.SOUTH);
		
		this.setSize(400, 200);
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	//消息处理
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==btnLogin) {
			String num=tfNum.getText();
			String pwd=pfPwd.getText();
			//FileOperate
			if(User.getNum()==null) {
				JOptionPane.showMessageDialog(this,"你的输入账号不存在,请重新输入!");
				return;
			}
			if(!User.getPwd().equals(pwd)) {
				JOptionPane.showMessageDialog(this, "你输入的密码错误,请重新输入!");
				return;
			}
			JOptionPane.showMessageDialog(this,"恭喜你,登录成功!");
			this.dispose();
		//设置管理员权限
		if(User.getNum().equals("17046211")&&User.getPwd().equals("Nchu042716")) {
			//new AdminFunction();
			return;
		}else if(User.getNum().equals("170462")&&User.getPwd().equals("123456")) {
			//new AdminFunction();
			return;
		}new UserFunction();
	}
		else if(e.getSource()==btnRegister){
		dispose();
		//new Register("用户注册");
		}
	else {
		JOptionPane.showMessageDialog(this,"谢谢使用,欢迎下次登录!");
		System.exit(0);
	}
	}
	}
 public class Login{
public static void main(String[] args) {
	new Login1(null);
	}
 }
/*
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		JFrame frame=new JFrame("图书馆管理系统");
		//String picPath="d:"+File.separator+"sky.jpg";
		//Icon icon=new ImageIcon(picPath);
		//JLabel lab=null;
		//lab=new JLabel(icon,JLabel.CENTER);
		JTextField name=new JTextField(30);
		JTextField num=new JTextField(20);
		JTextField borrowTime=new JTextField(10);
		JTextField book=new JTextField(30);
		JLabel nameLab=new JLabel("姓名:");
		JLabel numLab=new JLabel("学号:");
		JLabel borrowTimeLab=new JLabel("借阅时间:");
		JLabel bookLab=new JLabel("借阅书名:");
		Font fnt=new Font("serief",Font.BOLD,20);
		nameLab.setFont(fnt);
		numLab.setFont(fnt);
		borrowTimeLab.setFont(fnt);
		bookLab.setFont(fnt);
		nameLab.setBounds(110, 10, 100, 20);
		numLab.setBounds(110, 60, 100, 20);
		borrowTimeLab.setBounds(110, 110, 100, 20);
		bookLab.setBounds(110, 160, 100, 20);
		name.setBounds(310, 10, 80, 20);
		num.setBounds(310, 60, 80, 20);
		borrowTime.setBounds(310, 110, 80, 20);
		book.setBounds(310, 160, 80, 20);
		frame.setLayout(null);
		frame.add(nameLab);
		frame.add(name);
		frame.add(numLab);
		frame.add(num);
		frame.add(borrowTimeLab);
		frame.add(borrowTime);
		frame.add(bookLab);
		frame.add(book);
		frame.setSize(800, 400);
		frame.setLocation(500,400);
		frame.setVisible(true);
	}

package model;


import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Show {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		JFrame frame=new JFrame("图书馆管理系统");
		JPanel pan=new JPanel();
		pan.add(new JLabel("添加学生借阅信息"));
		pan.add(new JLabel("删除学生借阅信息"));
		pan.add(new JLabel("修改学生借阅信息"));
		pan.add(new JLabel("查询学生借阅信息"));
		pan.add(new JLabel("退出图书管理系统"));
		frame.setLayout(new BorderLayout(5,2));
		pan.add(new JButton("添加"),BorderLayout.EAST);
		pan.add(new JButton("删除"),BorderLayout.WEST);
		pan.add(new JButton("修改"),BorderLayout.SOUTH);
		pan.add(new JButton("查询"),BorderLayout.NORTH);
		pan.add(new JButton("退出"),BorderLayout.CENTER);
		frame.add(pan);
		frame.pack();
		frame.setLocation(500, 400);
		frame.setVisible(true);
	}

}


你可能感兴趣的:(java开发学习笔记之图书管理系统)