?? checkid.java
字號:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package book_booking;import javax.swing.JFrame;import java.awt.*;import javax.swing.*;import java.awt.event.*;//import javax.swing.border.*;import java.sql.*;/** * * @author Administrator */public class CheckID extends JFrame implements ActionListener{ private SqlBean sqlBean = new SqlBean(); JTextField usernameField; JPasswordField passwordField; JButton jbOK,jbCancel; public CheckID() { usernameField=new JTextField(10); passwordField=new JPasswordField(10); jbOK=new JButton("確定",new ImageIcon("D:/book_booking/image/14.jpg")); jbCancel=new JButton("取消",new ImageIcon("D:/book_booking/image/56.jpg")); jbOK.addActionListener(this); jbCancel.addActionListener(this); Box box1=Box.createHorizontalBox(); box1.add(new JLabel("輸入用戶名:",new ImageIcon("D:/book_booking/image/47.jpg"),JLabel.CENTER)); box1.add(usernameField); Box box2=Box.createHorizontalBox(); box2.add(new JLabel("輸入密碼:",new ImageIcon("D:/book_booking/image/17.jpg"),JLabel.CENTER)); box2.add(passwordField); Box boxH=Box.createVerticalBox(); boxH.add(box1); boxH.add(box2); boxH.add(Box.createVerticalGlue()); JPanel pCenter=new JPanel(); pCenter.add(boxH); setLayout(new BorderLayout()); add(pCenter,BorderLayout.CENTER); JPanel pSouth=new JPanel(); pSouth.add(jbOK); pSouth.add(jbCancel); add(pSouth,BorderLayout.SOUTH); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setVisible(true);// setBounds(500,400,600,300); validate(); } public void actionPerformed(ActionEvent e) { String username = usernameField.getText().trim(); String password = new String(passwordField.getPassword()).trim(); try { if (e.getSource() == jbOK) { if(username.equals("")) { JOptionPane.showMessageDialog(this,"用戶名不能為空!","錯誤",JOptionPane.ERROR_MESSAGE); return; } String sqlStr="select * from login where user_name="+"'"+username+"'"+" and psw="+"'"+password+"'"; ResultSet result=sqlBean.executeQuery(sqlStr); if(result.next()) { sqlBean.CloseDataBase(); this.setVisible(false); this.dispose(); Interface manager = new Interface(); manager.setSize(650,600); } else { JOptionPane.showMessageDialog(this,"對不起,用戶名或密碼不正確!","警告",JOptionPane.WARNING_MESSAGE); } } else if (e.getSource() == jbCancel) { this.setVisible(false);// this.dispose(); } } catch(Exception ex) { System.err.println(ex); } } public static void main(String[] args) { CheckID frame = new CheckID(); frame.setSize(300,200); frame.setVisible(true); } }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -