Java swing(3)SQL部分,自己设计完善的独特功能图书管理系统,获取下拉框等文字内容

总框架:

SQL部分:
create table yonghu(
yh_ID int primary key identity(1,1),
yh_Uname varchar(30) not null,
yh_Pwd varchar(30) not null,
yh_Name varchar(30) not null,
yh_Age int,
yh_Sex varchar(20),
yh_Phone varchar(100),
yh_Address varchar(200),
yh_Jieshao varchar(500),
yh_Q varchar(500),
yh_AQ varchar(500)
);
insert into yonghu values('1','11','诗书画唱1',21,'男','19999999999','江西','阳光帅气的男孩子','你爱好多吗?','多');
insert into yonghu values('2','22','诗书画唱2',22,'男','29999999999','北京','阳光帅气的男孩子','你看过的书多吗?','多');
insert into yonghu values('3','33','诗书画唱3',23,'男','39999999999','上海','阳光帅气的男孩子','你会的技能多吗?','多');
insert into yonghu values('4','44','诗书画唱4',24,'男','49999999999','湖南','阳光帅气的男孩子','你喜欢的动漫吗?','多');
insert into yonghu values('5','55','诗书画唱5',25,'男','59999999999','浙江','阳光帅气的男孩子','你喜欢的歌曲多吗?','多');
create table ts_Type(
ts_TypeID int primary key identity(1,1),
ts_TypeName varchar(100) not null
);
insert into ts_Type values('奇幻');
insert into ts_Type values('爱情');
insert into ts_Type values('日常');
insert into ts_Type values('科普');
create table tushu(
ts_ID int primary key identity(1,1),
ts_Name varchar(100) not null,
ts_Price decimal(10,2) not null,
ts_TypeID int,
ts_Jieshao varchar(300)
);
insert into tushu values('《奥秘》',12,1,'好');
insert into tushu values('《爱你》',2,2,'good');
insert into tushu values('《诗书》',4,1,'棒');
insert into tushu values('《科普》',3,2,'强');
drop table yonghu, tushu,dingdanxiangqing,ts_Type
drop table tushu
select * from yonghu;
select * from tushu;
select * from ts_Type;
drop table dingdan
create table dingdan(
dingdan_ID int primary key identity(1,1),
yh_ID int,
dingdanxiangqing_ID int
)
insert into dingdan values(1,1);
insert into dingdan values(1,2);
insert into dingdan values(1,3);
insert into dingdan values(2,4);
insert into dingdan values(2,5);
insert into dingdan values(2,6);
insert into dingdan values(3,7);
create table dingdanxiangqing(
dingdanxiangqing_ID int primary key identity(1,1),
sp_ID int,
sp_num int
)
insert into dingdanxiangqing values(1,3);
insert into dingdanxiangqing values(2,4);
insert into dingdanxiangqing values(1,5);
insert into dingdanxiangqing values(3,5);
insert into dingdanxiangqing values(4,2);
insert into dingdanxiangqing values(5,1);
insert into dingdanxiangqing values(3,3);
insert into dingdanxiangqing values(4,3);
select * from yonghu;
select * from shangpin;
select * from sp_Type;
本篇框架:

package denglu;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
class shijian_zhuce implements ActionListener {
public static zhuCe chuangkouneirong2 = null;
public shijian_zhuce(zhuCe shangPinLeiXingXiaLaKuang1) {
this.chuangkouneirong2 = shangPinLeiXingXiaLaKuang1;
// chuangkouneirong窗口内容
}
@Override
public void actionPerformed(ActionEvent arg0) {
JOptionPane.showMessageDialog(null, "点击了注册按钮");
String String_uname = chuangkouneirong2.JTextField_uname.getText();// 得到用户名
String String_pwd = chuangkouneirong2.JPasswordField_pwd1.getText();// 得到密码
String String_pwd1 = chuangkouneirong2.JPasswordField_pwd2.getText();// 得到确认密码
String String_TureName = chuangkouneirong2.JTextField_name.getText();// 得到用户名
String String_age = chuangkouneirong2.JComboBox_age.getSelectedItem()
.toString();
// String String_age = zc.JTextField_age.getText();// 得到年龄
String String_sex = "男";
// 判断用户是否选择是女:
if (chuangkouneirong2.rb2.isSelected()) {
String_sex = "女";
}
String String_phone = chuangkouneirong2.JTextField_phone.getText();// 得到电话号码
// String String_address = zc.JTextField_address.getText();// 得到地址
ArrayList<String> jiHe = new ArrayList<String>();
// jiHe集合
if (chuangkouneirong2.address1.isSelected()) {
jiHe.add(chuangkouneirong2.address1.getText());
}
if (chuangkouneirong2.address2.isSelected()) {
jiHe.add(chuangkouneirong2.address2.getText());
}
if (chuangkouneirong2.address3.isSelected()) {
jiHe.add(chuangkouneirong2.address3.getText());
}
String String_address = " ";
for (int i = 0; i < jiHe.size(); i++) {
String_address += jiHe.get(i) + " ";// 将集合中的内容转换为字符串
}
String String_jieshao = chuangkouneirong2.JTextArea_jieshao.getText();// 得到介绍
String String_Q = chuangkouneirong2.JTextField_Q.getText();// 得到问题
String String_A = chuangkouneirong2.JTextField_A.getText();// 得到答案
// 判断两次输入的秘密是否一致:
if (!String_pwd.equals(String_pwd1)) {
JOptionPane.showMessageDialog(null, "两次密码输入不一致, 请重新输入");
return;
}
String sql_panduanuname = "select * from yonghu where yh_uname='"
+ String_uname + "'";
ResultSet res_select_uname = DBUtils.Select(sql_panduanuname);
try {
if (res_select_uname.next()) {
JOptionPane.showMessageDialog(null, "用户名已经存在了,请重新输入");
return;
}
} catch (SQLException e) {
e.printStackTrace();
}
String sql = "insert into yonghu(yh_uname,yh_pwd,yh_Name"
+ ",yh_age,yh_sex,yh_phone,yh_address"
+ ",yh_jieshao,yh_Q,yh_A,yh_type) values('" + String_uname
+ "','"
+ String_pwd + "','"
+ String_TureName + "'," + String_age + ",'" + String_sex
+ "','" + String_phone + "','" + String_address + "','"
+ String_jieshao + "','" + String_Q + "','" + String_A + "'"
+ ",'普通用户')";
if (DBUtils.ZSG(sql)) {
JOptionPane.showMessageDialog(null, "注册成功");
} else {
JOptionPane.showMessageDialog(null, "出现了未知的错误,请重试");
}
}
}
public class zhuCe extends JFrame {
// 爱好使用复选框来做
static JCheckBox address1, address2, address3 = null;
public static JButton JButton_zhuce = null;
// 使用下拉框来当年龄
static JComboBox JComboBox_age = null;
public static JPasswordField JPasswordField_pwd1,
JPasswordField_pwd2 = null;
// public static JTextArea jta_adress, jta_jieshao = null;
/* JTextArea类是一 个显示纯文本的多行(DuoHang)区域。 */
static JTextArea JTextArea_jieshao = null;
public static JTextField JTextField_uname, JTextField_name,
JTextField_phone, JTextField_jieshao, JTextField_Q,
JTextField_A = null;
public static JLabel lb_uname, lb_pwd, lb_qrpwd, lb_name, lb_age, lb_sex,
lb_phone, lb_address, lb_jieshao, lb_Q, lb_A = null;
// 性别使用JRadioButton来做
static JRadioButton rb1, rb2 = null;
public zhuCe() {
this.setLayout(null);
this.setSize(600, 700);
this.setTitle("注册界面(只有普通用户才要注册)");
this.setLocationRelativeTo(null);
lb_uname = new JLabel("用户名");
lb_pwd = new JLabel("用户密码");
lb_qrpwd = new JLabel("确认密码");
lb_name = new JLabel("真实姓名");
lb_age = new JLabel("年龄");
lb_sex = new JLabel("性别");
lb_phone = new JLabel("电话");
lb_address = new JLabel("地址");
lb_jieshao = new JLabel("介绍");
lb_Q = new JLabel("问题");
lb_A = new JLabel("答案");
lb_uname.setBounds(80, 100, 70, 30);
lb_pwd.setBounds(80, 140, 70, 30);
lb_qrpwd.setBounds(80, 180, 70, 30);
lb_name.setBounds(80, 220, 70, 30);
lb_age.setBounds(80, 260, 70, 30);
lb_sex.setBounds(80, 300, 70, 30);
lb_phone.setBounds(80, 340, 70, 30);
lb_address.setBounds(80, 380, 70, 30);
lb_jieshao.setBounds(80, 420, 70, 30);
lb_Q.setBounds(80, 460, 70, 30);
lb_A.setBounds(80, 500, 70, 30);
this.add(lb_uname);
this.add(lb_pwd);
this.add(lb_qrpwd);
this.add(lb_name);
this.add(lb_age);
this.add(lb_sex);
this.add(lb_phone);
this.add(lb_address);
this.add(lb_jieshao);
this.add(lb_Q);
this.add(lb_A);
JTextField_uname = new JTextField();
JPasswordField_pwd1 = new JPasswordField();
JPasswordField_pwd2 = new JPasswordField();
JTextField_name = new JTextField();
rb1 = new JRadioButton("男", true);
rb2 = new JRadioButton("女");
this.add(rb1);
this.add(rb2);
JComboBox_age = new JComboBox();
ButtonGroup bg = new ButtonGroup();
bg.add(rb1);
bg.add(rb2);
for (int i = 18; i < 60; i++) {
JComboBox_age.addItem(i);
}
this.add(JComboBox_age);
// JTextField_age = new JTextField();
// JTextField_sex = new JTextField();
JTextField_phone = new JTextField();
// JTextField_address = new JTextField();
address1 = new JCheckBox("中国", true);
address2 = new JCheckBox("日本");
address3 = new JCheckBox("美国");
JTextField_Q = new JTextField();
JTextField_A = new JTextField();
JTextArea_jieshao = new JTextArea();
JTextArea_jieshao.setColumns(8);
JTextArea_jieshao.setRows(4);
JTextArea_jieshao.setLineWrap(true);
this.add(JTextArea_jieshao);
JTextField_uname.setBounds(160, 100, 140, 30);
JPasswordField_pwd1.setBounds(160, 140, 140, 30);
JPasswordField_pwd2.setBounds(160, 180, 140, 30);
JTextField_name.setBounds(160, 220, 140, 30);
// JTextField_age.setBounds(160, 260, 140, 30);
JComboBox_age.setBounds(160, 260, 140, 30);
// JTextField_sex.setBounds(160, 300, 140, 30);
rb1.setBounds(160, 300, 40, 30);
rb2.setBounds(200, 300, 40, 30);
JTextField_phone.setBounds(160, 340, 140, 30);
// JTextField_address.setBounds(160, 380, 140, 30);
address1.setBounds(160, 380, 80, 30);
address2.setBounds(240, 380, 70, 30);
address3.setBounds(320, 380, 70, 30);
JTextArea_jieshao.setBounds(160, 420, 140, 40);
JTextField_Q.setBounds(160, 460, 140, 30);
JTextField_A.setBounds(160, 500, 140, 30);
this.setLocationRelativeTo(null);
this.add(JTextField_uname);
this.add(JPasswordField_pwd1);
this.add(JPasswordField_pwd2);
this.add(JTextField_name);
// this.add(JTextField_age);
// this.add(JTextField_sex);
this.add(JTextField_phone);
// this.add(JTextField_address);
this.add(JTextField_Q);
this.add(JTextField_A);
this.add(address1);
this.add(address2);
this.add(address3);
JButton_zhuce = new JButton("确认注册");
JButton_zhuce.addActionListener(new shijian_zhuce(this));
JButton_zhuce.setBounds(100, 580, 120, 30);
this.add(JButton_zhuce);
// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}

部分效果展示:

鼠标左键双击选中的那一行后:

鼠标右键:






