package frame;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javadao.BooksDao;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JSeparator;
import classes.Books;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.Date;
public class AddBooksFrame extends JFrame {
private JPanel contentPane;
private JTextField textbnumber;
private JTextField textbname2;
private JTextField textauthor;
private JTextField textpublish;
private JTextField textsum;
private JTextField textleft;
private JTextField texttime;
private JTextField textaddress;
private JTextField textbname1;
/**
* Launch the application.
*/
/*public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
AddBooksFrame frame = new AddBooksFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}*/
/**
* Create the frame.
*/
public AddBooksFrame() {
setTitle("\u56FE\u4E66\u4FE1\u606F\u7F16\u8F91");
setBounds(100, 100, 617, 498);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
setLocationRelativeTo(null); //窗体居中
JLabel label_1 = new JLabel("\u4E66\u53F7\uFF1A");
label_1.setFont(new Font("宋体", Font.BOLD, 18));
label_1.setBounds(171, 54, 62, 21);
contentPane.add(label_1);
textbnumber = new JTextField();
textbnumber.setEnabled(false);
textbnumber.setBounds(313, 51, 96, 27);
contentPane.add(textbnumber);
textbnumber.setColumns(10);
JLabel label_2 = new JLabel("\u4E66\u540D\uFF1A");
label_2.setFont(new Font("宋体", Font.BOLD, 18));
label_2.setBounds(171, 93, 59, 21);
contentPane.add(label_2);
textbname2 = new JTextField();
textbname2.setBounds(313, 87, 96, 27);
contentPane.add(textbname2);
textbname2.setColumns(10);
JLabel label_3 = new JLabel("\u4F5C\u8005\uFF1A");
label_3.setFont(new Font("宋体", Font.BOLD, 18));
label_3.setBounds(172, 123, 61, 21);
contentPane.add(label_3);
textauthor = new JTextField();
textauthor.setBounds(313, 120, 96, 27);
contentPane.add(textauthor);
textauthor.setColumns(10);
JLabel label_4 = new JLabel("\u51FA\u7248\u793E\uFF1A");
label_4.setFont(new Font("宋体", Font.BOLD, 18));
label_4.setBounds(173, 159, 81, 21);
contentPane.add(label_4);
textpublish = new JTextField();
textpublish.setBounds(313, 151, 96, 27);
contentPane.add(textpublish);
textpublish.setColumns(10);
JLabel label_5 = new JLabel("\u56FE\u4E66\u603B\u6570\uFF1A");
label_5.setFont(new Font("宋体", Font.BOLD, 18));
label_5.setBounds(173, 195, 95, 21);
contentPane.add(label_5);
JLabel label_6 = new JLabel("\u56FE\u4E66\u4F59\u91CF\uFF1A");
label_6.setFont(new Font("宋体", Font.BOLD, 18));
label_6.setBounds(173, 238, 96, 21);
contentPane.add(label_6);
JLabel label_7 = new JLabel("\u51FA\u7248\u65F6\u95F4\uFF1A");
label_7.setFont(new Font("宋体", Font.BOLD, 18));
label_7.setBounds(173, 274, 96, 21);
contentPane.add(label_7);
JLabel label_8 = new JLabel("\u56FE\u4E66\u5730\u5740\uFF1A");
label_8.setFont(new Font("宋体", Font.BOLD, 18));
label_8.setBounds(173, 310, 107, 21);
contentPane.add(label_8);
textsum = new JTextField();
textsum.setBounds(313, 193, 96, 27);
contentPane.add(textsum);
textsum.setColumns(10);
textleft = new JTextField();
textleft.setBounds(313, 235, 96, 27);
contentPane.add(textleft);
textleft.setColumns(10);
texttime = new JTextField();
texttime.setBounds(313, 271, 96, 27);
contentPane.add(texttime);
texttime.setColumns(10);
textaddress = new JTextField();
textaddress.setBounds(313, 307, 96, 27);
contentPane.add(textaddress);
textaddress.setColumns(10);
JButton buttonadd = new JButton("\u6DFB\u52A0");
buttonadd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
BooksDao bdao=new BooksDao();
Books b=new Books();
if(!textbname2.getText().trim().isEmpty()){
b.setBname(textbname2.getText());
b.setBauthor(textauthor.getText());
b.setBpublish(textpublish.getText());
int sum=Integer.parseInt(textsum.getText());
b.setBsum(sum);
int left=Integer.parseInt(textleft.getText());
b.setBleft(left);
Date time=java.sql.Date.valueOf(texttime.getText());
b.setBtime(time);
b.setBaddress(textaddress.getText());
if(bdao.findByname(textbname2.getText().trim())!=null){
JOptionPane.showMessageDialog(getContentPane(),"该书已存在");
}else if(bdao.doInsert(b)){
JOptionPane.showMessageDialog(getContentPane(),"添加成功!");
}else{
JOptionPane.showMessageDialog(getContentPane(),"添加失败");
}
}else{
JOptionPane.showMessageDialog(getContentPane(), "请输入添加内容");
}
}
});
buttonadd.setFont(new Font("宋体", Font.BOLD, 18));
buttonadd.setBounds(15, 374, 123, 29);
contentPane.add(buttonadd);
JButton btnupdate = new JButton("\u4FEE\u6539");
btnupdate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
BooksDao bdao=new BooksDao();
Books b=new Books();
if(!textbnumber.getText().trim().isEmpty()){
int number=Integer.parseInt(textbnumber.getText());
b.setBnumber(number);
b.setBname(textbname2.getText());
b.setBauthor(textauthor.getText());
b.setBpublish(textpublish.getText());
int sum=Integer.parseInt(textsum.getText());
b.setBsum(sum);
int left=Integer.parseInt(textleft.getText());
b.setBleft(left);
Date time=java.sql.Date.valueOf(texttime.getText());
b.setBtime(time);
b.setBaddress(textaddress.getText());
if(bdao.doUpdate(b)){
JOptionPane.showMessageDialog(getContentPane(),"修改成功");
}else{
JOptionPane.showMessageDialog(getContentPane(),"修改失败");
}
}
}
});
btnupdate.setFont(new Font("宋体", Font.BOLD, 18));
btnupdate.setBounds(157, 374, 123, 29);
contentPane.add(btnupdate);
JButton buttondelete = new JButton("\u5220\u9664");
buttondelete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
BooksDao bdao=new BooksDao();
Books b=new Books();
if(!textbnumber.getText().trim().isEmpty()){
int number=Integer.parseInt(textbnumber.getText());
b.setBnumber(number);
if(bdao.doDelete(b)){
JOptionPane.showMessageDialog(getContentPane(),"删除成功");
}else{
JOptionPane.showMessageDialog(getContentPane(),"删除失败");
}
}
}
});
buttondelete.setFont(new Font("宋体", Font.BOLD, 18));
buttondelete.setBounds(313, 374, 123, 29);
contentPane.add(buttondelete);
JSeparator separator = new JSeparator();
separator.setBounds(15, 43, 541, 303);
contentPane.add(separator);
JLabel label = new JLabel("\u4E66\u540D\uFF1A");
label.setFont(new Font("宋体", Font.BOLD, 18));
label.setBounds(37, 15, 81, 21);
contentPane.add(label);
textbname1 = new JTextField();
textbname1.setBounds(105, 9, 96, 27);
contentPane.add(textbname1);
textbname1.setColumns(10);
JButton buttonfind = new JButton("\u67E5\u8BE2");
buttonfind.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
BooksDao bdao=new BooksDao();
Books b=new Books();
if(!text
评论5