⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lasttest.java

📁 一个学员信息管理系统小程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import java.awt.*;import java.awt.event.*;import java.lang.*;import java.util.*;import javax.swing.*;import java.io.*;/* * lastTest.java * * Created on 2004年11月7日, 上午2:17 *//** * * @author  aTom!c   陈冠栋 */public class lastTest{    public static void main(String[] args)    {        WelcomeFrame wframe = new WelcomeFrame();        wframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);                wframe.show();    }}class WelcomeFrame extends JFrame       //登陆窗口{    public WelcomeFrame()    {        setTitle("学生信息管理系统");        setBounds(150,150,300,200);        setResizable(false);                WelcomePanel wpanel = new WelcomePanel(this);        getContentPane().add(wpanel);    }}class WelcomePanel extends JPanel{    protected Hashtable date;    private final  JTextField num_t;    private final  JPasswordField psd_t;    private final   JButton login,cancel,reg;    private int i = 0;        public WelcomePanel(final WelcomeFrame a)    {        setLayout(new GridBagLayout());        date = new Hashtable();        date.put("6666","asdf");        JLabel num = new JLabel("学号:");        JLabel psd = new JLabel("密码:");        num_t = new JTextField(10);        num_t.requestFocus();        psd_t = new JPasswordField(10);        login = new JButton("登陆(L)");        login.setMnemonic('L');        login.setToolTipText("登陆系统");        cancel = new JButton("取消(C)");        cancel.setMnemonic('C');        cancel.setToolTipText("重新输入");        reg = new JButton("注册(R)");        reg.setMnemonic('R');        reg.setToolTipText("注册用户");                GridBagConstraints con = new GridBagConstraints();         //布局管理        con.weighty = 1;        con.anchor = GridBagConstraints.SOUTH;        addCompent(num,con,0,0,1,1);        addCompent(num_t,con,1,0,2,1);        con.anchor = GridBagConstraints.CENTER;        addCompent(psd,con,0,1,1,1);        addCompent(psd_t,con,1,1,2,1);        addCompent(login,con,0,2,1,1);        addCompent(cancel,con,1,2,1,1);        addCompent(reg,con,2,2,1,1);                a.addWindowListener(new WindowAdapter()        {           public void windowActivated (WindowEvent e)            {               num_t.requestFocus();           }        });                num_t.addKeyListener(new KeyAdapter()           //控制输入的字符        {            public void keyTyped(KeyEvent e)            {                char ch = e.getKeyChar();                if (ch < '0' || ch > '9')                {                    if (ch != '\b')                    {                        e.consume();                    }                }            }        });                num_t.addFocusListener(new FocusAdapter()        {            public void focusLost(FocusEvent e)            {                if ((num_t.getText().length() < 4) && (num_t.getText().length() > 0))                {                    int l = 4 - num_t.getText().length();                    for (int k = 0;k < l;k++)                    {                        num_t.setText("0"+num_t.getText());                    }                }            }        });                psd_t.addActionListener(new ActionListener()         //密码框里按回车等于按登陆按钮        {            public void actionPerformed(ActionEvent e)            {                login.doClick();            }        });                login.addActionListener(new ActionListener()        {            public void actionPerformed(ActionEvent e)            {                try                {                    checkDate();           //检查学号格式                }                catch (TextException e1)                {                    e1.display();                    cancel.doClick();                }                catch (PsdException e2)                {}                                if (date.containsKey(num_t.getText()))                {                    Object obj = date.get(num_t.getText());                    if (obj.toString().equals(psd_t.getText()))             //验证密码                    {                        i = 0;                        MainFrame mframe = new MainFrame(num_t.getText(),a);                        mframe.addWindowListener(new WindowAdapter()                        {                            public void windowClosing(WindowEvent e)                            {                                System.exit(0);                            }                        });                        mframe.show();                        psd_t.setText("");                        num_t.setText("");                        a.setVisible(false);                    }                    else                      //密码输入错误判断                    {                        i++;                        if (i<4)              //密码输入错误次数控制                        {                            JOptionPane.showMessageDialog(null,"密码错误!请重新输入密码!","注意",2);                            psd_t.setText("");                            psd_t.requestFocus();                        }                        else                        {                            JOptionPane.showMessageDialog(null,"输入错误密码次数过多,程序关闭!","错误",1);                            System.exit(0);                        }                    }                }                else                {                    if (num_t.getText().length() > 1)                    {                        int l = JOptionPane.showConfirmDialog(null,"你并不是合法用户,需要注册吗?","选择操作",0,3);                        if (l == 0)                        {                            reg.doClick();                            login.doClick();                        }                        else                        {                            cancel.doClick();                        }                    }                }            }        });                cancel.addActionListener(new ActionListener()        {            public void actionPerformed(ActionEvent e)            {                num_t.setText("");                psd_t.setText("");                num_t.requestFocus();            }        });                reg.addActionListener(new ActionListener()        {            public void actionPerformed(ActionEvent e)            {                try                            //注册时同时验证学号和密码                {                    checkDate();                    if (date.containsKey(num_t.getText()))                    {                        JOptionPane.showMessageDialog(null,"你申请的学号已被注册!请重新选择!","警告",2);                        cancel.doClick();                    }                    else                    {                        date.put(num_t.getText(),psd_t.getText());                        JOptionPane.showMessageDialog(null,"注册成功!谢谢!","恭喜",1);                    }                }                catch (TextException e1)                {                    e1.display();                    cancel.doClick();                }                catch (PsdException e2)                {                    e2.display();                    psd_t.setText("");                    psd_t.requestFocus();                }            }        });    }        public void addCompent(Component c,GridBagConstraints gc,int x,int y,int w,int h)    {        gc.gridx = x;        gc.gridy = y;        gc.gridwidth = w;        gc.gridheight = h;        add(c,gc);    }        public void checkDate() throws PsdException,TextException    {        if ((num_t.getText().length() > 4) || (num_t.getText().length() < 1 ))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -