Mysql+javafx+sence bulider实现图书借阅系统

本文档详细介绍了如何通过E-R图理解图书借阅系统,实机展示了登录、注册、图书查询等界面,并利用MVC架构、JDBC及javafx sence builder工具实现系统的各个功能,包括管理员和用户的不同操作、密码验证等。
摘要由CSDN通过智能技术生成

目录

 通过E-R图来了解系统

 实机演示

登入界面

注册界面一

注册界面二(出现重复用户名)

注册界面三(未出现重复用户名)

用户登入后界面

图书信息查询

用户借阅查询

 管理员账号登入

 管理员登入后的界面

图书信息查询(管理员)

 用户信息管理(所有用户的借阅记录和密码)

 MVC架构

 实现代码

登入界面代码

登入界面判断代码

用户(管理员)登入后界面代码

 用户(管理员)图书查询(增删改)界面

 用户还书界面代码

查询用户借阅信息界面(管理员)代码

JDBC

关于管理员和用户的操作

 密码验证和注册验证以及管理员和用户登入验证的代码

实体类代码

管理员类

书类

用户类

fxml(javafx)

图书信息查询

借书信息查询(用户)

注册界面

登入界面

登入后选择界面

借书信息查询(管理员)


开发工具:idea2022, datagrip,  javafx sence builder。

 通过E-R图来了解系统

通过E-R图我们可以清晰的抓住借阅系统中实体与实体之间的关联,不难看出

管理员管理用户和图书,是一对多的关系。

用户借阅图书也是一对多的关系。

并且各个实体的属性我们也是一目了然。

 实机演示

登入界面

注册界面一

注册界面二(出现重复用户名)

注册界面三(未出现重复用户名)

用户登入后界面

图书信息查询

用户借阅查询

 管理员账号登入

 管理员登入后的界面

图书信息查询(管理员)

 用户信息管理(所有用户的借阅记录和密码)

点击行再点击按钮进行操作

 MVC架构

经典MVC模式中,M是指业务模型,V是指用户界面,C则是控制器.

实体类包(模型)

界面包(javafx)

控制器包

jdbc包

 实现代码

登入界面代码

package com.example.lib;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;

public class LibApplication extends Application {
    //舞台封装
    public static Stage stage;
    public void start(Stage stage) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(LibApplication.class.getResource("hello-view.fxml"));
        this.stage = stage;
        Scene scene = new Scene(fxmlLoader.load(), 600, 400);
        stage.setTitle("图书馆管理系统");
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) throws Exception{
        launch();
    }
}

登入界面判断代码

package com.example.lib;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import JDBC.*;
import javafx.stage.Stage;
import java.io.IOException;
import java.net.URL;
import static com.example.lib.LibApplication.stage;

public class Controller {
    @FXML

    private Button exit;
    @FXML
    private PasswordField password;

    @FXML
    private Button enroll;

    @FXML
    private Button login;

    @FXML
    private TextField user;

    @FXML
    public static String userid;

    public static  int pd=0;
    @FXML
    void userOnAction(ActionEvent event) {
        TextField user =new TextField();
        this.user=user;
    }

    @FXML
    void passwordOnAction(ActionEvent event) {
        PasswordField password=new PasswordField();
        this.password=password;
    }

    public void start(Stage stage){
        URL url = getClass().getResource("login.fxml");
        Parent root=null;
        try {
            root = FXMLLoader.load(url);
        } catch (IOException e) {
            e.printStackTrace();
        }
        Scene scene = new Scene(root, 600, 400);
        stage.setTitle("图书馆管理系统");
        stage.setScene(scene);
        stage.show();
    }

    @FXML
    void admOnAction(ActionEvent event) throws Exception {
       pd=1;
    }
    @FXML
    public void loginOnAction(ActionEvent event) throws Exception {
        SqlUtil a=new SqlUtil();
        boolean pd=false;
        if(this.pd==0){
             pd=a.verify(user.getText(),password.getText());
            System.out.println("用户登入中");
        }else{
             pd=a.admverify(user.getText(),password.getText());
            System.out.println("管理员登入中");
        }
        SqlUtil su=new SqlUtil();
        userid=su.Getid(user.getText());
//        System.out.println(userid);
       if (pd){
           start(stage);
           System.out.println("登入成功");
       }else {
           System.out.println("登入失败");
       }

    }


    @FXML
    void enrollOnAction(ActionEvent event) {
        URL url = getClass().getResource("enroll.fxml");
        Parent root=null;
        try {
            root = FXMLLoader.load(url);
        } catch (IOException e) {
            e.printStackTrace();
        }
        Scene scene = new Scene(root, 600, 400);
        stage.setTitle("图书馆管理系统");
        stage.setScene(scene);
        stage.show();
    }
    @FXML
    void exitOnAction(ActionEvent event) {
        stage.close();
    }

}

用户(管理员)登入后界面代码

package com.example.lib;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
import java.io.IOException;
import static com.example.lib.Controller.pd;
import static com.example.lib.LibApplication.stage;


public class LoginCon {
    @FXML
    private Button Inquire;
    @FXML
    private Button userRead;
    @FXML
    private Button exitbutton;
    @FXML
    private Button userin;
    @FXML
    //普通用户和管理员界面区别
    public void initialize(){
        if (pd==0){
            userin.setVisible(false);
        }else{
            userRead.setVisible(false);
        }
    }
    //封装图书查询界面
    void Start(Stage stage) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(LibApplication.class.getResource("Bookinquiries.fxml"));
        Scene scene = new Scene(fxmlLoader.load(), 600, 400);
        stage.setTitle("图书馆管理系统");
        stage.setScene(scene);
        stage.show();
    }

    @FXML
    void InquireOnAction(ActionEvent event) throws Exception {
        Start(stage);
    }
    //封装图书归还界面
    void Start1(Stage stage) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(LibApplication.class.getResource("Borrow-Inquiries.fxml"));
        Scene scene = new Scene(fxmlLoader.load(), 600, 400);
        stage.setTitle("图书馆管理系统");
        stage.setScene(scene);
        stage.show();
    }
    @FXML
    void userReadOnAction(ActionEvent event) throws IOException {
        Start1(stage);
    }

    @FXML
    void exitbuttonOnAction(ActionEvent event) throws IOException {
        pd=0;
        LibApplication lib = new LibApplication();
        lib.start(stage);
    }
    //封装用户信息查询界面
    void Start2(Stage stage) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(LibApplication.class.getResource("userin.fxml"));
        Scene scene = new Scene(fxmlLoader.load(), 600, 400);
        stage.setTitle("图书馆管理系统");
        stage.setScene(scene);
        stage.show();
    }
    @FXML
    void userinOnAction(ActionEvent event) throws IOException {
        Start2(stage);
    }
}

 用户(管理员)图书查询(增删改)界面

package com.example.lib;

import JDBC.Bookinquiries;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import role.Book;

import java.io.IOException;

import static com.example.lib.Controller.pd;
import static com.example.lib.LibApplication.stage;

public class BookCon {

    @FXML
    private Button clear;

    @FXML
    private Button add;

    @FXML
    private TextField textAuthor;

    @FXML
    private TextField textquiries;

    @FXML
    private Button update;
    @FXML

    private Button delete;

    @FXML
    private Button borrow;

    @FXML
    private TextField textPrice;

    @FXML
    private TextField textId;

    @FXML
    private TextField textName;

    @FXML
    private TextField textState;

    @FXML
    private TableColumn<Book, String> Price;

    @FXML
    private TableColumn<Book, String> author;

    @FXML
    private TableColumn<Book, String> State;

    @FXML
    private TableView<Book> booktable;

    @FXML
    private TableColumn<Book, String> bookname;

    @FXML
    private Button quiries;

    @FXML
    private Button exit1;

    @FXML
    private TableColumn<Book, String> bookid;

    @FXML
    public static Book book;

    @FXML
    private TextField textquiries2;

    @FXML
    private void initialize() throws Exception {
        //管理员和用户的部分功能隐藏
        if (pd == 0) {
            textId.setVisible(false);
            textAuthor.setVisible(false);
            textName.setVisible(false);
            textState.setVisible(false);
            textPrice.setVisible(false);
            add.setVisible(false);
            delete.setVisible(false);
            update.setVisible(false);
            clear.setVisible(false);
        } else {
            borrow.setVisible(false);
        }
        Bookinquiries s = new Bookinquiries();
        //获取图书信息
        //cellvalueFactory设置单元格(定义列,然后通过book集合填入信息)
        bookid.setCellValueFactory(cellData -> cellData.getValue().getId());
        bookname.setCellValueFactory(cellData -> cellData.getValue().getName());
        author.setCellValueFactory(cellData -> cellData.getValue().getAuthor());
        Price.setCellValueFactory(cellData -> cellData.getValue().getPrice());
        State.setCellValueFactory(cellData -> cellData.getValue().getState());
        booktable.getItems().addAll(s.quiries());
        System.out.println("%%%%%%%%%%%%%%%");
        //鼠标点击行事件
        booktable.setRowFactory(a -> {
            TableRow<Book> row = new TableRow<Book>();
            row.setOnMouseClicked(event -> {
                if (event.getClickCount() == 1 && (!row.isEmpty())) {
                    book = row.getItem();
                    System.out.println(book);

                    //获取book对象的属性(以book.getName().getValue().toString()为例)
                    textName.setText(book.getName().getValue().toString());
                    textId.setText(book.getId().getValue().toString());
                    textAuthor.setText(book.getAuthor().getValue().toString());
                    textPrice.setText(book.getPrice().getValue().toString());
                    textState.setText(book.getState().getValue().toString());
                }
            });
            return row;
        });
    }
    //借阅
    @FXML
    void borrowOnAction(ActionEvent event) throws Exception
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值