?? logframe.java
字號:
package app;import java.awt.*;import com.borland.jbcl.layout.*;import javax.swing.*;import java.awt.event.*;import java.sql.*;import java.lang.Object;/** * <p>Title: 個人日常事務(wù)管理系統(tǒng)</p> * <p>Description: 用于個人管理</p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author unascribed * @version 1.0 */public class LogFrame extends JFrame { private XYLayout xYLayout1 = new XYLayout(); private JLabel jLabel_name = new JLabel(); private JLabel jLabel_password = new JLabel(); private JTextField jTextField_name = new JTextField(); private JLabel jLabel1 = new JLabel(); private JPasswordField jPasswordField = new JPasswordField(); private JButton jButton1 = new JButton(); private JButton jButton2 = new JButton(); protected String user,password,password_from; AppFrame frame; public LogFrame(AppFrame frame1) { frame = frame1; try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { this.setTitle("登錄窗口"); this.getContentPane().setLayout(xYLayout1); jLabel_name.setFont(new java.awt.Font("Dialog", 0, 14)); jLabel_name.setText("請輸入用戶名:"); jLabel_password.setFont(new java.awt.Font("Dialog", 0, 14)); jLabel_password.setText("請輸入密碼:"); jLabel1.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel1.setText("個 人 日 常 事 務(wù) 管 理 系 統(tǒng)"); jButton1.setFont(new java.awt.Font("Dialog", 0, 14)); jButton1.setText("確 認"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton1_actionPerformed(e); } }); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton2_actionPerformed(e); } }); jButton2.setText("取 消"); jButton2.setFont(new java.awt.Font("Dialog", 0, 14)); jTextField_name.addFocusListener(new java.awt.event.FocusAdapter() { public void focusLost(FocusEvent e) { jTextField_name_focusLost(e); } }); jPasswordField.addFocusListener(new java.awt.event.FocusAdapter() { public void focusLost(FocusEvent e) { jPasswordField_focusLost(e); } }); this.getContentPane().add(jLabel_password, new XYConstraints(52, 148, 91, 28)); this.getContentPane().add(jLabel_name, new XYConstraints(51, 101, 99, -1)); this.getContentPane().add(jTextField_name, new XYConstraints(160, 95, 155, 28)); this.getContentPane().add(jLabel1, new XYConstraints(84, 20, 220, 38)); this.getContentPane().add(jPasswordField, new XYConstraints(159, 143, 156, 32)); this.getContentPane().add(jButton1, new XYConstraints(77, 205, 88, 33)); this.getContentPane().add(jButton2, new XYConstraints(218, 206, 88, 33)); } void jButton2_actionPerformed(ActionEvent e) { System.exit(0); } void jTextField_name_focusLost(FocusEvent e) { } void jPasswordField_focusLost(FocusEvent e) {password = jPasswordField.getText(); } void jButton1_actionPerformed(ActionEvent e) { Connection con; String url="jdbc:odbc:grrc"; Statement stmt; user = jTextField_name.getText(); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection(url,"",""); String sql="SELECT PASSWORD from sys_safe where NAME ='"+user+"'"; stmt=con.createStatement(); ResultSet rs=stmt.executeQuery(sql); if(rs.next()) password_from = rs.getString("PASSWORD"); if(password_from.endsWith(password)){ JOptionPane.showMessageDialog(this,"密碼正確!","登錄信息",JOptionPane.INFORMATION_MESSAGE); this.setVisible(false); frame.setVisible(true); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int h = screenSize.height; int w = screenSize.width; frame.setSize(w,h); Dimension frameMainSize = frame.getSize(); // Center the Window if (frameMainSize.height > screenSize.height) { frameMainSize.height = screenSize.height; } if (frameMainSize.width > screenSize.width) { frameMainSize.width = screenSize.width; } frame.setLocation((screenSize.width - frameMainSize.width) / 2, (screenSize.height - frameMainSize.height) / 2); } else{ JOptionPane.showMessageDialog(this,"密碼和用戶名不符,請重新輸入密碼!","登錄信息",JOptionPane.INFORMATION_MESSAGE); } con.close(); }catch(Exception ex){ System.out.println("A problem occurred during the establishment of th connection: "+ex); } }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -