zoukankan      html  css  js  c++  java
  • 第十二周

    用户登录界面

    1.实验源码

    package Demo;
    
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPasswordField;
    import javax.swing.JTextField;
    
    class test1 {
        private JFrame frame = new JFrame("登录窗口");
        private JButton submit = new JButton("登录");
        private JButton reset = new JButton("重置");
        private JLabel nameLab = new JLabel("用户名:");
        private JLabel passLab = new JLabel("密码:");
        private JLabel infoLab = new JLabel("用户登录系统");
        private JTextField nameText = new JTextField();            
        private JPasswordField passText = new JPasswordField();
        
        public test1() {                                 
            submit.addActionListener(new ActionListener() {         
                public void actionPerformed(ActionEvent arg0) {
                    if(arg0.getSource() == submit) {                
                        String tname = nameText.getText();         
                        String tpass = new String(passText.getPassword());
                        
                        if(tname.equals("唐")&&tpass.equals("123456")) {
                            infoLab.setText("登录成功");
                        }else {
                            infoLab.setText("登录失败");
                        }
                    }
                        if(arg0.getSource() == reset) {                 
                            nameText.setText("");                     
                            passText.setText("");
                            infoLab.setText("用户登录系统");            
                    }
                }
            });
            
            frame.setLayout(null);
            nameLab.setBounds(5, 5, 60, 20);
            passLab.setBounds(5, 30, 60, 20);
            infoLab.setBounds(5, 65, 220, 30);
            nameText.setBounds(65, 5, 100, 20);
            passText.setBounds(65, 30, 100, 20);
            submit.setBounds(165, 5, 60, 20);
            reset.setBounds(165, 30, 60, 20);
            
            frame.add(nameLab);
            frame.add(passLab);
            frame.add(infoLab);
            frame.add(nameText);
            frame.add(passText);
            frame.add(submit);
            frame.add(reset);
            frame.setSize(400, 300);
            frame.setVisible(true);
        }
    }

    测验

    package Demo;
    
    public class test2 {
        public static void main(String[] args) {
            new test1();
        }
    }

    2.实验截图

    实验总结:

    这个登录窗口老师上课讲过,书上也有代码,还算比较简单。

    课程总结:

    窗体事件

    WindowListener是专门处理窗体事件的监听接口,如窗口打开、关闭等。

    WindowLisener接口的方法

    动作事件及监听处理

    ActionListener接口处理按钮的动作事件

    ActionListener接口方法

  • 相关阅读:
    Mybatis <set>标签
    Mybatis <where>标签
    Mybatis choose (when, otherwise)标签
    Mybatis <if>标签
    Mybatis <Sql>标签
    Mybatis配置详解
    [转]在浏览器的标签页显示网站标志图标(或指定图标)的方法
    【转】如何建立一个样式新颖的CSS3搜索框
    【转】css布局居中和CSS内容居中区别和对应DIV CSS代码
    作业:按钮控制打开关闭新窗口及新窗口按钮关闭父窗口
  • 原文地址:https://www.cnblogs.com/lyp82ndl/p/11871982.html
Copyright © 2011-2022 走看看