图书管理系统读者信息添加界面和功能
package com.zhibang.view;import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.zhibang.utils.JdbcUtils;
import com.zhibang.utils.StringUtils;
import java.awt.Toolkit;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import java.awt.Font;
import java.awt.Color;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.sql.*;
import java.awt.event.ActionEvent;
import javax.swing.JToolBar;
/**
* @title
* @author
* @date 2020-8-4 14:31:37
*/
public class ReaderAdd extends JFrame {
static String readname;
static String readsex;
static String readage;
static String readocc;
static String readsexid;
static String readidtype;
static String idnumber;
static String telnumber;
static String guaranteedeposit;
static String regdate;
static String readid;
private String readerid;
static java.sql.Connection con;
static Statement stmt;
static ResultSet res;
protected static final String
Intgeter = null;
private JPanel contentPane;
private JTextField textName;
private JTextField textAge;
private JTextField textIphone;
private JTextField textActionTime;
private JTextField textReadId;
private JTextField textMoney;
private JTextField textIdCard;
private JTextField textOccu;
private final ButtonGroup
buttonGroup = new ButtonGroup();
private PreparedStatement ps;
protected String reader_age;
/**
* Launch the application.
*/
public static void main(String[]
args) {
EventQueue.invokeLater(new
Runnable() {
public void run()
{
try {
ReaderAdd frame = new ReaderAdd();
frame.setVisible(true);
} catch
(Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public ReaderAdd() {
try {
JdbcUtils.getConnection();
con =
DriverManager.getConnection
("jdbc:mysql://localhost:3306/db_book",
"root", "root");
} catch (SQLException e) {
// TODO Auto-
generated catch block
e.printStackTrace
();
}
setTitle("读者信息添加");
setIconImage
(Toolkit.getDefaultToolkit()
.getImage
(ReaderAdd.class.getResource
("/image/read_16px.png")));
setDefaultCloseOperation
(1);
setBounds(100, 100, 507,
460);
contentPane = new JPanel
();
contentPane.setBorder(new
EmptyBorder(5, 5, 5, 5));
setContentPane
(contentPane);
contentPane.setLayout
(null);
JLabel lblNewLabel = new
JLabel("");
lblNewLabel.setIcon(new
ImageIcon(ReaderAdd.class.getResource
("/image/readerAdd.jpg")));
lblNewLabel.setBounds(0,
0, 491, 60);
contentPane.add
(lblNewLabel);
JLabel label = new JLabel
("姓名:");
label.setHorizontalAlignment
(SwingConstants.CENTER);
label.setBounds(10, 89,
60, 29);
contentPane.add(label);
textName = new JTextField
();
textName.setColumns(10);
textName.setBounds(90, 89,
134, 29);
contentPane.add(textName);
JLabel label_1 = new
JLabel("年龄:");
label_1.setHorizontalAlignment
(SwingConstants.CENTER);
label_1.setBounds(10, 146,
60, 29);
contentPane.add(label_1);
textAge = new JTextField
();
textAge.setColumns(10);
textAge.setBounds(90, 146,
134, 29);
contentPane.add(textAge);
JLabel label_2 = new
JLabel("有效证件:");
label_2.setHorizontalAlignment
(SwingConstants.CENTER);
label_2.setFont(new Font("
宋体", Font.PLAIN, 12));
label_2.setBounds(10, 203,
60, 29);
contentPane.add(label_2);
JLabel label_3 = new
JLabel("电话:");
label_3.setHorizontalAlignment
(SwingConstants.CENTER);
label_3.setBounds(10, 253,
60, 29);
contentPane.add(label_3);
textIphone = new
JTextField();
textIphone.setColumns(10);
textIphone.setBounds(90,
253, 134, 29);
contentPane.add
(textIphone);
JLabel label_4 = new
JLabel("注册日期:");
label_4.setHorizontalAlignment
(SwingConstants.CENTER);
label_4.setFont(new Font("
宋体", Font.PLAIN, 12));
label_4.setBounds(10, 305,
60, 29);
contentPane.add(label_4);
textActionTime = new
JTextField();
textActionTime.setEditable(false);
textActionTime.setText
(String.valueOf(new java.sql.Date(new
java.util.Date().getTime())));
textActionTime.setHorizontalAlignment
(SwingConstants.CENTER);
textActionTime.setForeground(Color.BLACK);
textActionTime.setColumns
(10);
textActionTime.setBounds
(90, 305, 134, 29);
contentPane.add
(textActionTime);
textReadId = new
JTextField();
textReadId.setColumns(10);
textReadId.setBounds(315,
305, 134, 29);
contentPane.add
(textReadId);
textMoney = new
JTextField();
textMoney.setColumns(10);
textMoney.setBounds(315,
253, 134, 29);
contentPane.add
(textMoney);
textIdCard = new
JTextField();
textIdCard.setColumns(10);
textIdCard.setBounds(315,
203, 134, 29);
contentPane.add
(textIdCard);
JLabel label_5 = new
JLabel("证件号码:");
label_5.setHorizontalAlignment
(SwingConstants.CENTER);
label_5.setBounds(238,
203, 67, 29);
contentPane.add(label_5);
JLabel label_6 = new
JLabel("押金:");
label_6.setHorizontalAlignment
(SwingConstants.CENTER);
label_6.setBounds(258,
253, 60, 29);
contentPane.add(label_6);
JLabel label_7 = new
JLabel("读者编号:");
label_7.setHorizontalAlignment
(SwingConstants.CENTER);
label_7.setFont(new Font("
宋体", Font.PLAIN, 12));
label_7.setBounds(245,
304, 60, 29);
contentPane.add(label_7);
JLabel label_8 = new
JLabel("职业:");
label_8.setHorizontalAlignment
(SwingConstants.CENTER);
label_8.setBounds(245,
146, 60, 29);
contentPane.add(label_8);
JLabel label_9 = new
JLabel("性别:");
label_9.setHorizontalAlignment
(SwingConstants.CENTER);
label_9.setBounds(245, 89,
60, 29);
contentPane.add(label_9);
JRadioButton sexm = new
JRadioButton("男");
sexm.setSelected(true);
buttonGroup.add(sexm);
sexm.setHorizontalAlignment
(SwingConstants.CENTER);
sexm.setBounds(313, 92,
48, 23);
contentPane.add(sexm);
JRadioButton sexw = new
JRadioButton("女");
buttonGroup.add(sexw);
sexw.setHorizontalAlignment
(SwingConstants.CENTER);
sexw.setBounds(401, 92,
48, 23);
contentPane.add(sexw);
textOccu = new JTextField
();
textOccu.setColumns(10);
textOccu.setBounds(315,
146, 134, 29);
contentPane.add(textOccu);
JComboBox comboBox = new
JComboBox();
comboBox.setModel(new
DefaultComboBoxModel(new String[] { "身份
证", "学生证", "教师证" }));
comboBox.setBounds(90,
205, 134, 29);
contentPane.add(comboBox);
JButton btnNewButton = new
JButton("保存");
btnNewButton.addActionListener(new
ActionListener() {
public void
actionPerformed(ActionEvent arg0) {
//
添加功能
readname =
textName.getText();
readsex = sexm.isSelected
()?"男":"女";
if (readsex.equals("男"))
{
readsexid = "1";//1男
}else {
readsexid = "2";//2女
}
//
"身份证", "学生证", "教师证", "演
员"
if
(comboBox.getSelectedItem() == "身份证") {
readidtype = "0";
}
if
(comboBox.getSelectedItem() == "学生证") {
readidtype = "1";
}
if
(comboBox.getSelectedItem() == "教师证") {
readidtype = "2";
}
if
(comboBox.getSelectedItem() == "演员") {
readidtype = "3";
}
reader_age =
textAge.getText();
idnumber =
textIdCard.getText();
telnumber =
textIphone.getText();
guaranteedeposit =
textMoney.getText();
readerid =
textReadId.getText();
readocc =
textOccu.getText();
regdate =
textActionTime.getText();
if (StringUtils.isEmpty
(readname)) {
JOptionPane.showMessageDialog(null, "姓名
不能为空");
return;
}
if (StringUtils.isEmpty
(reader_age)) {
JOptionPane.showMessageDialog(null, "年龄
不能为空");
return;
}
if (StringUtils.isEmpty
(readocc)) {
JOptionPane.showMessageDialog(null, "职业
不能为空");
return;
}
if (StringUtils.isEmpty
(idnumber)) {
JOptionPane.showMessageDialog(null, "证件
号码不能为空");
return;
}
if (StringUtils.isEmpty
(telnumber)) {
JOptionPane.showMessageDialog(null, "电话
号码不能为空");
return;
}
if (StringUtils.isEmpty
(guaranteedeposit)) {
JOptionPane.showMessageDialog(null, "押金
不能为空");
return;
}
if (StringUtils.isEmpty
(readerid)) {
JOptionPane.showMessageDialog(null, "读者
编号不能为空");
return;
}
try {
java.sql.Connection con =
JdbcUtils.getConnection();
String xgai = "INSERT INTO `t_reader`" +
"VALUES('"+readerid
+"','"+readname+"','"+readsexid
+"','"+reader_age+"','"+readocc
+"','"+readidtype+"','"+idnumber
+"','"+telnumber+"','"+guaranteedeposit
+"','"+regdate+"');";
stmt = con.createStatement();
int i =
stmt.executeUpdate(xgai);
if (i > 0) {
JOptionPane.showMessageDialog(null, "添加
成功!");
dispose();
}
textName.setText("");
textAge.setText("");
textOccu.setText("");
textIdCard.setText("");
textIphone.setText("");
textMoney.setText("");
textActionTime.setText("");
textReadId.setText("");
} catch
(SQLException e) {
e.printStackTrace();
} finally
{
JdbcUtils.close(null,stmt,null,con);
}
}
});
btnNewButton.setIcon(new
ImageIcon(ReaderAdd.class.getResource
("/image/save_button_16px.png")));
btnNewButton.setBounds
(113, 373, 93, 29);
contentPane.add
(btnNewButton);
JButton button = new
JButton("返回");
button.addActionListener
(new ActionListener() {
public void
actionPerformed(ActionEvent arg0) {
dispose();
}
});
button.setIcon(new
ImageIcon(ReaderAdd.class.getResource
("/image/return_button16px.png")));
button.setBounds(315, 373,
93, 29);
contentPane.add(button);
this.setLocationRelativeTo(null);// 居中显
示
}
}
好歹排下版吧。。javaGUI现在确实用的少了 瞄帕斯 发表于 2020-8-7 14:26
好歹排下版吧。。javaGUI现在确实用的少了
知道了,抱歉哈 java还没开始学
页:
[1]