首页 > 其他 > 详细

第十二周

时间:2019-11-16 17:03:53      阅读:96      评论:0      收藏:0      [点我收藏+]

用户登录界面

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接口方法

技术分享图片

第十二周

原文:https://www.cnblogs.com/lyp82ndl/p/11871982.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!