package com.feicui.frame;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.SimpleDateFormat;
import java.util.List;
import javax.swing.ButtonGroup;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableModel;
import com.feicui.Start;
import com.feicui.dao.Dao;
import com.feicui.entity.ReaderInfo;
import com.feicui.util.MyDocument;
public class ReaderInfoChangeFrame extends JInternalFrame{
private JTable table;
private JTextField readername;
private JRadioButton boy;
private ButtonGroup buttonGroup=new ButtonGroup();
private JRadioButton JRadioButton2;
private JTextField age;
private JTextField zy;
private JComboBox comboBox;
private String[] columnNames={ "读者名称", "读者性别", "读者年龄", "证件号码", "会员证有效日期",
"最大借书量", "电话","押金","证件","职业","读者编号","读者办证时间" };
private String[] array=new String[]{"身份证","军人证","学生证","工作证"};
private JTextField zjnumber;
private JFormattedTextField bztime;
private JTextField maxnumber;
private JFormattedTextField date;
private JFormattedTextField tel;
private JTextField keepmoney;
private JTextField ISBN;
public ReaderInfoChangeFrame() {
setIconifiable(true);
setClosable(true);
setTitle("读者信息修改与删除");
setBounds(100, 100, 600, 420);
final JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setPreferredSize(new Dimension(400, 80));
getContentPane().add(panel, BorderLayout.NORTH);
final JLabel logoLabel = new JLabel();
ImageIcon readerModiAndDelIcon=new ImageIcon(Start.class.getResource("/readerModiAndDel.jpg"));
logoLabel.setIcon(readerModiAndDelIcon);
logoLabel.setBackground(Color.CYAN);
logoLabel.setOpaque(true);
logoLabel.setPreferredSize(new Dimension(400, 80));
panel.add(logoLabel);
logoLabel.setText("读者信息修改logo(400*80)");
final JPanel panel_1 = new JPanel();
panel_1.setLayout(new BorderLayout());
getContentPane().add(panel_1);
final JScrollPane scrollPane = new JScrollPane();
scrollPane.setPreferredSize(new Dimension(0, 100));
panel_1.add(scrollPane, BorderLayout.NORTH);
final DefaultTableModel model=new DefaultTableModel();
String[][]contents=getContents();
table = new JTable(contents,columnNames);
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int selRow = table.getSelectedRow();
//id=table.getValueAt(selRow, 0).toString().trim();
readername.setText(table.getValueAt(selRow, 0).toString().trim());
if(table.getValueAt(selRow, 1).toString().trim().equals("男"))
boy.setSelected(true);
else
JRadioButton2.setSelected(true);
age.setText(table.getValueAt(selRow, 2).toString().trim());
zjnumber.setText(table.getValueAt(selRow, 3).toString().trim());
date.setText(table.getValueAt(selRow, 4).toString().trim());
maxnumber.setText(table.getValueAt(selRow, 5).toString().trim());
tel.setText(table.getValueAt(selRow, 6).toString().trim());
keepmoney.setText(table.getValueAt(selRow, 7).toString().trim());
comboBox.setSelectedItem(table.getValueAt(selRow, 8).toString().trim());
zy.setText(table.getValueAt(selRow, 9).toString().trim());
ISBN.setText(table.getValueAt(selRow, 10).toString().trim());
bztime.setText(table.getValueAt(selRow, 11).toString().trim());
}
});
scrollPane.setViewportView(table);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
final JPanel panel_2 = new JPanel();
final GridLayout gridLayout = new GridLayout(0, 4);
gridLayout.setVgap(9);
panel_2.setLayout(gridLayout);
panel_2.setPreferredSize(new Dimension(0, 200));
panel_1.add(panel_2, BorderLayout.SOUTH);
final JLabel label_1 = new JLabel();
label_1.setText(" 姓 名:");
panel_2.add(label_1);
readername = new JTextField();
readername.setDocument(new MyDocument(10));
panel_2.add(readername);
final JLabel label_2 = new JLabel();
label_2.setText(" 性 别:");
panel_2.add(label_2);
final JPanel panel_3 = new JPanel();
final FlowLayout flowLayout_1 = new FlowLayout();
flowLayout_1.setVgap(0);
panel_3.setLayout(flowLayout_1);
panel_2.add(panel_3);
boy = new JRadioButton();
boy.setSelected(true);
buttonGroup.add(boy);
panel_3.add(boy);
boy.setText("男");
JRadioButton2 = new JRadioButton();
buttonGroup.add(JRadioButton2);
panel_3.add(JRadioButton2);
JRadioButton2.setText("女");
final JLabel label_3 = new JLabel();
label_3.setText(" 年 龄:");
panel_2.add(label_3);
age = new JTextField();
age.setDocument(new MyDocument(2));
panel_2.add(age);
final JLabel label_5 = new JLabel();
label_5.setText(" 职 业:");
panel_2.add(label_5);
zy = new JTextField();
zy.setDocument(new MyDocument(30));
panel_2.add(zy);
final JLabel label = new JLabel();
label.setText(" 有效证件:");
panel_2.add(label);
comboBox = new JComboBox();
comboBox.setModel(new DefaultComboBoxModel(array));
for(int i=1;i<array.length;i++){
comboBox.setSelectedIndex(i);
comboBox.setSelectedItem(array);
}
panel_2.add(comboBox);
final JLabel label_6 = new JLabel();
label_6.setText(" 证件号码:");
panel_2.add(label_6);
zjnumber = new JTextField();
zjnumber.setDocument(new MyDocument(13));
panel_2.add(zjnumber);
final JLabel label_7 = new JLabel();
label_7.setText(" 办证日期:");
panel_2.add(label_7);
SimpleDateFormat myfmt=new SimpleDateFormat("yyyy-MM-dd");
bztime = new JFormattedTextField(myfmt.getDateInstance());
panel_2.add(bztime);
final JLabel label_9 = new JLabel();
label_9.setText(" 最大借书量:");
panel_2.add(label_9);
maxnumber = new JTextField();
panel_2.add(maxnumber);
final JLabel label_13 = new JLabel();
label_13.setText(" 会员证有效日期:");
panel_2.add(label_13);
date = new JFormattedTextField(myfmt.getDateInstance());
panel_2.add(date);
final JLabel label_8 = new JLabel();
label_8.setText(" 电 话:");
panel_2.add(label_8);
tel = new JFormattedTextField();
tel.setDocument(new MyDocument(11));
panel_2.add(tel);
final JLabel label_14 = new JLabel();
label_14.setText(" 押 金:");
panel_2.add(label_14);
keepmoney = new JTextField();
panel_2.add(keepmoney);
final JLabel label_4 = new JLabel();
label_4.setText(" 读者编号:");
panel_2.add(label_4);
ISBN = new JTextField();
ISBN.setEditable(false);
ISBN.setDocument(new MyDocument(13));
panel_2.add(ISBN);
final JPanel panel_4 = new JPanel();
panel_4.setMaximumSize(new Dimension(0, 0));
final FlowLayout flowLayout = new FlowLayout();
flowLayout.setVgap(0);
flowLayout.setHgap(4);
panel_4.setLayout(flowLayout);
panel_2.add(panel_4);
final JButton button = new JButton();
button.setHorizontalTextPosition(SwingConstants.CENTER);
panel_4.add(button);
button.setText("修改");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// 姓名为空 提示
String name=readername.getText().trim();
if (na