📄 frame3.java~39~
字号:
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.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class Frame3 extends JFrame { JPanel contentPane; JLabel statusBar = new JLabel(); XYLayout xYLayout1 = new XYLayout(); JLabel jLabel1 = new JLabel(); JScrollPane jScrollPane1 = new JScrollPane(); JTextArea jTextArea1 = new JTextArea(); JLabel jLabel2 = new JLabel(); JLabel jLabel3 = new JLabel(); JTextField jTextField1 = new JTextField(); JLabel jLabel4 = new JLabel(); //Construct the frame public Frame3() { 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.setForeground(Color.red); jLabel1.setText("图书管理系统"); jTextArea1.setBackground(Color.lightGray); jTextArea1.setText(""); jLabel2.setFont(new java.awt.Font("SansSerif", 0, 20)); jLabel2.setForeground(Color.red); jLabel2.setText("书籍的详细信息"); jLabel3.setFont(new java.awt.Font("SansSerif", 0, 15)); jLabel3.setText("名称"); jTextField1.setText(""); jTextField1.addActionListener(new Frame3_jTextField1_actionAdapter(this)); jLabel4.setFont(new java.awt.Font("SansSerif", 0, 13)); jLabel4.setText("请输入书籍的名称"); contentPane.add(statusBar, new XYConstraints(0, 284, 400, -1)); contentPane.add(jScrollPane1, new XYConstraints(49, 139, 478, 310)); jScrollPane1.getViewport().add(jTextArea1, null); contentPane.add(jLabel3, new XYConstraints(59, 58, -1, -1)); contentPane.add(jTextField1, new XYConstraints(87, 58, 119, 29)); contentPane.add(jLabel1, new XYConstraints(242, 0, 138, 42)); contentPane.add(jLabel2, new XYConstraints(164, 456, 187, 43)); contentPane.add(jLabel4, new XYConstraints(7, 38, -1, -1)); } //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) { validID(); System.out.println("str1"); } void validID() { System.out.println("JLKJLJLJLJL"); try { String str1; str1 = jTextField1.getText(); // int issn=Integer.parseInt(str1); System.out.println(str1); // 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 ,writer, issn, state, place, date1, id from book where name=? "); pstmt.setString(1, str1); ResultSet res = pstmt.executeQuery(); System.out.println("ljljljljljljlj"); //String sa=res.getString(1); if ((!res.next()) || res.getString("writer")== null) { JOptionPane.showMessageDialog(this, "查无此书", "错误", JOptionPane.ERROR_MESSAGE); }else { String outputarea=" name " +" writer "+" issn "+" state "+" place "+" date "+" id "+"\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.getString(2)+" "+" "+res.getLong(3)+" "+" "+res.getString(4)+" "+" "+res.getString(5)+" "+" "+res.getDate(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 Frame3_jTextField1_actionAdapter implements java.awt.event.ActionListener { Frame3 adaptee; Frame3_jTextField1_actionAdapter(Frame3 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jTextField1_actionPerformed(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -