zoukankan      html  css  js  c++  java
  • 2016/4/24 图形界面 作业

    public Register(){
      JFrame  regster =new JFrame("登陆");  //新建窗口
      regster.addNotify();   // 连接到屏幕
      regster.setVisible(true);  // 显示窗口
      regster.setSize(400, 300); //设置窗口大小
      regster.setLocationRelativeTo(null); //窗口居中
      regster.setDefaultCloseOperation(regster.EXIT_ON_CLOSE);//关闭窗口关闭程序
      Container   container=new Container();// 容器
      container=regster.getContentPane(); // 内容返回 容器中
      container.setLayout(null);  // 为空
      
         
      JLabel  user=new JLabel("用户名:"); //用户字体
      JPanel  userPanel=new JPanel(); // 仪表板
      userPanel.add(user);  // 用户  显示
      userPanel.setBounds(40, 50, 60,20);
      container.add(userPanel);
       //用户  输入框
      JTextField  userFrame =new JTextField();
      userFrame.setBounds(100, 50, 130, 20);
      JLabel  userprompt=new JLabel("请输入用户名 ");
        FocusListener   focusm=new focus(userFrame, userprompt); // 焦点
      userFrame.addFocusListener(focusm); // 焦点监视
      container.add(userFrame);
      // 用户    提示
      
      JPanel  userpromptPanel=new JPanel();
      userpromptPanel.add(userprompt);
      userpromptPanel.setBounds(240, 50, 100, 20);
      container.add(userpromptPanel);
      
      //密码
      JLabel  password=new JLabel("密      码:");
      JPanel  passwordPanel=new JPanel();
      passwordPanel.setBounds(40, 100, 60, 20);
      passwordPanel.add(password);
      container.add(passwordPanel);
      // 密码输入框
      JPasswordField  passwordFrame =new JPasswordField();
      passwordFrame.setBounds(100, 100, 130, 20);
      //密码   提示
      JLabel  passwordprompt=new JLabel("请输入密码 ");
         FocusListener   focusm2=new focus2(passwordFrame, passwordprompt); // 焦点
         passwordFrame.addFocusListener(focusm2); //焦点监视
      container.add(passwordFrame);
      // 密码放入          
      JPanel  passwordpromptPanel=new JPanel();
      passwordpromptPanel.add(passwordprompt);
      passwordpromptPanel.setBounds(240, 100, 100, 20);
      container.add(passwordpromptPanel);
      
      //鼠标监视 创建
      MouseListener  mouse=new  Mouse(userFrame,passwordFrame);
        
      //按钮    确定
      JButton  confirm=new JButton("确定");
      confirm.addMouseListener(mouse);  // 鼠标监视
      confirm.setBounds(50, 230, 60, 30);
      container.add(confirm);
      //  取消
      JButton  cancel=new JButton("取消");
      cancel.setBounds(200, 230, 60, 30);
      container.add(cancel); 
      
     }
     


     //  焦点监视   用户
     class focus extends FocusRegulator{ 
      private JTextField userFrame;  //用户输入框
      private  JLabel  userprompt;   //用户提示
      public focus(JTextField userFrame,JLabel  userprompt){
       this.userFrame=userFrame;
       this.userprompt=userprompt;
      }
           
      @Override
      public void focusLost(FocusEvent e) {
       // TODO Auto-generated method stub
       
       if(userFrame.getText().length()>5&&userFrame.getText().length()<19){
        if(Pattern.matches("[a-zA-Z]*", userFrame.getText().toString())){
         System.out.println("符合要求");
         userprompt.setText("符合要求");
        }else{
         userprompt.setText("不能有数字");
         System.out.println("不能有数字");
        }
       }else{
        userprompt.setText("请输入8-16位数");
        System.out.println("请输入8-16位数");
       }
       System.out.println(userFrame.getText());
       super.focusLost(e);
      }
      
     }
      // 密码焦点监视
     class focus2 extends FocusRegulator{ 
      private JPasswordField  passwordFrame;    //密码输入框
      private  JLabel  passwordprompt; //密码提示
      public focus2(JPasswordField passwordFrame,JLabel  passwordprompt){
       this.passwordFrame=passwordFrame;
       this.passwordprompt=passwordprompt;
      }
           
      @Override
      public void focusLost(FocusEvent e) {
       // TODO Auto-generated method stub
       
       if(passwordFrame.getText().length()>5&&passwordFrame.getText().length()<19){
        if(Pattern.matches("[0-9]*", passwordFrame.getText().toString())){
         System.out.println("符合要求");
         passwordprompt.setText("符合要求");
        }else{
         passwordprompt.setText("必须全为数字");
         System.out.println("必须全为数字");
        }
       }else{
        passwordprompt.setText("请输入8-16位数");
        System.out.println("请输入8-16位数");
       }
       System.out.println(passwordFrame.getText());
       super.focusLost(e);
      }
      
     }

     // 鼠标监视
     class Mouse  extends  MouseRegulator{
      private JTextField userFrame;  //用户名
      private JPasswordField  passwordFrame; // 密码
      
         public Mouse(JTextField userFrame,JPasswordField  passwordFrame){
          this.userFrame=userFrame;
          this.passwordFrame=passwordFrame;
         }
      
      @Override
      public void mouseClicked(MouseEvent e) {
       // TODO Auto-generated method stub
       if(userFrame.getText().equals("zhangsan")&&
       passwordFrame.getText().equals("88888888")){
        new StudentInterface();
        
       }
       if(userFrame.getText().equals("laowang")&&
          passwordFrame.getText().equals("88888888")){
        new TeacherInterface();
        
       }
     
       super.mouseClicked(e);
      }
     
     }

         public static void main(String[] args) {
      new Register();
     }
      
     
     
    }

  • 相关阅读:
    [转] 美股评论:远离波动的噪音
    [转] GDB 下 watch的使用
    [转] Web性能压力测试工具之ApacheBench(ab)详解
    [转] Ubuntu 12.04下LAMP安装配置 (Linux+Apache+Mysql+PHP)
    [转] 在 Linux 中怎样使用cp命令合并目录树
    [转] postgresql常用命令
    [转] 跟着美联储投资
    [转] 智能指针(三):unique_ptr使用简介
    关于前端开发
    [转] 美股评论:美国散户血泪辛酸
  • 原文地址:https://www.cnblogs.com/waxlh/p/5428508.html
Copyright © 2011-2022 走看看