📄 frame2.java
字号:
package untitled5;
import java.io.*;
import java.net.*;
import java.sql.*;
import java.lang.*;
import javax.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import com.borland.dbswing.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
//查询读者信息
public class Frame2 extends JFrame {
JPanel contentPane;
JLabel statusBar = new JLabel();
JLabel jLabel1 = new JLabel();
XYLayout xYLayout1 = new XYLayout();
JPasswordField jPasswordField1 = new JPasswordField();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextField jTextField1 = new JTextField();
JScrollPane jScrollPane1 = new JScrollPane();
JTextArea jTextArea1 = new JTextArea();
JLabel jLabel4 = new JLabel();
//Construct the frame
public Frame2() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(600, 500));
this.setTitle("查询读者状态");
statusBar.setText(" ");
jLabel1.setFont(new java.awt.Font("SansSerif", 0, 20));
jLabel1.setText("图书馆管理系统");
jLabel2.setFont(new java.awt.Font("SansSerif", 0, 15));
jLabel2.setForeground(Color.black);
jLabel2.setText("密码");
contentPane.setForeground(Color.black);
jLabel3.setFont(new java.awt.Font("SansSerif", 0, 15));
jLabel3.setText("姓名");
jTextField1.addActionListener(new Frame2_jTextField1_actionAdapter(this));
jTextField1.setText("");
jPasswordField1.setText("");
jPasswordField1.addActionListener(new Frame2_jPasswordField1_actionAdapter(this));
jTextArea1.setBackground(Color.lightGray);
jLabel4.setFont(new java.awt.Font("SansSerif", 0, 20));
jLabel4.setText("该读者的详细信息");
contentPane.add(statusBar, new XYConstraints(0, 284, 400, -1));
contentPane.add(jLabel1, new XYConstraints(127, 0, 146, 40));
contentPane.add(jLabel3, new XYConstraints(67, 43, -1, -1));
contentPane.add(jTextField1, new XYConstraints(102, 42, 96, 25));
contentPane.add(jLabel2, new XYConstraints(215, 39, -1, 26));
contentPane.add(jPasswordField1, new XYConstraints(246, 40, 82, 26));
contentPane.add(jScrollPane1, new XYConstraints(20, 98, 414, 315));
contentPane.add(jLabel4, new XYConstraints(156, 432, 217, 43));
jScrollPane1.getViewport().add(jTextArea1, null);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void jTextField1_actionPerformed(ActionEvent e) {
}
void jPasswordField1_actionPerformed(ActionEvent e) {
//OptionPane.showMessageDialog(this, "查无此人", "错误",
// JOptionPane.ERROR_MESSAGE);
validID();
}
void validID() {
try {
String str1, str2;
str1 = jTextField1.getText();
str2 = jPasswordField1.getText();
//装载jdbc驱动程序
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=student"; //连接服务器和数据库sample
String userName = "sa"; //默认用户名
String userPwd = "081129"; //密码
//连接数据库
Connection con;
Class.forName(driverName);
con=DriverManager.getConnection(dbURL, userName, userPwd);
PreparedStatement pstmt = con.prepareStatement(
" select name ,id,password ,books,yuding,department,money from first where name=?");
pstmt.setString(1, str1);
ResultSet res = pstmt.executeQuery();
//String sa=res.getString(1);
if ((!res.next()) || res.getString("password") == null) {
JOptionPane.showMessageDialog(this, "查无此人", "错误",
JOptionPane.ERROR_MESSAGE);
}else {
if ( !res.getString("password").equals(str2)) { JOptionPane.showMessageDialog(this, "密码错误重输!!" ,"请重新输入",
JOptionPane.ERROR_MESSAGE);
}else {
String outputarea="名字"+"\t"+"读者ID"+"\t"+"读者密码"+"\t"+"书名"+"\t"+"是否预订"+"\t"+"读者院系"+"\t"+"书籍价格"+"\t"+"\n";
do{
outputarea+=res.getString(1)+"\t"+res.getInt(2)+"\t"+res.getInt(3)+"\t"+res.getString(4)+"\t"+res.getString(5)+"\t"+res.getString(6)+"\t"+res.getInt(7)+"\t"+"\n";
jTextArea1.setText(outputarea);
}while (res.next());
}
}
pstmt.close();
con.close();
}catch (ClassNotFoundException e) {
System.out.println(e.getMessage());
}catch (SQLException edd) {
edd.printStackTrace() ;
System.out.println(edd.getMessage());
}
}
}
class Frame2_jTextField1_actionAdapter implements java.awt.event.ActionListener {
Frame2 adaptee;
Frame2_jTextField1_actionAdapter(Frame2 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jTextField1_actionPerformed(e);
}
}
class Frame2_jPasswordField1_actionAdapter implements java.awt.event.ActionListener {
Frame2 adaptee;
Frame2_jPasswordField1_actionAdapter(Frame2 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jPasswordField1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -