• Java 第二次作业


    package javazuoye;
    import javax.swing.*;

    import java.awt.*;
    import java.awt.event.*;
    public class denglujiemian {

        public static void main(String[] args) {
            // TODO Auto-generated method stub
            LoginDialog lo = new LoginDialog();
            lo.setVisible(true);
        }

    }
    public class MainWindow extends JFrame{
       

        JLabel but1;
        MainWindow(){
           
            setTitle("系统登录");
            setBounds(400,200,300,180);
            setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    //        setLayout(null);


            addWindowListener(new WindowAdapter(){
                public void windowClosing(WindowEvent e){
                    System.exit(0);
                }
            });
            but1 = new JLabel("登录成功!");
            this.add(but1);
       
        }
       
       
    }

    public class LoginDialog extends JDialog {
        JLabel name;
        JLabel a2;
        JComboBox a3;
        JPasswordField password;
        JButton shi;
        JButton fou;
       
        LoginDialog(){
            method1();
        }

        private void method1() {
            // TODO Auto-generated method stub
            setTitle("登录系统");
            setBounds(500,250,220,140);
            setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
            setLayout(null);
            setModal(true);
    //        this.setResizable(false);
           
            name = new JLabel("用户名:");
            name.setBounds(20,10,50,20);
            this.add(name);
            a2 = new JLabel("密码:");
            a2.setBounds(20,32,50,20);
            this.add(a2);
           
            a3 = new JComboBox();
            a3.addItem("huakaihualuo");
            a3.addItem("hellow");
            a3.setBounds(75,10,105,20);
            this.add(a3);
            password = new JPasswordField("666666");
            password.setBounds(75,33,105,20);
            password.setEchoChar('*');
            this.add(password);
           
            shi = new JButton("登录");
            shi.setBounds(25,60,60,20);
            add(shi);
            shi.addActionListener(new ActionListener(){

                @Override
                public void actionPerformed(ActionEvent e) {
                    // TODO Auto-generated method stub
                    login();
                }           
            });
            fou =new JButton("退出");
            fou.setBounds(110,60,60,20);
            add(fou);
            fou.addActionListener(new ActionListener(){

                @Override
                public void actionPerformed(ActionEvent e) {
                    // TODO Auto-generated method stub
                    logout();
                }   
            });
           
        }
        void login(){
            String accout = a3.getSelectedItem().toString();
            String pwd = new String(password.getPassword());
            if(accout.equals("huakaihualuo")&&pwd.equals("666666")){
                setVisible(false);
                showMainWindow();
            }else{
                JOptionPane.showMessageDialog(this, "用户名是"+accout + ",密码是" + pwd);
            }
        }
        void logout(){
            int ret = JOptionPane.showConfirmDialog(this,"退出登录?","取消登录",JOptionPane.YES_NO_OPTION);
            if(ret ==JOptionPane.YES_NO_OPTION){
                dispose();
            }
        }
        void showMainWindow(){
            MainWindow frm = new MainWindow();
            frm.setVisible(true);
        }
    }


    复制代码
  • 相关阅读:
    P3015 [USACO11FEB]最好的括号Best Parenthesis
    P1944 最长括号匹配_NOI导刊2009提高(1)
    P2328 [SCOI2005]超级格雷码
    P2308 添加括号
    P5657 格雷码【民间数据】
    P2196 挖地雷
    P5020 货币系统
    括号序列模型--序列dp--U86873 小Y的精灵国机房之旅
    P1033 自由落体
    P1017 进制转换
  • 原文地址:https://www.cnblogs.com/wawawaawa/p/5293315.html
Copyright © 2020-2023  润新知