在學完java基礎篇的時候,安排做了一個綜合版的java基礎專案,可以把之前學到的知識綜合運用,
圖書管理系統,
- 一.專案設計到的知識
- 1.MVC設計模式思想(分包)
- >專案分包
- >MVC簡單介紹
- 2.GUI(圖形化界面)
- 3.JDBC連接MySql資料庫
- 4.I/O流
- 5.面向物件思想
- 專案運行效果
- 登錄界面
- 主界面
- 讀者資訊管理
- 讀者資訊添加
- 讀者資訊查詢和修改
- 讀者資訊查詢
- 讀者資訊修改
- 圖書資訊管理
- 圖書資訊添加
- 圖書資訊查詢
- 圖書資訊修改
- 圖書借閱管理
- 圖書借閱
- 圖書歸還
- 基礎資訊維護
- 圖書類別設定
- 讀者類別設定
- 罰金設定
- 用戶管理
- 修改密碼
- 用戶添加
- 用戶洗掉
一.專案設計到的知識
1.MVC設計模式思想(分包)
>專案分包

運用這種設計模式的優點:
MVC 是一種程式開發設計模式,它實作了顯示模塊與功能模塊的分離,提高了程式的可維護性、可移植性、可擴展性與可重用性,降低了程式的開發難度,它主要分模型、視圖、控制器三層,
>MVC簡單介紹
M model業務模型(pojo/domain/bean)與現實中物體類聯系
V views視圖層(views)
圖形化界面(gui)
C controller
用戶與軟體互動,處理資訊
dao層(資料持久化)
提供資料
service層(處理邏輯)
處理資料
controller(javaweb里邊的內容,servlet)
較詳細的圖示:

2.GUI(圖形化界面)
其中的GUI代碼案例:
package org.vector.view;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
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;
import org.vector.bean.Book;
import org.vector.bean.Booktype;
import org.vector.bean.Borrowbook;
import org.vector.bean.Reader;
import org.vector.bean.Readertype;
import org.vector.bean.Users;
import org.vector.serviceImpl.UsersServiceImpl;
public class BookLogin extends JFrame{
public BookLogin() {
buliding();
addListeners();
}
public static String name1;
public static List<Users> list = new ArrayList<Users>();
public static List<Reader> list1 = new ArrayList<Reader>();
public static List<Book> list2 = new ArrayList<Book>();
public static List<Readertype> list3 = new ArrayList<Readertype>();
public static List<Booktype> list4 = new ArrayList<Booktype>();
public static List<Borrowbook> list5 = new ArrayList<Borrowbook>();
private JButton login,reset,register;
private JLabel name,password,label;
private JTextField name_Text;
private JPasswordField password_Text;
private void buliding() {
// TODO Auto-generated method stub
setLayout(null);
background();
setTitle("圖書借閱系統登錄界面");
Font font = new Font("圓體", Font.BOLD, 50);
label = new JLabel("圖書借閱系統");
label.setFont(font);
label.setBounds(40, 20, 400, 50);
add(label);
name = new JLabel("用戶名:");
name.setBounds(45, 100, 120, 30);
add(name);
name_Text = new JTextField(20);
name_Text.setBounds(100, 100, 200, 30);
add(name_Text);
password = new JLabel("密 碼:");
password.setBounds(45, 150, 120, 30);
add(password);
password_Text = new JPasswordField(20);
password_Text.setBounds(100, 150, 200, 30);
add(password_Text);
login = new JButton("登錄");
login.setBounds(50, 200, 100, 35);
add(login);
reset = new JButton("重置");
reset.setBounds(150, 200, 100, 35);
add(reset);
// register = new JButton("注冊");
// register.setBounds(250, 200, 100, 35);
// add(register);
setBounds(400,300,400,300);
setLocation((2000-getWidth())/2,(1000-getHeight())/2);
setResizable(false);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setVisible(true);
}
public void background() {
setSize(600, 500);
setLocation(100, 100);
String path = "Login.jpg";
ImageIcon background = new ImageIcon(path);
JLabel label = new JLabel(background);
label.setBounds(0, 0, this.getWidth(), this.getHeight());
JPanel imagePanel = (JPanel) this.getContentPane();
imagePanel.setOpaque(false);
this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void addListeners() {
login.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
login.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
int flag = 0;
String name = name_Text.getText();
String password = password_Text.getText();
name1 = name;
UsersServiceImpl user = new UsersServiceImpl();
BookLogin.list.clear();
BookLogin.list.addAll(user.findUsers());
for (int i = 0; i < BookLogin.list.size(); i++) {
if(name.equals(BookLogin.list.get(i).getName())&&password.equals(BookLogin.list.get(i).getPassword())){
JOptionPane.showMessageDialog(null, "登錄成功", "標題", JOptionPane.WARNING_MESSAGE);
BookLogin.this.dispose();
new BorrowbookView().setVisible(true);
flag = 1;
BookLogin.this.dispose();
new BorrowbookView().setVisible(true);
break;
}
}
if(flag == 0) {
JOptionPane.showMessageDialog(null, "登錄失敗,該用戶不存在", "標題", JOptionPane.WARNING_MESSAGE);
}
}
});
reset.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
BookLogin.this.dispose();
new BookLogin().setVisible(true);
}
});
// register.addActionListener(new ActionListener() {
//
// @Override
// public void actionPerformed(ActionEvent e) {
// // TODO Auto-generated method stub
// BookLogin.this.dispose();
// new UserAdd().setVisible(true);
// }
// });
}
}
3.JDBC連接MySql資料庫
用了c3p0對原生JDBC的封裝思想,大大提高了開發者的效率,
c3p0xml組態檔
<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config>
<!-- c3p0默認配置,下面還可以配置多個資料庫 -->
<default-config>
<property name="jdbcUrl">jdbc:mysql://localhost:3306/mybook?characterEncoding=UTF8
</property>
<property name="driverClass">com.mysql.jdbc.Driver</property>
<property name="user">root</property>
<property name="password">password</property>
<property name="initialPoolSize">6</property>
<property name="maxPoolSize">10</property>
<property name="maxIdleTime">10000</property>
</default-config>
</c3p0-config>

大多數情況下只用改,資料庫名,賬號,密碼,別的默認值就行,
4.I/O流
I/O流是開發程序中,最耗費,最占用資源的一門技術,在開發中盡量減少對I/O的使用,
5.面向物件思想
面向物件的思想是在整個學java期間,都不斷去學習,這種思想是潛移默化的,短時間內,往往難以清楚地理解,
專案運行效果
登錄界面


主界面

…紳士們,請識訓你們的目光,
讀者資訊管理

讀者資訊添加


讀者資訊查詢和修改

讀者資訊查詢

查詢成功!

讀者資訊修改

修改成功!

圖書資訊管理

圖書資訊添加


由于東西較多,后面的我就不一一演示了,大家有興趣的可以自己做一個更好的,
圖書資訊查詢

圖書資訊修改

圖書借閱管理

圖書借閱

圖書歸還

基礎資訊維護

圖書類別設定

讀者類別設定

罰金設定

用戶管理

修改密碼

用戶添加

用戶洗掉

詳細的可以了解,資源里邊的專案,
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/244265.html
標籤:java
