• Swing程序设计实践与练习3


    public class asd extends JFrame {
    
        public asd() {
            // TODO Auto-generated constructor stub
            Container c = getContentPane();
            setLayout(new GridLayout(3, 1, 5, 5));
            final JPanel jp1 = new JPanel();
            JPanel jp2 = new JPanel();
            JPanel jp3 = new JPanel();
            jp1.setLayout(new GridLayout(1, 2, 5, 5));
            jp2.setLayout(new GridLayout(1, 2, 5, 5));
            jp3.setLayout(new GridLayout(1, 2, 5, 5));
            
            
            jp1.add(new JLabel("用户名"));
            final JTextField jt = new JTextField();
            jp1.add(jt);
            
            
            jp2.add(new JLabel("密码"));
            final JPasswordField jp = new JPasswordField();
            jp2.add(jp);
    
            JButton jb1 = new JButton("登录");
            JButton jb2 = new JButton("重置");
            jp3.add(jb1);
            jp3.add(jb2);
            
            jb1.addActionListener(new ActionListener() {
    
                @Override
                public void actionPerformed(ActionEvent e) {
    
                    // TODO Auto-generated method stub
                    if (jt.getText().trim().equals("mr")&&jp.getText().trim().equals("mrsoft")) {
                        JOptionPane.showMessageDialog(null, "登陆成功");
                    }
                    else{
                        JOptionPane.showMessageDialog(null, "登陆失败,用户名或密码错误");
                    }
                }
            });
            
            jb2.addActionListener(new ActionListener() {
                
                @Override
                public void actionPerformed(ActionEvent e) {
                    // TODO Auto-generated method stub
                    jt.setText("");
                    jp.setText("");
                }
            });
            
            c.add(jp1);
            c.add(jp2);
            c.add(jp3);
            setSize(200, 150);
            setVisible(true);
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        }
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            new asd();
        }
    
    }

  • 相关阅读:
    07.28周四
    07.27 约束自己
    07.26
    07.25新的一周,踏实,努力
    07.21 智能充电开发
    07.20小笔记
    07.20 html5的适配flexible
    07.19 Linux命令 cd
    SpringBoot简介和Banner
    webpack生产环境配置
  • 原文地址:https://www.cnblogs.com/dulute/p/10588358.html
Copyright © 2020-2023  润新知