📄 4.借书界面.txt
字号:
package library;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import javax.swing.JTextArea;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JPasswordField;
public class Frame4 extends JFrame
{
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
JButton jButton1 = new JButton();
JLabel jLabel2 = new JLabel();
JTextField jTextField2 = new JTextField();
JTextArea jTextArea1 = new JTextArea();
Connection conn;
JLabel jLabel1 = new JLabel();
JTextField jTextField1 = new JTextField();
JScrollPane jScrollPane1 = new JScrollPane();
JLabel jLabel3 = new JLabel();
JPasswordField jPasswordField1 = new JPasswordField();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JLabel jLabel7 = new JLabel();
JTextField jTextField3 = new JTextField();
JTextField jTextField4 = new JTextField();
JTextField jTextField5 = new JTextField();
JTextField jTextField6 = new JTextField();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
JButton jButton4 = new JButton();
JButton jButton5 = new JButton();
JButton jButton6 = new JButton();
JLabel jLabel8 = new JLabel();
public Frame4()
{
try
{
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
jbInit();
}
catch (Exception exception)
{
exception.printStackTrace();
}
}
private void jbInit() throws Exception
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String connURL ="jdbc:odbc:library";
String user = "sa";
String pw = "123";
conn=DriverManager.getConnection(connURL,user,pw);
}
catch(Exception e)
{
System.out.println("class no found can not connect to sql server"+e);
}
contentPane = (JPanel) getContentPane();
contentPane.setLayout(xYLayout1);
setSize(new Dimension(570, 400));
setTitle("借阅书籍");
jButton1.setText("确定");
jButton1.addActionListener(new Frame4_jButton1_actionAdapter(this));
jLabel2.setText("借书(1)");
jLabel1.setText("ID");
jLabel3.setText("密码");
jLabel4.setText("借书(2)");
jLabel5.setText("借书(3)");
jLabel6.setText("借书(4)");
jLabel7.setText("借书(5)");
jTextField6.setToolTipText("");
jButton2.setText("确定");
jButton2.addActionListener(new Frame4_jButton2_actionAdapter(this));
jButton3.setText("确定");
jButton3.addActionListener(new Frame4_jButton3_actionAdapter(this));
jButton5.setText("确定");
jButton5.addActionListener(new Frame4_jButton5_actionAdapter(this));
jButton4.setText("确定");
jButton4.addActionListener(new Frame4_jButton4_actionAdapter(this));
jButton6.setText("清除显示");
jButton6.addActionListener(new Frame4_jButton6_actionAdapter(this));
jLabel8.setText("请从上至下输入所借的书籍编号");
contentPane.add(jLabel1, new XYConstraints(13, 22, -1, -1));
contentPane.add(jLabel3, new XYConstraints(10, 58, -1, -1));
contentPane.add(jScrollPane1, new XYConstraints(290, 18, 234, 227));
jScrollPane1.getViewport().add(jTextArea1);
contentPane.add(jTextField6, new XYConstraints(71, 258, 117, 27));
contentPane.add(jLabel7, new XYConstraints(3, 267, -1, -1));
contentPane.add(jTextField5, new XYConstraints(70, 224, 118, 26));
contentPane.add(jLabel6, new XYConstraints(2, 233, -1, -1));
contentPane.add(jTextField4, new XYConstraints(70, 189, 118, 26));
contentPane.add(jLabel5, new XYConstraints(3, 199, -1, -1));
contentPane.add(jTextField2, new XYConstraints(70, 118, 118, 27));
contentPane.add(jLabel2, new XYConstraints(6, 126, -1, -1));
contentPane.add(jTextField1, new XYConstraints(70, 19, 199, 23));
contentPane.add(jPasswordField1, new XYConstraints(70, 55, 199, 23));
contentPane.add(jTextField3, new XYConstraints(71, 154, 118, 28));
contentPane.add(jLabel4, new XYConstraints(4, 160, -1, -1));
contentPane.add(jButton6, new XYConstraints(340, 253, 118, 27));
contentPane.add(jButton1, new XYConstraints(212, 115, 62, 31));
contentPane.add(jButton2, new XYConstraints(211, 153, 65, 29));
contentPane.add(jButton3, new XYConstraints(211, 188, 64, 27));
contentPane.add(jButton4, new XYConstraints(210, 222, 65, 26));
contentPane.add(jLabel8, new XYConstraints(87, 79, 230, 28));
contentPane.add(jButton5, new XYConstraints(211, 256, 66, 28));
}
public void jButton1_actionPerformed(ActionEvent e)
{
F4_1();
}
void F4_1()
{
try
{
String str4_1_1,str4_1_2;
str4_1_1=jTextField1.getText();
str4_1_2=new String(jPasswordField1.getPassword());
Statement stmt4_1_1 = conn.createStatement(ResultSet.
TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sq4_1_l= "select * from reader where ID='"+str4_1_1+"' AND 密码 = '"+str4_1_2+"' ";
ResultSet rs4_1_1 = stmt4_1_1.executeQuery(sq4_1_l);
if(!rs4_1_1.next())
{
JOptionPane.showMessageDialog(this,"帐号或者密码错误","错误",JOptionPane.ERROR_MESSAGE);
}
else
{
try
{
String str4_1_3;
str4_1_3=jTextField2.getText();
Statement stmt4_1_2 = conn.createStatement(ResultSet.
TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sq4_1_2 = "select * from book where 编号 = '"+str4_1_3+"'";
ResultSet rs4_1_2 = stmt4_1_2.executeQuery(sq4_1_2);
if(!rs4_1_2.next())
{
JOptionPane.showMessageDialog(this,"书籍编号错误","错误",JOptionPane.ERROR_MESSAGE);
}
else{
Statement stmt4_1_3 = conn.createStatement( ResultSet.
TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sq4_1_3 ="select 借阅情况 from book where 编号 = '"+str4_1_3+"'";
ResultSet rs4_1_3 = stmt4_1_3.executeQuery(sq4_1_3);
String a = new String("未借");
if ((rs4_1_3.next()) &&!rs4_1_3.getString("借阅情况").equals(a))
{
JOptionPane.showMessageDialog(this, "此书已借被借阅",
"错误", JOptionPane.ERROR_MESSAGE);
}
else
{
Statement stmt11611 = conn.createStatement(ResultSet.
TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sq4_1_4 ="select 已借书籍 from reader where ID = '"+str4_1_1+"'";
ResultSet rs4_1_4 = stmt11611.executeQuery(sq4_1_4);
String b = new String("未借");
if(rs4_1_4.next()&&!rs4_1_4.getString("已借书籍").equals(b))
{
JOptionPane.showMessageDialog(this, "此借书位已经不能借书,请尝试其他借书位",
"错误", JOptionPane.ERROR_MESSAGE);
}
else
{
Statement stmt4_1_21 = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sq4_1_21 = "select * from book where 编号 = '"+str4_1_3+"'";
ResultSet rs4_1_21 = stmt4_1_21.executeQuery(sq4_1_21);
if(rs4_1_21.next())
{ String rs1item1 = rs4_1_21.getString("编号");
String rs1item2 = rs4_1_21.getString("书名");
String rs1item3 = rs4_1_21.getString( "作者");
String rs1item4 = rs4_1_21.getString("出版社");
jTextArea1.setText("编号: " +
rs1item1 +
'\n' +
"书名: " + rs1item2 + '\n' +
"作者: " + rs1item3 + '\n' +
"出版社: " + rs1item4 +
'\n');}
JOptionPane.showMessageDialog(this,"请核对所借的书籍信息", "成功借书",JOptionPane.OK_CANCEL_OPTION);
try
{
Statement stmt4_1_5_1 = conn.createStatement(ResultSet.
TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -