?? loginsystem.java
字號:
package com.csbook.restaurant;import java.awt.*;import javax.swing.*;import java.awt.event.*;import javax.swing.UIManager;import com.csbook.restaurant.utility.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author pengtao * @version 1.0 */public class LoginSystem extends JDialog { private int logincount=0; private JPanel centerPanel = new JPanel(); private JLabel jLabel2 = new JLabel(); private JLabel jLabel3 = new JLabel(); private JPasswordField password = new JPasswordField(); private JTextField username = new JTextField(); private JPanel southPanel = new JPanel(); private JButton login = new JButton(); private GridLayout gridLayout1 = new GridLayout(2,2); private JPanel northjPanel = new JPanel(); private JLabel jLabel4 = new JLabel(); private CheckUser cUser=new CheckUser(); FlowLayout flowLayout1 = new FlowLayout(); public LoginSystem(Frame frame, String title, boolean modal) { super(frame, title, modal); try { jbInit(); pack(); } catch(Exception ex) { ex.printStackTrace(); } } public LoginSystem() { this(null, "登陸系統(tǒng)", false); } //初始化用戶界面 private void jbInit() throws Exception { centerPanel.setLayout(gridLayout1); jLabel2.setText("用戶名:"); jLabel3.setText("密碼:"); login.setText("登陸系統(tǒng)"); login.addActionListener(new ActionListener(this)); jLabel4.setText("請輸入用戶名和密碼"); northjPanel.setLayout(flowLayout1); centerPanel.add(jLabel2, null); centerPanel.add(username, null); centerPanel.add(jLabel3, null); centerPanel.add(password, null); this.getContentPane().add(northjPanel, BorderLayout.NORTH); northjPanel.add(jLabel4, null); this.getContentPane().add(southPanel, BorderLayout.SOUTH); southPanel.add(login, null); this.getContentPane().add(centerPanel, BorderLayout.CENTER); this.setVisible(true); } public void login_actionPerformed(ActionEvent e) { //取得用戶輸入的用戶名 String operator=username.getText(); //取得用戶輸入的密碼 char temp[]=password.getPassword(); String tempPass=new String(temp); //檢查用戶是否為合法用戶 if(cUser.isValidUser(operator,tempPass)==false){ JOptionPane.showMessageDialog(this, "錯誤的用戶名或密碼", "錯誤", JOptionPane.WARNING_MESSAGE); logincount++; //如果輸入錯誤三次,自動退出系統(tǒng) if(logincount>=3) System.exit(1); } else{ //初始化系統(tǒng)主界面 MainFrame frame=new MainFrame(); //獲取用戶類型 String userType=cUser.getUserType(operator); //將主界面置于屏幕中央 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = frame.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } int inset = 50; setBounds(inset, inset, screenSize.width - inset*2, screenSize.height-inset*2); frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); //將當前用戶的名稱傳送給主界面 frame.setOperator(operator); //設(shè)置用戶可以使用的功能 frame.setMenuStatus(userType); //顯示主界面 frame.setVisible(true); //關(guān)閉登陸窗口 this.dispose(); } }}class ActionListener implements java.awt.event.ActionListener { LoginSystem adaptee; ActionListener(LoginSystem adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.login_actionPerformed(e); }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -