package reader;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.*;
import System_set.dbhelp;
public class reader extends JFrame {
public JLabel name, age, provename, borrowmax, telephone, provedate, sex,
job, proveid, effectivedate, pledge, readerid;
public JTextField name_text, age_text, borrowmax_text, telephone_text,
provedate_text, job_text, proveid_text, effectivedate_text,
pledge_text, readerid_text;
public Choice prove;
public JRadioButton male, female;
public JButton button1, button2;
ButtonGroup fm;
JFrame f;
public reader() {
f = new JFrame();
f.setSize(640, 310);
f.setVisible(true);
f.setResizable(false);
f.setLayout(null);
// 背景图片设置
ImageIcon background = new ImageIcon("images/addreader.png");
JLabel image = new JLabel(background);
image.setBounds(0, 0, background.getIconWidth(),
background.getIconHeight());
f.add(image);
// name
name = new JLabel("姓 名:");
name.setBounds(15, 60, 100, 20);
f.add(name);
name_text = new JTextField(15);
name_text.setText("张琪");
name_text.setBounds(160, 60, 150, 20);
f.add(name_text);
// age
age = new JLabel("年 龄:");
age.setBounds(15, 90, 100, 20);
f.add(age);
age_text = new JTextField(15);
age_text.setText("20");
age_text.setBounds(160, 90, 150, 20);
f.add(age_text);
// 有效证件
provename = new JLabel("有 效 证 件:");
provename.setBounds(15, 120, 100, 20);
f.add(provename);
prove = new Choice();
prove.add("工作证");
prove.add("学生证");
prove.add("身份证");
prove.add("教师证");
prove.setBounds(160, 120, 150, 20);
f.add(prove);
// 最大借书量
borrowmax = new JLabel("最 大 借 书 量:");
borrowmax.setBounds(15, 150, 100, 20);
f.add(borrowmax);
borrowmax_text = new JTextField(15);
borrowmax_text.setText("8");
borrowmax_text.setBounds(160, 150, 150, 20);
f.add(borrowmax_text);
// 电话
telephone = new JLabel("电 话:");
telephone.setBounds(15, 180, 100, 20);
f.add(telephone);
telephone_text = new JTextField(15);
telephone_text.setText("13564595124");
telephone_text.setBounds(160, 180, 150, 20);
f.add(telephone_text);
// 办证日期
provedate = new JLabel("办 证 日 期:");
provedate.setBounds(15, 210, 100, 20);
f.add(provedate);
provedate_text = new JTextField(15);
provedate_text.setText("2012-10-21");
provedate_text.setBounds(160, 210, 150, 20);
f.add(provedate_text);
// sex
sex = new JLabel("性 别:");
sex.setBounds(320, 60, 100, 20);
f.add(sex);
fm = new ButtonGroup();
male = new JRadioButton("男", true);
female = new JRadioButton("女");
male.setBounds(480, 60, 50, 20);
female.setBounds(540, 60, 50, 20);
fm.add(male);
fm.add(female);
f.add(male);
f.add(female);
// job
job = new JLabel("职 业:");
job.setBounds(320, 90, 100, 20);
f.add(job);
job_text = new JTextField(15);
job_text.setText("学生");
job_text.setBounds(465, 90, 150, 20);
f.add(job_text);
// 证件号码
proveid = new JLabel("证 件 号 码:");
proveid.setBounds(320, 120, 100, 20);
f.add(proveid);
proveid_text = new JTextField(15);
proveid_text.setText("1234567894561");
proveid_text.setBounds(465, 120, 150, 20);
f.add(proveid_text);
// 会员证有效日期
effectivedate = new JLabel("会员证有效日期:");
effectivedate.setBounds(320, 150, 110, 20);
f.add(effectivedate);
effectivedate_text = new JTextField(15);
effectivedate_text.setText("2013-10-21");
effectivedate_text.setBounds(465, 150, 150, 20);
f.add(effectivedate_text);
// 押金
pledge = new JLabel("押 金:");
pledge.setBounds(320, 180, 100, 20);
f.add(pledge);
pledge_text = new JTextField(15);
pledge_text.setText("20");
pledge_text.setBounds(465, 180, 150, 20);
f.add(pledge_text);
// 读者编码
readerid = new JLabel("读 者 编 码:");
readerid.setBounds(320, 210, 100, 20);
f.add(readerid);
readerid_text = new JTextField(15);
readerid_text.setText("123456779625");
readerid_text.setBounds(465, 210, 150, 20);
f.add(readerid_text);
// 按钮
button1 = new JButton("保存");
button1.setBounds(250, 240, 60, 20);
f.add(button1);
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DefaultButtonModel model = (DefaultButtonModel) male.getModel();
String sexselect = null;
if (model.getGroup().isSelected(model))
sexselect = male.getText();
else
sexselect = female.getText();
System.out.print(sexselect);
String sql = "insert into reader values "
+ "('"
+ readerid_text.getText()
+ "','"
+ name_text.getText()
+ "','"
+ sexselect
+ "','"
+ age_text.getText()
+ "','"
+ job_text.getText()
+ "','"
+ prove.getSelectedItem()
+ "''"
+ proveid_text.getText()
+ "','"
+ telephone_text.getText()
+ "','"
+ borrowmax_text.getText()
+ "','"
+ effectivedate_text.getText()
+ "','"
+ provedate_text.getText()
+ "','"
+ pledge_text.getText() + "')";
try {
Statement pstm = dbhelp.xianjie().createStatement();
pstm.executeUpdate(sql);
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
button2 = new JButton("取消");
button2.setBounds(320, 240, 60, 20);
f.add(button2);
button1.setText("保存");
f.setTitle("读者相关信息添加");
System.out.print( pledge_text.getText().getClass());
}
public static void main(String[] args) {
new reader();
}
}