📄 modifybookinfo.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package libsystem;/** * * @author admin */import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.sql.*;public class ModifyBookInfo extends JFrame{ String strurl; Connection conn; Statement stmt; ResultSet rs; private JPanel ContentPane; private JLabel lbookid = new JLabel(); private JLabel ltips = new JLabel(); private JTextField bookid = new JTextField(); private JButton commit = new JButton(); private JLabel lbookid2 = new JLabel(); private JLabel lbookname = new JLabel(); private JLabel lisout = new JLabel(); private JLabel lpubdate = new JLabel(); private JLabel ltype = new JLabel(); private JLabel lauthor= new JLabel(); private JLabel lfaculty = new JLabel(); private JLabel lpublic = new JLabel(); private JLabel lremark = new JLabel(); private JTextField bookid2 = new JTextField(); private JTextField bookname = new JTextField(); private JTextField pubdate = new JTextField(); private JTextField author = new JTextField(); private JTextField publics = new JTextField(); private JComboBox isout = new JComboBox(); private JComboBox type = new JComboBox(); private JComboBox faculty = new JComboBox(); private JTextArea remark = new JTextArea(); private JButton modifybut = new JButton(); public ModifyBookInfo() { ContentPane = (JPanel)this.getContentPane(); ContentPane.setLayout(null); this.setTitle("图书信息修改"); this.setBounds(320,160,400,350); ContentPane.setBackground(Color.black); ltips.setText("输入要修改的书号"); ltips.setFont(new Font("Dialog", 1, 20)); ltips.setForeground(Color.white); ltips.setVisible(true); ltips.setBounds(new Rectangle(115, 60, 200, 30)); lbookid.setText("书号"); lbookid.setVisible(true); lbookid.setForeground(Color.white); lbookid.setBounds(new Rectangle(124, 130, 178, 24)); bookid.setText(""); bookid.setBounds(new Rectangle(178, 127, 83, 22)); bookid.setVisible(true); commit.setText("下一步"); commit.setVisible(true); commit.setBounds(new Rectangle(178, 177, 73, 22)); commit.addActionListener(new button_actionPerformed()); //显示详细信息 lbookid2.setText("书号"); lbookid2.setVisible(false); lbookid2.setBounds(new Rectangle(30, 11, 51, 33)); lbookid2.setForeground(Color.white); lbookname.setText("书名"); lbookname.setVisible(false); lbookname.setBounds(new Rectangle(162, 11, 28, 33)); lbookname.setForeground(Color.white); lisout.setText("借出"); lisout.setVisible(false); lisout.setBounds(new Rectangle(241, 11, 28, 33)); lisout.setForeground(Color.white); lpubdate.setText("出版日期"); lpubdate.setVisible(false); lpubdate.setBounds(new Rectangle(31, 53, 55, 33)); lpubdate.setForeground(Color.white); ltype.setText("图书分类"); ltype.setVisible(false); ltype.setBounds(new Rectangle(241, 53, 55, 33)); ltype.setForeground(Color.white); lauthor.setText("作者"); lauthor.setVisible(false); lauthor.setBounds(new Rectangle(163, 53, 26, 33)); lauthor.setForeground(Color.white); lfaculty.setText("系 别"); lfaculty.setVisible(false); lfaculty.setBounds(new Rectangle(30, 94, 50, 33)); lfaculty.setForeground(Color.white); lpublic.setText("出版社"); lpublic.setVisible(false); lpublic.setBounds(new Rectangle(163, 94, 66, 33)); lpublic.setForeground(Color.white); lremark.setText("备 注"); lremark.setVisible(false); lremark.setBounds(new Rectangle(30, 132, 50, 33)); lremark.setForeground(Color.white); modifybut.setText("修改"); modifybut.setVisible(true); modifybut.setBounds(new Rectangle(153, 242, 94, 22)); modifybut.addActionListener(new button_actionPerformed()); modifybut.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { dispose(); } }); //关闭当前窗 bookid2.setText("");//书号 bookid2.setVisible(false); bookid2.setBounds(new Rectangle(86, 16, 74, 22)); bookname.setText("");//书名 bookname.setVisible(false); bookname.setBounds(new Rectangle(192, 16, 44, 22)); pubdate.setText("");//出版日期 pubdate.setVisible(false); pubdate.setBounds(new Rectangle(86, 58, 74, 22)); author.setText("");//作者 author.setVisible(false); author.setBounds(new Rectangle(191, 58, 44, 22)); publics.setText("");//出版社 publics.setVisible(false); publics.setBounds(new Rectangle(210, 99, 158, 22)); isout.setBounds(new Rectangle(275, 15, 50, 25)); isout.setVisible(false); isout.addItem("否"); isout.addItem("是"); isout.setForeground(Color.black); isout.setBackground(Color.white); type.setBounds(new Rectangle(296, 57, 72, 25)); type.setVisible(false); type.addItem("科技"); type.addItem("文学"); type.addItem("其他"); type.setForeground(Color.black); type.setBackground(Color.white); faculty.setBounds(new Rectangle(86, 98, 75, 25)); faculty.setVisible(false); faculty.addItem("信息系"); faculty.addItem("经济系"); faculty.addItem("机电系"); faculty.addItem("管理系"); faculty.addItem("旅游系"); faculty.addItem("外语系"); faculty.setForeground(Color.black); faculty.setBackground(Color.white); remark.setText(""); remark.setVisible(false);//初始先不显示,第二步才显示 remark.setBounds(new Rectangle(84, 139, 285, 92)); ContentPane.add(lbookid); ContentPane.add(ltips); ContentPane.add(bookid); ContentPane.add(commit); // ContentPane.add(lbookid2); ContentPane.add(lbookname); ContentPane.add(lisout); ContentPane.add(lpubdate); ContentPane.add(ltype); ContentPane.add(lauthor); ContentPane.add(lfaculty); ContentPane.add(lpublic); ContentPane.add(lremark); ContentPane.add(bookid2); ContentPane.add(bookname); ContentPane.add(pubdate); ContentPane.add(author); ContentPane.add(publics); ContentPane.add(isout); ContentPane.add(type); ContentPane.add(faculty); ContentPane.add(remark); ContentPane.add(modifybut); this.setVisible(true); } class button_actionPerformed implements ActionListener { public void actionPerformed(ActionEvent e) { try { Statement stmt = ConnDataBase.getConnection().createStatement(); if(e.getSource()==commit) { rs = stmt.executeQuery("select * from Book where 书号 = '"+bookid.getText()+"'"); if(rs.next()) { lbookid.setVisible(false); commit.setVisible(false); ltips.setVisible(false); bookid.setVisible(false); //--------------------显示以下标签------------ lbookid2.setVisible(true);//书号 lbookname.setVisible(true);//书名 lisout.setVisible(true);//借出 lpubdate.setVisible(true);//出版日期 ltype.setVisible(true);//图书分类 lauthor.setVisible(true);//作者 lfaculty.setVisible(true);//系别 lpublic.setVisible(true);//出版社 lremark.setVisible(true);//备注 /*****从各个控件中得到查询的相应结果*****/ bookid2.setVisible(true);//书号 bookid2.setText(rs.getString("书号")); bookid2.setEditable(false); faculty.setVisible(true);//系别 faculty.setSelectedItem(rs.getString("系别")); publics.setVisible(true);//出版社 publics.setText(rs.getString("出版社")); bookname.setVisible(true);//书名 bookname.setText(rs.getString("书名")); isout.setVisible(true);//借出 isout.setSelectedItem(rs.getString("借出")); isout.getSelectedItem(); pubdate.setVisible(true);//出版日期 pubdate.setText((rs.getString("出版日期")).substring(0,10)); author.setVisible(true);//作者 author.setText(rs.getString("作者")); type.setVisible(true);//图书分类 type.setSelectedItem(rs.getString("图书分类")); remark.setVisible(true); remark.setText(rs.getString("备注")); //有TEXT类型,要按先后顺序读取 modifybut.setVisible(true); } else JOptionPane.showMessageDialog(null, "无此书号对应信息", "警告", JOptionPane.WARNING_MESSAGE); } else if(e.getSource()==modifybut) { try { stmt.executeUpdate("delete from Book where 书号 = '"+bookid.getText()+"'"); stmt.executeUpdate("insert into Book(书号,系别,出版社,书名,借出,出版日期,作者,图书分类,备注) values ('"+bookid2.getText()+"','"+faculty.getSelectedItem()+"','"+publics.getText()+"','"+bookname.getText()+"','"+isout.getSelectedItem()+"','"+pubdate.getText()+"','"+author.getText()+"','"+type.getSelectedItem()+"','"+remark.getText()+"') "); JOptionPane.showMessageDialog(null, "修改信息成功!"); BrBookinfo allinfo = new BrBookinfo(); } catch(Exception ee) { JOptionPane.showMessageDialog(null, "请认真检查各项(不能为空),\n日期要合法!然后重试.", "异常警告", JOptionPane.WARNING_MESSAGE); ee.printStackTrace(); } } } catch(Exception ee) { ee.printStackTrace(); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -