一、系统介绍
1.开发环境
操作系统:Win10
开发工具 :Eclipse2021
JDK版本:jdk1.8
存储方式:Txt文件存储
2.技术选型
Java+Swing+Txt
3.功能模块
4.工程结构
5.系统功能
1.系统登录
管理员可以登录系统
2.查看图书
管理员可以查看图书信息。
3.新增图书
管理员可以新增图书信息。
4.修改图书
管理员可以修改图书信息。
5.删除图书
管理员可以删除图书信息。
二、系统展示
1.登录页面
2.主页面
3.查看图书
4.新增图书
5.修改图书
6.删除图书
三、部分代码
LoginActivity
package com.sjsq.view;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
/**
*
* 登录
*
*/
public class LoginActivity extends JFrame implements ActionListener {
static LoginActivity w1;
JLabel jL1, jL2, jLname;
JButton jB1, jB2;
JTextField jF1;
JPasswordField jP1;
public LoginActivity() {
super("图书信息管理系统_登录界面");
jLname = new JLabel("");
jLname.setFont(new Font("宋体", Font.BOLD, 20));
jLname.setBounds(5, 5, 200, 30);
jL1 = new JLabel("用户名称:");
jL1.setFont(new Font("宋体", Font.BOLD, 20));
jL1.setBounds(60, 40, 200, 30);
jL2 = new JLabel("登录密码:");
jL2.setFont(new Font("宋体", Font.BOLD, 20));
jL2.setBounds(60, 120, 200, 30);
jF1 = new JTextField("", 20);
jF1.setBounds(250, 40, 200, 30);
jP1 = new JPasswordField("", 20);
jP1.setBounds(250, 120, 200, 30);
jB1 = new JButton("登录");
jB1.setBounds(150, 260, 60, 30);
jB1.addActionListener(this);
jB2 = new JButton("退出");
jB2.setBounds(340, 260, 60, 30);
jB2.addActionListener(this);
Container winContainer = this.getContentPane();
winContainer.setLayout(null);
winContainer.add(jLname);
winContainer.add(jL1);
winContainer.add(jL2);
winContainer.add(jF1);
winContainer.add(jP1);
winContainer.add(jB1);
winContainer.add(jB2);
this.setSize(600, 400);
this.setVisible(true);
this.setLocationRelativeTo(null);
}
public static void main(String[] args) {
LoginActivity w1 = new LoginActivity();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getSource() == jB1) {
if (jF1.getText().toString() != null && jF1.getText().toString().length() > 0) {
if(new String(jP1.getPassword()).equals(""))
{
JOptionPane.showMessageDialog(w1, "登录密码不为空", "提示", 2);
}
else {
// 账号和密码
if (jF1.getText().equals("admin") && new String(jP1.getPassword()).equals("admin")) // ※
{
JOptionPane.showMessageDialog(w1, "登录成功", "提示", 1);
jL1.setText("");
jL2.setText("");
jF1.setText("");
this.setVisible(false);
IndexActivity w2 = new IndexActivity();
} else {
JOptionPane.showMessageDialog(w1, "登录失败", "提示", 2);
}
}
} else {
JOptionPane.showMessageDialog(w1, "用户名称不为空", "提示", 2);
}
} else if (e.getSource() == jB2)
System.exit(0);
}
}
IndexActivity
package com.sjsq.view;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
/**
*
* 主页面
*
*/
public class IndexActivity extends JFrame implements ActionListener {
JLabel jL1, jL2, jLname, jL3;
JButton jB1, jB2, jB3, jB4, jB5, jB6, SignOut;
JTextField jF1;
JPasswordField jP1;
ImageIcon background;
JPanel myPanel;
public IndexActivity() {
super("图书信息管理系统_操作主界面");
jLname = new JLabel("用户名称:admin");
jLname.setFont(new Font("宋体", Font.BOLD, 16));
jLname.setBounds(950, 5, 200, 30);
jL1 = new JLabel("操作:");
jL1.setFont(new Font("宋体", Font.BOLD, 20));
jL1.setBounds(20, 40, 200, 30);
jB3 = new JButton("查询图书信息");
jB3.setBounds(100, 75, 150, 30);
jB3.addActionListener(this);
jB4 = new JButton("添加图书信息");
jB4.setBounds(100, 125, 150, 30);
jB4.addActionListener(this);
jB5 = new JButton("更新图书信息");
jB5.setBounds(100, 175, 150, 30);
jB5.addActionListener(this);
jB6 = new JButton("删除图书信息");
jB6.setBounds(100, 225, 150, 30);
jB6.addActionListener(this);
SignOut = new JButton("退出登录");
SignOut.setBounds(460, 155, 110, 30);
SignOut.addActionListener(this);
background = new ImageIcon("e:\\\\图片/图标/cloud.png"); // 创建一个背景图片
jL3 = new JLabel(background); // 把背景图片添加到标签里
jL3.setBounds(950, 35, background.getIconWidth(), background.getIconHeight()); // 把标签设置为和图片等高等宽
myPanel = (JPanel) this.getContentPane(); // 把我的面板设置为内容面板
myPanel.setOpaque(false); // 把我的面板设置为不可视
myPanel.setLayout(new FlowLayout()); // 把我的面板设置为流动布局
this.getLayeredPane().setLayout(null); // 把分层面板的布局置空
this.getLayeredPane().add(jL3, new Integer(Integer.MIN_VALUE));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container winContainer = this.getContentPane();
winContainer.setLayout(null);
winContainer.add(jLname);
winContainer.add(jB3);
winContainer.add(jB4);
winContainer.add(jB5);
winContainer.add(jB6);
winContainer.add(SignOut);
this.setSize(600, 400);
this.setVisible(true);
this.setLocationRelativeTo(null);
}
public static void main(String[] args) {
IndexActivity w2 = new IndexActivity();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getSource() == jB3) {
this.setVisible(false);
// 查询信息
SearchInfoActivity w6 = new SearchInfoActivity();
}
if (e.getSource() == jB4) {
this.setVisible(false);
// 添加信息
AddInfoActivity w5 = new AddInfoActivity();
}
if (e.getSource() == jB5) {
this.setVisible(false);
// 更新信息
UpdateInfoActivity w5 = new UpdateInfoActivity();
}
if (e.getSource() == jB6) {
this.setVisible(false);
// 删除信息
DeleteInfoActivity w5 = new DeleteInfoActivity();
}
if (e.getSource() == SignOut) {
this.setVisible(false);
// 登录界面
LoginActivity w1 = new LoginActivity();
}
}
}
SearchInfoActivity
package com.sjsq.view;
import com.sjsq.util.*;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
/**
*
* 查询图书
*
*/
public class SearchInfoActivity extends JFrame implements ActionListener {
static IndexActivity w2;
JLabel jL1, jL2, jLname;
JButton jB1, jB2;
JTextField jF1, jF;
JScrollPane scrollPane;
JTextArea textArea;
public SearchInfoActivity() {
super("图书信息管理系统_查询图书信息");
jLname = new JLabel("用户名称:admin");
jLname.setFont(new Font("宋体", Font.BOLD, 16));
jLname.setBounds(950, 5, 200, 30);
jL1 = new JLabel("编号:");
jL1.setFont(new Font("宋体", Font.BOLD, 20));
jL1.setBounds(20, 60, 200, 30);
jF1 = new JTextField("", 20);
jF1.setBounds(110, 60, 280, 30);
jF1.setFont(new Font("宋体", Font.BOLD, 15));
jF1.addFocusListener(new JTextFieldHintListener(jF1, "请输入书籍编号"));
jF = new JTextField("", 20);
jB1 = new JButton("查询");
jB1.setBounds(60, 170, 60, 30);
jB1.addActionListener(this);
jB2 = new JButton("返回");
jB2.setBounds(250, 170, 60, 30);
jB2.addActionListener(this);
// 创建文本区域组件
textArea = new JTextArea();
textArea.setLineWrap(true); // 自动换行
textArea.setFont(new Font("sssssssss", Font.PLAIN, 18)); // 设置字体
// 创建滚动面板, 指定滚动显示的视图组件(textArea), 垂直滚动条一直显示, 水平滚动条从不显示
scrollPane = new JScrollPane(textArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setBounds(400, 50, 660, 160);
Container winContainer = this.getContentPane();
winContainer.setLayout(null);
winContainer.add(jLname);
winContainer.add(jL1);
winContainer.add(jF1);
winContainer.add(jF);
winContainer.add(jB1);
winContainer.add(jB2);
winContainer.add(scrollPane);
this.setSize(1100, 400);
this.setVisible(true);
this.setLocationRelativeTo(null);
jF.requestFocus();
try {
SQLTxt.searchAllTxtFile();
textArea.setText(SQLTxt.getreadStr());
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
SearchInfoActivity w6 = new SearchInfoActivity();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getSource() == jB1) {
if (jF1.getText().toString() != null && jF1.getText().toString().length() > 0) {
if (jF1.getText().toString().equals("search.all")) {
try {
SQLTxt.searchAllTxtFile();
textArea.setText(SQLTxt.getreadStr());
JOptionPane.showMessageDialog(w2, "查询成功", "提示", 1);
// System.out.println(SQLTxt.getreadStr());
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(w2, "查询失败", "提示", 1);
e1.printStackTrace();
}
} else {
try {
SQLTxt.searchTxtFile(jF1.getText().toString());
textArea.setText(SQLTxt.getreadStr());
JOptionPane.showMessageDialog(w2, "查询成功", "提示", 1);
// System.out.println(SQLTxt.getreadStr());
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(w2, "查询失败", "提示", 1);
e1.printStackTrace();
}
}
} else {
JOptionPane.showMessageDialog(w2, "输入不为空", "提示", 1);
}
} else if (e.getSource() == jB2) {
this.setVisible(false);
w2 = new IndexActivity();
}
}
}
Book
package com.sjsq.vo;
import java.io.Serializable;
/**
*
* 图书类
*
*/
public class Book implements Serializable {
String name;
String introduce;
public Book(String name, String introduce) {
super();
this.name = name;
this.introduce = introduce;
}
public String toString() {
return "Book (书名=[" + name + "], 简介=[" + introduce + "])";
}
}
JTextFieldHintListener
package com.sjsq.util;
import java.awt.Color;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import javax.swing.JTextField;
/**
*
* 输入监听
*
*/
public class JTextFieldHintListener implements FocusListener {
private String hintText;
private JTextField textField;
public JTextFieldHintListener(JTextField jTextField,String hintText) {
this.textField = jTextField;
this.hintText = hintText;
jTextField.setText(hintText); //默认直接显示
jTextField.setForeground(Color.GRAY);
}
@Override
public void focusGained(FocusEvent e) {
//获取焦点时,清空提示内容
String temp = textField.getText();
if(temp.equals(hintText)) {
textField.setText("");
textField.setForeground(Color.BLACK);
}
}
@Override
public void focusLost(FocusEvent e) {
//失去焦点时,没有输入内容,显示提示内容
String temp = textField.getText();
if(temp.equals("")) {
textField.setForeground(Color.GRAY);
textField.setText(hintText);
}
}
}
四、源码下载
1.登录说明
1.系统登录:账号:admin 密码:admin;
2.文件存储:BookInfo.txt。
2.下载地址
私信我
五、其他事宜
1.更多系统
Java+Swing系统系列实现
Java+JSP系统系列实现
Java+Servlet系统系列实现
Java+SSM系统系列实现
Java+SSH系统系列实现
Java+Springboot系统系列实现
Java+Springboot+H-ui+Maven实现营销管理系统
Java+Springboot+Bootstrap+Maven实现网上商城系统
Java+Springboot+Bootstrap+Maven实现景区旅游管理系统
1.更多JavaWeb系统请关注专栏。
https://blog.csdn.net/helongqiang/category_10020130.html
2.更多JavaSwing系统请关注专栏。
https://blog.csdn.net/helongqiang/category_6229101.html
2.运行项目
关注B站:水坚石青
后期有更多干货视频推出!!!
3.侵权事宜
如有侵权请联系我删除。
4.支持博主
如果您觉得此文对您有帮助,请点赞加关注加收藏。祝您生活愉快!