zoukankan      html  css  js  c++  java
  • 使用Java的Frame类编写的QQ登录界面

      1 public static void main(String[] args) {
      2         
      3         Frame f = new Frame();
      4         
      5         //关闭窗体
      6         f.addWindowListener(new WindowAdapter() {
      7             @Override
      8             public void windowClosing(WindowEvent e) {
      9                 System.exit(0);
     10             }
     11         });
     12         
     13         f.setTitle("QQ登录");//添加标题
     14         f.setSize(420, 230);//设置窗体的尺寸
     15         f.setLocation(455, 207);//设置窗体出现坐标
     16         f.setLayout(null);//清除窗体默认布局
     17         f.setIconImage(Toolkit.getDefaultToolkit().getImage("F:\qq.png"));//设置图标
     18         f.setResizable(false);//禁止窗体改变尺寸
     19         
     20     
     21         
     22         //账号标签
     23         Label user = new Label("账号:");
     24         user.setLocation(75, 50);
     25         user.setSize(50, 25);
     26         user.setFont(new Font("微软雅黑",Font.BOLD,16));
     27         f.add(user);
     28         
     29         //密码标签
     30         Label password = new Label("密码:");
     31         password.setLocation(75, 100);
     32         password.setSize(50, 25);
     33         password.setFont(new Font("微软雅黑",Font.BOLD,16));
     34         f.add(password);
     35         
     36         //输入账号的文本框
     37         TextField t1 = new TextField();
     38         //键盘输入监听
     39         t1.addKeyListener(new KeyAdapter() {
     40             @Override
     41             public void keyTyped(KeyEvent e) {
     42                 int key = e.getKeyChar();
     43                 if(key>=KeyEvent.VK_0 && key<=KeyEvent.VK_9){
     44                     
     45                 }else{
     46                     e.consume();
     47                 }
     48             }
     49         });
     50         t1.setSize(220,25);
     51         t1.setLocation(130, 50);
     52         t1.setFont(new Font("微软雅黑",Font.PLAIN,16));
     53         f.add(t1);
     54         
     55         //输入密码的文本框
     56         TextField t2 = new TextField();
     57         t2.setEchoChar('*');
     58         t2.setSize(220,25);
     59         t2.setLocation(130, 100);
     60         t2.setFont(new Font("微软雅黑",Font.PLAIN,16));
     61         f.add(t2);
     62         
     63         //登录按钮
     64         Button login = new Button("登录");
     65         //按钮触发事件
     66         login.addActionListener(new ActionListener() {
     67             
     68             @Override
     69             public void actionPerformed(ActionEvent arg0) {
     70                 String zh = t1.getText();
     71                 String ma = t2.getText();
     72                 if(zh.equals("34598700") && ma.equals("meinv123")){
     73                     System.out.println("登录成功");
     74                 }else{
     75                     JOptionPane.showMessageDialog(f, "账号或密码输入错误");
     76                     t1.setText("");
     77                     t2.setText("");
     78                 }
     79             }
     80         });
     81         login.setLocation(100, 160);//按钮在窗体中的坐标
     82         login.setSize(75, 30);//设计按钮的尺寸
     83         f.add(login);//把按钮元素添加到窗体中
     84         
     85         //注册按钮
     86         Button reg = new Button("注册");
     87         //触发事件
     88         reg.addActionListener(new ActionListener() {
     89             
     90             @Override
     91             public void actionPerformed(ActionEvent e) {
     92                 new Reg();
     93             }
     94         });
     95         reg.setLocation(250, 160);//按钮在窗体中的坐标
     96         reg.setSize(75, 30);//设计按钮的尺寸
     97         f.add(reg);//把按钮元素添加到窗体中
     98         
     99         f.setVisible(true);//设置窗体的可见性
    100 
    101     }
  • 相关阅读:
    rest_framework 认证组件 权限组件
    Django rest_framework 序列化组件
    django 跨域问题
    python的magic methods
    RESTful规范
    BBS论坛 后台管理
    BBS论坛 文章详情、点赞、评论
    BBS论坛 home主页与个人站点主页
    好用的SqlParamterList
    教你如何在实战项目中使用WCF
  • 原文地址:https://www.cnblogs.com/jpwz/p/6070349.html
Copyright © 2011-2022 走看看