欢迎光临散文网 会员登陆 & 注册

Java swing6图书管理系统无注释美化皮肤包版:含SQL部分和效果图

2020-04-26 01:20 作者:诗书画唱  | 我要投稿



package denglu;


import java.awt.Color;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.ArrayList;

import java.util.Vector;


import javax.swing.BorderFactory;

import javax.swing.JButton;

import javax.swing.JComboBox;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTable;

import javax.swing.JTextField;

import javax.swing.table.DefaultTableModel;


class shijian_tushu implements MouseListener, ActionListener {

public tuShuGuanLi tushu = null;


public shijian_tushu(tuShuGuanLi tuShuGuanLi) {

this.tushu = tuShuGuanLi;

}


@Override

public void actionPerformed(ActionEvent arg0) {


String str = arg0.getActionCommand();

if (str.equals("查询")) {

String tid = tushu.txt_tid.getText();

String uname = tushu.txt_tname.getText();

tushu.tushu_load(tid, uname);


} else if (str.equals("增加图书")) {


String tname = tushu.txt_tname1.getText();

String tnu = tushu.txt_num.getText();

int typeid = tushu.arr_type.get(tushu.com_type.getSelectedIndex());

String tchubanshe = tushu.txt_tchubanshe.getText();

String sql = "insert into tushu(ts_name,ts_shuliang,ts_leixingid,"

+ "ts_chubanshe) " + "values('" + tname + "'," + tnu + ","

+ typeid + ",'" + tchubanshe + "')";

if (DBUtils.ZSG(sql)) {

tushu.tushu_load(null, null);

JOptionPane.showMessageDialog(null, "图书增加成功!");


} else {

JOptionPane.showMessageDialog(null, "增加失败,请重试");

}


} else if (str.equals("修改图书")) {


String tid = tushu.txt_tid1.getText();

String tname = tushu.txt_tname1.getText();

String tnu = tushu.txt_num.getText();

int typename = tushu.arr_type

.get(tushu.com_type.getSelectedIndex());

String tchubanshe = tushu.txt_tchubanshe.getText();


String sql = "update tushu set  ts_name='" + tname

+ "',ts_shuliang='" + tnu + "',ts_leixingid=" + typename

+ ",ts_chubanshe='" + tchubanshe + "' where ts_id='" + tid

+ "'";

if (DBUtils.ZSG(sql)) {

tushu.tushu_load(null, null);

JOptionPane.showMessageDialog(null, "修改增加成功!");


} else {

JOptionPane.showMessageDialog(null, "修改失败,请重试");

}

} else if (str.equals("清空")) {

tushu.txt_tid1.setText("");

tushu.txt_tname1.setText("");

tushu.txt_num.setText("");

tushu.txt_tchubanshe.setText("");

tushu.com_type.setSelectedIndex(1);

}

}


@Override

public void mouseClicked(MouseEvent arg0) {


if (arg0.getClickCount() == 2) {


int row = tushu.jt1.getSelectedRow();

tushu.txt_tid1.setText(tushu.jt1.getValueAt(row, 0).toString());

tushu.txt_tname1.setText(tushu.jt1.getValueAt(row, 1).toString());

tushu.txt_num.setText(tushu.jt1.getValueAt(row, 2).toString());

tushu.txt_tchubanshe.setText(tushu.jt1.getValueAt(row, 4)

.toString());


String type = tushu.jt1.getValueAt(row, 3).toString();


tushu.com_type.setSelectedItem(type);

} else if (arg0.isMetaDown()) {

int num = JOptionPane.showConfirmDialog(null, "确定要删除这条信息吗?");

if (num == 0) {

int row = tushu.jt1.getSelectedRow();

String tid = tushu.jt1.getValueAt(row, 0).toString();

String sql = "delete tushu where ts_id='" + tid + "'";

if (DBUtils.ZSG(sql)) {

tushu.tushu_load(null, null);

JOptionPane.showMessageDialog(null, "图书删除成功!");


} else {

JOptionPane.showMessageDialog(null, "删除失败,请重试");

}

}

}

}


@Override

public void mouseEntered(MouseEvent arg0) {

// TODO Auto-generated method stub


}


@Override

public void mouseExited(MouseEvent arg0) {

// TODO Auto-generated method stub


}


@Override

public void mousePressed(MouseEvent arg0) {

// TODO Auto-generated method stub


}


@Override

public void mouseReleased(MouseEvent arg0) {

// TODO Auto-generated method stub


}


}


public class tuShuGuanLi extends JFrame {

public static ArrayList<Integer> arr_type = null;

public static JButton btn_select, btn_insert, btn_update,

btn_qingkong = null;

public static JComboBox com_type = null;

public static DefaultTableModel dtm = null;

public static JPanel jp1, jp2, jp3 = null;

public static JTable jt1 = null;

public static JLabel lb_tid, lb_tname = null;

public static JLabel lb_tid1, lb_tname1, lb_tnum, lb_typename,

lb_tchubanshe = null;

public static JTextField txt_tid, txt_tname = null;

public static JTextField txt_tid1, txt_tname1, txt_num,

txt_tchubanshe = null;


public tuShuGuanLi() {

this.setTitle("图书管理");

this.setLayout(null);

this.setSize(710, 550);

this.setLocationRelativeTo(null);

jp2 = new JPanel();

jp2.setBorder(BorderFactory.createLineBorder(Color.gray));

jp2.setLayout(null);

jp2.setBounds(470, 10, 200, 150);

lb_tid = new JLabel("图书编号:");

lb_tname = new JLabel("图书名称:");

lb_tid.setBounds(10, 10, 70, 30);

lb_tname.setBounds(10, 50, 70, 30);

txt_tid = new JTextField();

txt_tname = new JTextField();

txt_tid.setBounds(80, 10, 100, 30);

txt_tname.setBounds(85, 50, 100, 30);

btn_select = new JButton("查询");

btn_select.setBounds(30, 90, 100, 30);

jp2.add(lb_tid);

jp2.add(lb_tname);

jp2.add(txt_tid);

jp2.add(txt_tname);

jp2.add(btn_select);

jp3 = new JPanel();

jp3.setBorder(BorderFactory.createLineBorder(Color.gray));

jp3.setLayout(null);

jp3.setBounds(470, 170, 200, 300);

lb_tid1 = new JLabel("图书编号:");

lb_tname1 = new JLabel("图书名称:");

lb_tnum = new JLabel("图书数量:");

lb_typename = new JLabel("图书类型:");

lb_tchubanshe = new JLabel("出版社:");

lb_tid1.setBounds(10, 10, 70, 30);

lb_tname1.setBounds(10, 50, 70, 30);

lb_tnum.setBounds(10, 90, 70, 30);

lb_typename.setBounds(10, 130, 70, 30);

lb_tchubanshe.setBounds(10, 170, 70, 30);

jp3.add(lb_tid1);

jp3.add(lb_tname1);

jp3.add(lb_tnum);

jp3.add(lb_typename);

jp3.add(lb_tchubanshe);

txt_tid1 = new JTextField();

txt_tid1.setEditable(false);

txt_tname1 = new JTextField();

txt_num = new JTextField();

txt_tchubanshe = new JTextField();

txt_tid1.setBounds(80, 10, 100, 30);

txt_tname1.setBounds(80, 50, 100, 30);

txt_num.setBounds(80, 90, 100, 30);

txt_tchubanshe.setBounds(80, 170, 100, 30);

com_type = new JComboBox();

String sql = "select * from ts_type";

ResultSet res_type = DBUtils.Select(sql);

arr_type = new ArrayList<Integer>();

try {

while (res_type.next()) {

com_type.addItem(res_type.getObject(2));

arr_type.add(res_type.getInt(1));

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}


com_type.setBounds(80, 130, 100, 30);

btn_insert = new JButton("增加图书");

btn_insert.setBounds(10, 210, 80, 30);

btn_update = new JButton("修改图书");

btn_update.setBounds(95, 210, 80, 30);

btn_qingkong = new JButton("清空");

btn_qingkong.setBounds(10, 250, 160, 30);

btn_select.addActionListener(new shijian_tushu(this));

btn_insert.addActionListener(new shijian_tushu(this));

btn_update.addActionListener(new shijian_tushu(this));

btn_qingkong.addActionListener(new shijian_tushu(this));

jp3.add(txt_tid1);

jp3.add(txt_tname1);

jp3.add(txt_num);

jp3.add(com_type);

jp3.add(txt_tchubanshe);

jp3.add(btn_insert);

jp3.add(btn_update);

jp3.add(btn_qingkong);

this.add(jp2);

this.add(jp3);

this.setVisible(true);

tushu_load(null, null);

}


public void tushu_load(String tid, String tname) {

if (jp1 != null) {

this.remove(jp1);

}

String sql = "select * from tushu a inner join ts_type b on"

+ " a.ts_leixingid=b.ts_leixingid where 1=1";

if (tid != null && tid.length() > 0) {

sql += " and ts_id='" + tid + "'";

}

if (tname != null && tname.length() > 0) {

sql += " and ts_name like'%" + tname + "%'";

}

Vector<Object> v_head = new Vector<Object>();

v_head.add("图书编号");

v_head.add("图书名称");

v_head.add("图书数量");

v_head.add("图书类型");

v_head.add("图书出版社");

Vector<Vector<Object>> v_body = new Vector<Vector<Object>>();

ResultSet res = DBUtils.Select(sql);

try {

while (res.next()) {

Vector<Object> v = new Vector<Object>();

v.add(res.getInt("ts_id"));

v.add(res.getString("ts_name"));

v.add(res.getInt("ts_shuliang"));

v.add(res.getString("ts_leixing"));

v.add(res.getString("ts_chubanshe"));

v_body.add(v);

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}


dtm = new DefaultTableModel(v_body, v_head) {

@Override

public boolean isCellEditable(int a, int b) {

return false;

}

};

jt1 = new JTable(dtm);

jt1.addMouseListener(new shijian_tushu(this));

JScrollPane jsp = new JScrollPane(jt1);

jsp.setBounds(0, 0, 450, 500);

jp1 = new JPanel();

jp1.setLayout(null);

jp1.setBounds(10, 10, 450, 500);

jp1.add(jsp);

this.add(jp1);

}

}

package denglu;


import java.awt.Color;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.Vector;


import javax.swing.BorderFactory;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTable;

import javax.swing.JTextField;

import javax.swing.table.DefaultTableModel;


public class tuShuLeiXingGuanLi extends JFrame {

class shijian_GULtushutype implements MouseListener, ActionListener {

public tuShuLeiXingGuanLi zz = null;


public shijian_GULtushutype(tuShuLeiXingGuanLi z) {

this.zz = z;

}


@Override

public void actionPerformed(ActionEvent arg0) {


String str = arg0.getActionCommand();

if (str.equals("查询类型")) {

String tname = zz.txt_ttypename.getText();


zz.typeload(tname);

} else if (str.equals("修改类型")) {

String tid = zz.txt_id.getText();

String tname = zz.txt_ttypename.getText();

String sql = "update ts_type set ts_leixing='" + tname

+ "' where ts_leixingid='" + tid + "'";

if (DBUtils.ZSG(sql)) {

zz.typeload(null);

JOptionPane.showMessageDialog(null, "修改成功");

} else {

JOptionPane.showMessageDialog(null, "修改失败,请重试");

}

} else if (str.equals("增加类型")) {

String tid = zz.txt_id.getText();

String tname = zz.txt_ttypename.getText();

String sql = "insert into ts_type values('" + tname + "')";

if (DBUtils.ZSG(sql)) {

zz.typeload(null);

JOptionPane.showMessageDialog(null, "增加成功");

} else {

JOptionPane.showMessageDialog(null, "增加失败,请重试");

}

} else if (str.equals("清空")) {

zz.txt_id.setText("");

zz.txt_ttypename.setText("");

}

}


@Override

public void mouseClicked(MouseEvent arg0) {


if (arg0.getClickCount() == 2) {


int row = zz.tb1.getSelectedRow();

zz.txt_id.setText(zz.tb1.getValueAt(row, 0).toString());

zz.txt_ttypename.setText(zz.tb1.getValueAt(row, 1).toString());

} else if (arg0.isMetaDown()) {


int row = zz.tb1.getSelectedRow();

String id = zz.tb1.getValueAt(row, 0).toString();

String sql = "delete ts_type where ts_leixingid='" + id + "'";

int num = JOptionPane.showConfirmDialog(null, "确定要册除这条信息吗?");

if (num == 0) {

if (DBUtils.ZSG(sql)) {


JOptionPane.showMessageDialog(null, "册除成功");

zz.typeload(null);

return;


} else {


JOptionPane.showMessageDialog(null, "出现了未知的错误,请重试");

}

}

}

}


@Override

public void mouseEntered(MouseEvent arg0) {

// TODO Auto-generated method stub


}


@Override

public void mouseExited(MouseEvent arg0) {

// TODO Auto-generated method stub


}


@Override

public void mousePressed(MouseEvent arg0) {

// TODO Auto-generated method stub


}


@Override

public void mouseReleased(MouseEvent arg0) {

// TODO Auto-generated method stub


}

}


public static JButton btn1, btn2, btn3, btn4 = null;

public static DefaultTableModel dtm = null;

public static JPanel jp1, jp2 = null;

public static JLabel lb_id, lb_name = null;

public static JTable tb1 = null;


public static JTextField txt_id, txt_ttypename = null;


public tuShuLeiXingGuanLi() {

this.setTitle("图书类型管理");

this.setLayout(null);

this.setSize(600, 600);

this.setLocationRelativeTo(null);

jp2 = new JPanel();

jp2.setLayout(null);

jp2.setBounds(368, 10, 200, 350);

jp2.setBorder(BorderFactory.createLineBorder(Color.gray));

lb_id = new JLabel("类型id:");


lb_name = new JLabel("类型名称:");

lb_id.setBounds(10, 20, 70, 30);

lb_name.setBounds(10, 60, 70, 30);

jp2.add(lb_id);

jp2.add(lb_name);

txt_id = new JTextField();

txt_id.setEditable(false);

txt_ttypename = new JTextField();

txt_id.setBounds(65, 20, 120, 30);

txt_ttypename.setBounds(65, 60, 120, 30);

jp2.add(txt_id);

jp2.add(txt_ttypename);

btn1 = new JButton("查询类型");

btn2 = new JButton("修改类型");

btn3 = new JButton("增加类型");

btn4 = new JButton("清空");

btn1.setBounds(0, 100, 100, 30);

btn2.setBounds(110, 100, 100, 30);

btn3.setBounds(0, 140, 100, 30);

btn4.setBounds(110, 140, 100, 30);

btn1.addActionListener(new shijian_GULtushutype(this));

btn2.addActionListener(new shijian_GULtushutype(this));

btn3.addActionListener(new shijian_GULtushutype(this));

btn4.addActionListener(new shijian_GULtushutype(this));

jp2.add(btn1);

jp2.add(btn2);

jp2.add(btn3);

jp2.add(btn4);

this.add(jp2);

this.setVisible(true);

typeload(null);

}


public tuShuLeiXingGuanLi(Object object) {

// TODO Auto-generated constructor stub

}


public void typeload(String str) {

if (jp1 != null) {

this.remove(jp1);

}

String sql = "select * from ts_type where 1=1";

if (str != null) {

sql += "and ts_leixing like '%" + str + "%'";

}

Vector<Object> v_head = new Vector<Object>();

v_head.add("类型编号");

v_head.add("类型名称");

Vector<Vector<Object>> v_body = new Vector<Vector<Object>>();

ResultSet res = DBUtils.Select(sql);


try {

while (res.next()) {

Vector<Object> v = new Vector<Object>();

v.add(res.getInt("ts_leixingid"));

v.add(res.getString("ts_leixing"));

v_body.add(v);


}

} catch (SQLException e) {


e.printStackTrace();

}

dtm = new DefaultTableModel(v_body, v_head) {

@Override

public boolean isCellEditable(int a, int b) {

return false;

}

};


tb1 = new JTable(dtm);

tb1.addMouseListener(new shijian_GULtushutype(this));

JScrollPane jsp = new JScrollPane(tb1);

jsp.setBounds(0, 0, 350, 400);

jp1 = new JPanel();

jp1.setLayout(null);

jp1.add(jsp);

jp1.setBounds(8, 0, 350, 400);


this.add(jp1);

}

}




package denglu;


public class yonghu {

private String yh_A;

private int yh_id;

private String yh_name;

private String yh_phone;

private String yh_pwd;

private String yh_Q;

private String yh_sex;

private String yh_typename;

private String yh_uname;


public yonghu() {

}


public yonghu(String yh_Q, int yh_id, String yh_uname, String yh_name,

String yh_phone, String yh_pwd, String yh_sex, String yh_typename,

String yh_A) {


this.yh_Q = yh_Q;

this.yh_id = yh_id;

this.yh_uname = yh_uname;

this.yh_name = yh_name;

this.yh_phone = yh_phone;

this.yh_pwd = yh_pwd;

this.yh_sex = yh_sex;

this.yh_typename = yh_typename;

this.yh_A = yh_A;

}


public String getYh_A() {

return yh_A;

}


public int getYh_id() {

return yh_id;

}


public String getYh_name() {

return yh_name;

}


public String getYh_phone() {

return yh_phone;

}


public String getYh_pwd() {

return yh_pwd;

}


public String getYh_Q() {

return yh_Q;

}


public String getYh_sex() {

return yh_sex;

}


public String getYh_typename() {

return yh_typename;

}


public String getYh_uname() {

return yh_uname;

}


public void setYh_A(String yh_A) {

this.yh_A = yh_A;

}


public void setYh_id(int yh_id) {

this.yh_id = yh_id;

}


public void setYh_name(String yh_name) {

this.yh_name = yh_name;

}


public void setYh_phone(String yh_phone) {

this.yh_phone = yh_phone;

}


public void setYh_pwd(String yh_pwd) {

this.yh_pwd = yh_pwd;

}


public void setYh_Q(String yh_Q) {

this.yh_Q = yh_Q;

}


public void setYh_sex(String yh_sex) {

this.yh_sex = yh_sex;

}


public void setYh_typename(String yh_typename) {

this.yh_typename = yh_typename;

}


public void setYh_uname(String yh_uname) {

this.yh_uname = yh_uname;

}


@Override

public String toString() {

return "users [yh_Q=" + yh_Q + ", yh_id=" + yh_id + ", yh_uname="

+ yh_uname + ", yh_name=" + yh_name + ", yh_phone=" + yh_phone

+ ", yh_pwd=" + yh_pwd + ", yh_sex=" + yh_sex

+ ", yh_typename=" + yh_typename + ", yh_A=" + yh_A + "]";

}


}





Java swing6图书管理系统无注释美化皮肤包版:含SQL部分和效果图的评论 (共 条)

分享到微博请遵守国家法律