📄 d_addreader.java
字号:
/*
* D_addreader.java
*
* Created on 2007年6月22日, 上午11:01
*/
package 图书管理系统;
import javax.swing.*;
import java.sql.*;
public class D_addreader extends javax.swing.JFrame {
/** Creates new form D_addreader */
public D_addreader() {
initComponents();
con=connect.getcon();
stmt=connect.getstmt();
this.setTitle("添加读者");
this.setBounds(300,250,350,280);
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();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
T_RID = new javax.swing.JTextField();
T_rname = new javax.swing.JTextField();
T_unit = new javax.swing.JTextField();
T_sex = new javax.swing.JTextField();
B_Radd = new javax.swing.JButton();
B_Rcancel = new javax.swing.JButton();
jLabel6 = new javax.swing.JLabel();
T_tel = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("\u8bf7\u8f93\u5165\u60a8\u6240\u8981\u5f55\u5165\u7684\u8bfb\u8005\u4fe1\u606f:");
jLabel2.setText("\u7f16\u53f7:");
jLabel3.setText("\u59d3\u540d:");
jLabel4.setText("\u6027\u522b:");
jLabel5.setText("\u5355\u4f4d:");
B_Radd.setText("\u5f55\u5165");
B_Radd.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
B_RaddActionPerformed(evt);
}
});
B_Rcancel.setText("\u53d6\u6d88");
B_Rcancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
B_RcancelActionPerformed(evt);
}
});
jLabel6.setText("\u7535\u8bdd:");
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(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jLabel1))
.add(layout.createSequentialGroup()
.add(46, 46, 46)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel4)
.add(jLabel5)
.add(jLabel3)
.add(jLabel2)
.add(jLabel6))
.add(37, 37, 37)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(T_tel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.TRAILING, T_RID, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)
.add(T_rname, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)
.add(T_unit, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)
.add(T_sex, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE))))
.add(42, 42, 42)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(B_Radd)
.add(B_Rcancel))
.add(45, 45, 45))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(22, 22, 22)
.add(jLabel1)
.add(21, 21, 21)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel2)
.add(T_RID, 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(jLabel3)
.add(T_rname, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(B_Radd))
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel5)
.add(T_unit, 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(jLabel4)
.add(T_sex, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.add(layout.createSequentialGroup()
.add(22, 22, 22)
.add(B_Rcancel)))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel6)
.add(T_tel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap(61, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void B_RcancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_B_RcancelActionPerformed
// TODO 将在此处添加您的处理代码:
this.setVisible(false);
}//GEN-LAST:event_B_RcancelActionPerformed
private void B_RaddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_B_RaddActionPerformed
// TODO 将在此处添加您的处理代码:
try{
if(T_RID.getText().trim().equals("")||T_rname.getText().trim().equals(""))
{
JOptionPane.showMessageDialog(null,"读者编号和读者姓名输入不能为空");
return;
}
PreparedStatement sql=con.prepareStatement("insert into 读者 values (?,?,?,?,?,0)");
sql.setString(1,T_RID.getText().trim());
sql.setString(2,T_rname.getText().trim());
sql.setString(3,T_unit.getText().trim());
sql.setString(4,T_sex.getText().trim());
sql.setString(5,T_tel.getText().trim());
sql.executeUpdate();
JOptionPane.showMessageDialog(null,"数据添加成功");
this.setVisible(false);
}
catch(Exception ee)
{
JOptionPane.showMessageDialog(null,"数据库访问失败!");
ee.printStackTrace();
}
}//GEN-LAST:event_B_RaddActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new D_addreader().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton B_Radd;
private javax.swing.JButton B_Rcancel;
private javax.swing.JTextField T_RID;
private javax.swing.JTextField T_rname;
private javax.swing.JTextField T_sex;
private javax.swing.JTextField T_tel;
private javax.swing.JTextField T_unit;
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;
// End of variables declaration//GEN-END:variables
private Connection con;
private Statement stmt;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -