📄 frame2.java~37~
字号:
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("Frame Title"); 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(); // System.out.println(str1); //System.out.println(str2); //装载jdbc驱动程序 String driverName = "oracle.jdbc.OracleDriver"; Driver driver = (Driver) Class.forName(driverName).newInstance(); //连接数据库 Connection con = DriverManager.getConnection( "jdbc:oracle:thin:@thsspc0791:1521:tongfang", "sa", "tongfang"); 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=" name " +" id "+" password "+" books "+" yuding "+" department "+" money "+"\n"; //System.out.println("aksdjflkajsdlf"); do{ //System.out.println(res.getString(1)+":" + res.getLong(2) + ":" +res.getLong(3) +":"+res.getInt(4)+":"+res.getString(5)+":"+res.getString(6)+":"+res.getInt(7)); outputarea+=" "+res.getString(1)+" "+" "+res.getLong(2)+" "+" "+res.getLong(3)+" "+" "+res.getInt(4)+" "+" "+res.getString(5)+" "+" "+res.getString(6)+" "+" "+res.getInt(7)+" "+"\n"; jTextArea1.setText(outputarea); }while (res.next()); } } pstmt.close(); con.close(); }catch (InstantiationException e) { System.out.println(e.getMessage()); }catch (IllegalAccessException e) { System.out.println(e.getMessage()); }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 + -