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


    复制代码
  • 相关阅读:
    sql经典语句大全
    经典SQL语句大全
    Bat命令学习
    [Microsoft][ODBC 驱动程序管理器] 在指定的 DSN 中,驱动程序和应用程序之间的体系结构不匹配
    配置WebSite的IIS时遇到的问题与解决方法
    数据库SQL优化大总结之 百万级数据库优化方案
    数据库索引以及优化
    搭建android开发环境
    SQL2008根据日志恢复
    WebService处理大数据量数据
  • 原文地址:https://www.cnblogs.com/wawawaawa/p/5293315.html
Copyright © 2011-2022 走看看