d_addbook.java
来自「图书管理系统」· Java 代码 · 共 214 行
JAVA
214 行
/*
* D_addbook.java
*
* Created on 2007年6月22日, 上午10:28
*/
package 图书管理系统;
import javax.swing.*;
import java.sql.*;
public class D_addbook extends javax.swing.JFrame {
/** Creates new form D_addbook */
public D_addbook() {
initComponents();
con=connect.getcon();
stmt=connect.getstmt();
this.setTitle("新书入库");
this.setBounds(300,250,400,350);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
T_BID = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
T_name = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
T_class = new javax.swing.JTextField();
T_press = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
T_author = new javax.swing.JTextField();
B_add = new javax.swing.JButton();
B_cancel = new javax.swing.JButton();
jLabel7 = new javax.swing.JLabel();
T_price = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(155, 155, 244));
jLabel1.setText("\u8bf7\u8f93\u5165\u60a8\u6240\u8981\u5f55\u5165\u7684\u56fe\u4e66\u4fe1\u606f:");
jLabel2.setText("\u4e66\u53f7:");
jLabel3.setText("\u4e66\u540d:");
jLabel4.setText("\u7c7b\u522b:");
jLabel5.setText("\u51fa\u7248\u793e:");
jLabel6.setText("\u4f5c\u8005:");
B_add.setText("\u5f55\u5165");
B_add.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
B_addActionPerformed(evt);
}
});
B_cancel.setText("\u53d6\u6d88");
B_cancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
B_cancelActionPerformed(evt);
}
});
jLabel7.setText("\u5b9a\u4ef7:");
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(60, 60, 60)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel2)
.add(jLabel3)
.add(jLabel6)
.add(jLabel4)
.add(jLabel5)
.add(jLabel7))
.add(39, 39, 39)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(T_press, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
.add(T_class, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
.add(T_author, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
.add(T_name, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
.add(T_BID, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
.add(layout.createSequentialGroup()
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(T_price, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))))
.add(layout.createSequentialGroup()
.add(B_add)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 37, Short.MAX_VALUE)
.add(B_cancel)
.add(9, 9, 9)))
.add(69, 69, 69))
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jLabel1)
.addContainerGap(128, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(9, 9, 9)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel2)
.add(T_BID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel3)
.add(T_name, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel6)
.add(T_author, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel4)
.add(T_class, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel5)
.add(T_press, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel7)
.add(T_price, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(30, 30, 30)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(B_add)
.add(B_cancel))
.add(39, 39, 39))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void B_cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_B_cancelActionPerformed
// TODO 将在此处添加您的处理代码:
this.setVisible(false);
}//GEN-LAST:event_B_cancelActionPerformed
private void B_addActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_B_addActionPerformed
// TODO 将在此处添加您的处理代码:
//书号,书名,类别,出版社,作者,定价 from 图书
try{
if(T_BID.getText().trim().equals("")||T_name.getText().trim().equals(""))
{
JOptionPane.showMessageDialog(null,"图书ID和图书名输入不能为空");
return;
}
double n=Double.parseDouble(T_price.getText().trim());
PreparedStatement sql=con.prepareStatement("insert into 图书 values (?,?,?,?,?,?)");
sql.setString(1,T_BID.getText().trim());
sql.setString(2,T_class.getText().trim());
sql.setString(3,T_press.getText().trim());
sql.setString(4,T_author.getText().trim());
sql.setString(5,T_name.getText().trim());
sql.setDouble(6,n);
sql.executeUpdate();
JOptionPane.showMessageDialog(null,"数据添加成功");
this.setVisible(false);
}
catch(Exception ee)
{
JOptionPane.showMessageDialog(null,"数据库访问失败,请确认图书号是否正确!");
ee.printStackTrace();
}
}//GEN-LAST:event_B_addActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new D_addbook().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton B_add;
private javax.swing.JButton B_cancel;
private javax.swing.JTextField T_BID;
private javax.swing.JTextField T_author;
private javax.swing.JTextField T_class;
private javax.swing.JTextField T_name;
private javax.swing.JTextField T_press;
private javax.swing.JTextField T_price;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
// End of variables declaration//GEN-END:variables
private Connection con;
private Statement stmt;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?