zoukankan      html  css  js  c++  java
  • 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();
        }
    
    }

  • 相关阅读:
    学习记录6
    学习记录5
    学习记录4
    学习记录3&开启新的世界
    学习记录2
    学习记录1
    类、对象和包
    班会总结
    请简单描述一下,java程序的运行过程,以及java为什么能跨平台
    JDK、JRE、JVM的区别与关系
  • 原文地址:https://www.cnblogs.com/dulute/p/10588358.html
Copyright © 2011-2022 走看看