swing之复杂登陆界面的实现

Posted 猫儿爹

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swing之复杂登陆界面的实现相关的知识,希望对你有一定的参考价值。

package jiemian;

import gonggong.message;
import gonggong.messageType;
import gonggong.user;
import gongju.glhylb;
import gongju.glxc;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.ObjectOutputStream;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;

import moxing.yanzheng;

public class denglu extends JFrame implements ActionListener,KeyListener{

    JPanel jp1,jp2,jp2_1,jp2_2,jp2_11,jp2_12,jp2_13,jp2_14,jp2_3,jp3,jp3_1,jp3_2,jp3_3;
    
    JLabel jl1,jl2,jl3,jl4,jl5;
    
    JTextField jt1;
    JPanel jta1,jta2;
    JPasswordField jt2;
    
    JButton jb1,jb2,jb3,jb4;
    
    JCheckBox jcb1,jcb2;
    
    JTabbedPane jtp;
    
    
    public denglu()
     {
        jp1=new JPanel();
        jl1=new JLabel(new ImageIcon("image/DL.jpg"));
        jp1.add(jl1);
        
        
        jp2_1=new JPanel();
        jl2=new JLabel("QQ号码",JLabel.CENTER);
        jl3=new JLabel("QQ密码",JLabel.CENTER);
        jl4=new JLabel("忘记密码",JLabel.CENTER);
        jl4.setFont(new Font("宋体",Font.PLAIN,16));
        jl4.setForeground(Color.blue);
        jl5=new JLabel("<html><a href=\'www.qq.com\'>申请密码保护</a>");
        jl5.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
         
        jt1=new JTextField(10);
        jta1=new JPanel();
        jta1.add(jt1);
        jt2=new JPasswordField(10);
        jt2.addKeyListener(this);
        jta2=new JPanel();
        jta2.add(jt2);
        
        jb1=new JButton("清除号码");
        jp2_11=new JPanel();
        jp2_11.add(jb1);
        
        jcb1=new JCheckBox("隐身登录");
        
        jcb2=new JCheckBox("记住密码");
        
        jp2_1.setLayout(new GridLayout(3,3));
        jp2_1.add(jl2);jp2_1.add(jta1);jp2_1.add(jp2_11);
        jp2_1.add(jl3);jp2_1.add(jta2);jp2_1.add(jl4);
        jp2_1.add(jcb1);jp2_1.add(jcb2);jp2_1.add(jl5);
        
        jp2_2=new JPanel();
        jp2_3=new JPanel();
        jtp=new JTabbedPane();
        jtp.add("QQ号码",jp2_1);
        jtp.add("手机号码",jp2_2);
        jtp.add("电子邮件",jp2_3);
        
        jb2=new JButton("登录");
        jb2.addActionListener(this);
        jb3=new JButton("取消");
        jb4=new JButton("注册向导");
        jp2_12=new JPanel();
        jp2_12.add(jb2);
        
        jp2_13=new JPanel();
        jp2_13.add(jb3);
        
        jp2_14=new JPanel();
        jp2_14.add(jb4);
        jp3=new JPanel();
        jp3.setLayout(new GridLayout(1,3));
        jp3.add(jp2_12);
        jp3.add(jp2_13);
        jp3.add(jp2_14);
        
        this.add(jp1,BorderLayout.NORTH);
        this.add(jtp);
        this.add(jp3,BorderLayout.SOUTH);
        
        this.setTitle("用户登陆");
        this.setSize(400,320);
        this.setLocation(300, 300);
        this.setResizable(false);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
        
     }
    
    public static void main(String [] args)
      {
        denglu dl=new denglu();
        
        
      }

    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        if(e.getSource()==jb2)
        {
            user u=new user();
        u.setUserid(jt1.getText().trim());
    //密码要特殊处理下
        u.setPasswd(new String(jt2.getPassword()));
        yanzheng yz=new yanzheng();
        if(yz.check(u))
         {
            new liebiao(u.getUserid());
            this.dispose();
            
         }
        else
         {
            JOptionPane.showMessageDialog(this, "用户名或密码错误");
            
         }
    }
        }

    @Override
    public void keyPressed(KeyEvent e1) {
        // TODO Auto-generated method stub
        if(e1.getKeyCode()==KeyEvent.VK_ENTER)
         {

            user u=new user();
        u.setUserid(jt1.getText().trim());
        u.setPasswd(new String(jt2.getPassword()));
        yanzheng yz=new yanzheng();
        if(yz.check(u))
         {
            try{
        liebiao lb=    new liebiao(u.getUserid());
        glhylb.addliebiao(u.getUserid(), lb);
        message m2=new message();
        m2.setMesType(messageType.message_get_onlinefriend);
        m2.setSender(u.getUserid());
        ObjectOutputStream oos=new ObjectOutputStream(glxc.getljfwxc(u.getUserid()).getS().getOutputStream());
        oos.writeObject(m2);
            }catch(Exception e){e.printStackTrace();}
            this.dispose();
            
         }
        else
         {
            JOptionPane.showMessageDialog(this, "用户名或密码错误");
            
         }
    
         }
    }

    @Override
    public void keyReleased(KeyEvent arg0) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void keyTyped(KeyEvent arg0) {
        // TODO Auto-generated method stub
        
    }
}

以上是关于swing之复杂登陆界面的实现的主要内容,如果未能解决你的问题,请参考以下文章

❤️Java实现模拟QQ(消息通信+登陆界面美化)❤️

编写了Java GUI的一个登录框,如何实现跳转,错误时出现提示框,登陆成功切换为下一界面

实验任务四-实现登陆界面的内容

Java Swing中键盘输入事件及处理

java中如何做到界面的跳转?

用java写一个登陆界面代码。