Java+Swing实现学校教材管理系统
一、系统介绍
本系统实现的功能:管理员登录、教材的增删改查、导出PDF。
JDK:1.8
数据库:Mysql8.0.13
二、系统展示
1.登录页
2.主页面
3.导出表单
三、部分代码
DBUtil.java
package com.sjsq;
/**
* 此类用以载入数据库
* @author 郑伟
* */
import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JOptionPane;
public class DBUtil {
// 数据库驱动名
private static String DriverName = "com.mysql.cj.jdbc.Driver";
// 数据库协议
private static String dbUril = "jdbc:mysql://localhost:3306/teachbook_management_swing?serverTimezone=UTC";
// 数据库用户名
private static String dbName = "root";
// 数据库密码
private static String dbPassword = "admin";
public static Connection getlink() {
try {
Class.forName(DriverName);
System.out.println("正在加载...");
Connection connection = DriverManager.getConnection(dbUril, dbName, dbPassword);
System.out.println("连接成功!");
// ResultSet rs = stmt.executeQuery(sql);
return connection;
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "数据库链接失败!", "警告", JOptionPane.ERROR_MESSAGE);
System.out.println("连接失败");
e.printStackTrace();
return null;
}
}
public static void main(String args[]) {
getlink();
}
}
Login.java
package com.sjsq;
/**
* 此类为登录窗口类
* 由Visual Editor 生成
* @author 郑伟
* @author shuijianshiqing
* @date 2020-12-30
*
* */
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import org.jvnet.substance.skin.SubstanceCremeLookAndFeel;
public class Login extends JFrame implements WindowListener, ActionListener, KeyListener {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JButton jButton = null;
private JButton jButton1 = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JLabel jLabel2 = null;
private JTextField jTextField = null;
private JPasswordField jPasswordField = null;
private Connection connection; // @jve:decl-index=0:
private Statement stmt;
private String username;
private int flag = 0;
/**
* This is the default constructor
*/
public Login() {
super();
try {
UIManager.setLookAndFeel(new SubstanceCremeLookAndFeel());
} catch (UnsupportedLookAndFeelException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
initialize();
Dimension screen = getToolkit().getScreenSize(); // 得到屏幕尺寸
// pack(); //窗口适应组件尺寸
setLocation((screen.width - getWidth()) / 2, (screen.height - getHeight()) / 2);// 使窗口出现在屏幕中间
this.setResizable(false);// 不可缩放~~
this.addWindowListener(this);
connection = DBUtil.getlink();
try {
stmt = connection.createStatement();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} // 链接数据库
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
// 登录窗口大小
this.setSize(500, 308);
this.setContentPane(getJContentPane());
this.setTitle("欢迎登录教材管理系统");
}
// 登录函数
private void denglu() {
if (flag > 2) {
jButton.setEnabled(false);
}
this.jLabel.setText("登录中请稍候。。");
username = jTextField.getText();
String pwd = String.valueOf(jPasswordField.getPassword());
String yz = new String("Select username,pswd,yanzheng from login where username='" + username + "'");
try {
ResultSet result = stmt.executeQuery(yz);
if (result.next()) { // 用户名存在~
if (pwd.equals(result.getString(2))) {
if (result.getString(3).equals("1")) { // 验证权限
this.jLabel.setText(" 登录成功");
this.flag = 1; // 若取得数据的第三项是1的话,则把flag设置为1
this.setVisible(false);
XFlashScreen splash = new XFlashScreen();
splash.start(); // 运行启动界面
} else if (result.getString(3).equals("4")) { // 验证权限
this.jLabel.setText(" 登录成功");
this.flag = 4; // 若取得数据的第三项是4的话,则把flag设置为4
this.setVisible(false);
}
} else {
this.jLabel.setText(" 密码错误 -_-!");
flag++;
}
} else {
this.jLabel.setText(" 没有此用户 -_-!");
flag++;
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(160, 55, 57, 17));
jLabel1.setText("账号:");
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(160, 100, 55, 17));
jLabel2.setText("密码:");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(180, 150, 177, 14));
jLabel.setText("不能尝试超过4次哦~(*^__^*) ");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.setBackground(new Color(255, 255, 225));
jContentPane.add(getJButton(), null);
jContentPane.add(getJButton1(), null);
jContentPane.add(jLabel, null);
jContentPane.add(jLabel1, null);
jContentPane.add(jLabel2, null);
jContentPane.add(getJTextField(), null);
jContentPane.add(getJPasswordField(), null);
}
return jContentPane;
}
public void windowActivated(WindowEvent arg0) {
}
public void windowClosed(WindowEvent arg0) {
System.exit(0);
}
public void windowClosing(WindowEvent arg0) {
}
public void windowDeactivated(WindowEvent arg0) {
}
public void windowDeiconified(WindowEvent arg0) {
}
public void windowIconified(WindowEvent arg0) {
}
public void windowOpened(WindowEvent arg0) {
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton(new ImageIcon("./pic/key.gif"));
jButton.setBounds(new Rectangle(120, 180, 83, 25));
// jButton.setFont(new Font("Dialog", Font.BOLD, 11));
jButton.setText("登录");
jButton.addActionListener(this);
}
return jButton;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton(new ImageIcon("./pic/exit.gif"));
jButton1.addActionListener(this);
jButton1.setBounds(new Rectangle(300, 180, 83, 25));
// jButton1.setFont(new Font("Dialog", Font.BOLD, 11));
jButton1.setText("退出");
}
return jButton1;
}
/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setBounds(new Rectangle(200, 45, 156, 35));
jTextField.addKeyListener(this);
}
return jTextField;
}
/**
* This method initializes jPasswordField
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getJPasswordField() {
if (jPasswordField == null) {
jPasswordField = new JPasswordField();
jPasswordField.setBounds(new Rectangle(200, 90, 156, 35));
jPasswordField.addKeyListener(this);
}
return jPasswordField;
}
public void actionPerformed(ActionEvent e) {
if ((JButton) e.getSource() == jButton1) {
this.dispose();
System.exit(0);
} else if ((JButton) e.getSource() == jButton) {
denglu();
}
}
public void keyPressed(KeyEvent arg0) {
}
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER)/** 判断是否回车 */
denglu();
}
public void keyTyped(KeyEvent arg0) {
}
public static void main(String[] args) {
Login aaa = new Login();
aaa.setVisible(true);
}
}
MyTable.java
package com.sjsq;
import javax.swing.table.AbstractTableModel;
class MyTable extends AbstractTableModel {
Object[][] p = null;
String[] n = null;
MyTable(Object[][] p, String[] n) {
this.p = p;
this.n = n;
}
public int getColumnCount() {
return n.length;
}
public int getRowCount() {
return p.length;
}
public Object getValueAt(int row, int col) {
return p[row][col];
}
public String getColumnName(int col) {
return n[col];
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
public boolean isCellEditable(int row, int col) {
if (col == 0) {
return false;
} else {
return true;
}
}
public void setValueAt(Object value, int row, int col) {
{
p[row][col] = value;
}
}
}
XMainFrame.java
package com.sjsq;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Rectangle;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
public class XMainFrame extends JFrame implements WindowListener {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JTabbedPane jTabbedPane = null;
XAddForm xaddform;
/**
* This is the default constructor
*/
public XMainFrame() {
super();
xaddform = new XAddForm();
initialize();
Dimension screen = getToolkit().getScreenSize(); // 得到屏幕尺寸
// pack(); //窗口适应组件尺寸
setLocation((screen.width - 800) / 2, (screen.height - 600) / 2);
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(567, 401);
this.setContentPane(getJContentPane());
this.setTitle("教材管理系统");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.fill = GridBagConstraints.BOTH;
gridBagConstraints.gridwidth = -1;
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.ipadx = -5;
gridBagConstraints.ipady = -7;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.gridheight = -1;
jContentPane = new JPanel();
jContentPane.setLayout(new GridBagLayout());
jContentPane.add(getJTabbedPane(), gridBagConstraints);
}
return jContentPane;
}
/**
* This method initializes jTabbedPane
*
* @return javax.swing.JTabbedPane
*/
private JTabbedPane getJTabbedPane() {
if (jTabbedPane == null) {
jTabbedPane = new JTabbedPane();
xaddform.setBounds(new Rectangle(1, 2, 558, 366));
jTabbedPane.addTab("表单提交", null, xaddform, null);
}
return jTabbedPane;
}
public void windowActivated(WindowEvent arg0) {
// TODO 自动生成方法存根
}
public void windowClosed(WindowEvent arg0) {
// TODO 自动生成方法存根
}
public void windowClosing(WindowEvent arg0) {
// TODO 自动生成方法存根
System.exit(0);
}
public void windowDeactivated(WindowEvent arg0) {
// TODO 自动生成方法存根
}
public void windowDeiconified(WindowEvent arg0) {
// TODO 自动生成方法存根
}
public void windowIconified(WindowEvent arg0) {
// TODO 自动生成方法存根
}
public void windowOpened(WindowEvent arg0) {
// TODO 自动生成方法存根
}
}
四、其他
1.其他系统实现
Java+JSP系统系列实现
Java+JSP实现学生图书管理系统
Java+JSP实现学生信息管理系统
Java+JSP实现用户信息管理系统
Java+Servlet+JSP系统系列实现
Java+Servlet+JSP实现航空订票系统
Java+Servlet+JSP实现新闻发布系统
Java+Servlet+JSP实现图书管理系统
Java+Servlet+JSP实现停车场管理系统
Java+Servlet+JSP实现房屋租赁管理系统
Java+Servlet+JSP实现学生选课管理系统
Java+Servlet+JSP实现宠物诊所管理系统
Java+Servlet+JSP实现学生宿舍管理系统
Java+Servlet+JSP实现学生信息管理系统
Java+Servlet+JSP实现学生成绩管理系统1
Java+Servlet+JSP实现学生成绩管理系统2
Java+SSM系统系列实现
Java+SSM+JSP实现宠物商城系统
Java+SSM+JSP实现超市订单系统
Java+SSM+JSP实现图书管理系统
Java+SSM+Easyui实现网上考试系统
Java+SSM+Layui实现学生成绩管理系统
Java+SSM+Bootstrap实现学生信息管理系统
Java+SSM+Bootstrap+Maven实现网上书城系统
Java+SSM+Bootstrap+Maven实现学校教务管理系统
Java+SSH系统系列实现
Java+SSH+Bootstrap实现在线考试系统
Java+SSH+JSP实现医院在线挂号系统
Java+Springboot系统系列实现
Java+Springboot+H-ui实现营销管理系统
Java+Springboot+Bootstrap实现网上商城系统
Java+Springboot+Bootstrap+Maven实现景区旅游管理系统
JavaSwing+Mysql系统系列实现
Java+Swing实现斗地主游戏
Java+Swing实现图书管理系统
Java+Swing实现医院管理系统
Java+Swing实现考试管理系统
Java+Swing实现酒店管理系统
Java+Swing实现超市管理系统
Java+Swing实现网上订餐系统
Java+Swing实现电影购票系统
Java+Swing实现仓库管理系统1
Java+Swing实现仓库管理系统2
Java+Swing实现进销存管理系统
Java+Swing实现通讯录管理系统
Java+Swing实现停车场管理系统
Java+Swing实现学生宿舍管理系统
Java+Swing实现学生选课管理系统
Java+Swing实现学生成绩管理系统
Java+Swing实现学校教材管理系统
Java+Swing实现学校教务管理系统
Java+Swing实现企业人事管理系统
Java+Swing实现电子相册管理系统
Java+Swing实现学生信息管理系统1
Java+Swing实现学生信息管理系统2
Java+Swing实现自助取款机(ATM)系统
JavaSwing+Txt系统系列实现
Java+Swing实现超市管理系统-TXT存储信息
Java+Swing实现宠物商店管理系统-TXT存储信息
Java+Swing实现自助取款机(ATM)系统-TXT存储信息
2.获取源码
3.备注
如有侵权请联系我删除。