📄 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, "登陆系统", false); } //初始化用户界面 private void jbInit() throws Exception { centerPanel.setLayout(gridLayout1); jLabel2.setText("用户名:"); jLabel3.setText("密码:"); login.setText("登陆系统"); 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++; //如果输入错误三次,自动退出系统 if(logincount>=3) System.exit(1); } else{ //初始化系统主界面 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); //设置用户可以使用的功能 frame.setMenuStatus(userType); //显示主界面 frame.setVisible(true); //关闭登陆窗口 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); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -