?? loginframe.java~2~
字號:
package simpleusers;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class LoginFrame extends JFrame { Connection con = null; Statement stmt = null; ResultSet rs = null; JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); JTextField jT1 = new JTextField(); JPasswordField jP1 = new JPasswordField(); JButton jButton1 = new JButton(); JButton jButton2 = new JButton(); public LoginFrame() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { jLabel1.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel1.setText("用戶名"); jLabel1.setBounds(new Rectangle(63, 46, 61, 30)); this.setTitle("用戶管理系統-用戶登錄"); this.getContentPane().setLayout(null); jLabel2.setBounds(new Rectangle(63, 102, 61, 30)); jLabel2.setText("密 碼"); jLabel2.setFont(new java.awt.Font("Dialog", 0, 16)); jT1.setFont(new java.awt.Font("Dialog", 0, 16)); jT1.setText(""); jT1.setBounds(new Rectangle(137, 46, 131, 37)); jP1.setText(""); jP1.setBounds(new Rectangle(137, 102, 131, 37)); jButton1.setBounds(new Rectangle(69, 175, 69, 39)); jButton1.setFont(new java.awt.Font("Dialog", 0, 14)); jButton1.setText("確定"); jButton1.addActionListener(new LoginFrame_jButton1_actionAdapter(this)); jButton2.setText("重置"); jButton2.setFont(new java.awt.Font("Dialog", 0, 14)); jButton2.setBounds(new Rectangle(184, 175, 69, 39)); this.getContentPane().add(jLabel1, null); this.getContentPane().add(jT1, null); this.getContentPane().add(jP1, null); this.getContentPane().add(jLabel2, null); this.getContentPane().add(jButton1, null); this.getContentPane().add(jButton2, null); } void jButton1_actionPerformed(ActionEvent e) { String username=jT1.getText().trim(); String password=jP1.getText().trim(); String sql="select * from userandpwd where username='"+username+ "' and pwd='"+password+"'"; try{ Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); }catch(ClassNotFoundException e1){ System.out.println("加載JDBC數據庫驅動程序出錯"); } String url="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=Test"; try{ con = DriverManager.getConnection(url, "sa", ""); stmt = con.createStatement(); rs = stmt.executeQuery(sql); }catch(SQLException e2){ System.out.println("數據庫連接出錯"); } try{ if (rs.next()){ //信息顯示 } }catch(SQLException e3 ){ } try{ rs.close(); stmt.close(); con.close(); }catch(SQLException e4){ System.out.println("關閉對象連接出錯"); } }}class LoginFrame_jButton1_actionAdapter implements java.awt.event.ActionListener { LoginFrame adaptee; LoginFrame_jButton1_actionAdapter(LoginFrame adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton1_actionPerformed(e); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -