java 仿qq登陆_java简单实现仿QQ登陆界面

本文档介绍如何使用Java Swing库创建一个简单的仿QQ登录界面。界面包括一个顶部图片、登录区域、找回密码和注册账号链接,以及记住密码和自动登录的选项。代码中详细设置了各个组件的位置和样式。
摘要由CSDN通过智能技术生成

实现思路:

1.总体用南北布局,北部为一个label图片,中部是一个自定义面板

2.面板不采用默认布局,自己给组建设置布局方式

package com.shl;

import javax.swing.*;

import java.awt.*;

public class Login extends JFrame{

JPanel mb;

JLabel lb,lb1,lb2,lb3;

JButton bt;

JTextField username;

JPasswordField password;

JCheckBox select1,select2;

public Login() {

lb=new JLabel(new ImageIcon("img/qimg.png"));//上部分图片

mb=new JPanel();

lb3=new JLabel(new ImageIcon("img/head.png"));//qq头像部分

username =new JTextField(20);

password=new JPasswordField(20);

lb1=new JLabel("注册账号");

lb1.setForeground(new Color(28,134,238));

lb1.setFont(new Font("宋体",Font.PLAIN,16));

lb1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

lb2=new JLabel("找回密码");

lb2.setForeground(new Color(28,134,238));

lb2.setFont(new Font("宋体",Font.PLAIN,16));

lb2.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

select1=new JCheckBox("记住密码");

select1.setFont(new Font("宋体",Font.PLAIN,15));

select1.setBackground(Color.WHITE);

select2=new JCheckBox("自动登陆");

select2.setFont(new Font("宋体",Font.PLAIN,15));

select2.setBackground(new Color(255,250,250));

bt=new JButton("登 录");

//将组建添加到面板当中

mb.add(lb2);mb.add(lb1);mb.add(lb3);mb.add(select1);mb.add(select2);

mb.add(bt);mb.add(username);mb.add(password);

mb.setSize(540,190);

//将面板的布局设为null,然后自定义布局

mb.setLayout(null);

mb.setBackground(Color.white);

lb3.setBounds(43, 8, 100, 100);

username.setBounds(160, 14, 250, 37);

username.setFont(new Font("宋体",Font.PLAIN,16));

password.setBounds(160,48, 250, 37);

password.setFont(new Font("宋体",Font.PLAIN,16));

lb1.setBounds(420,10,80,34);

lb2.setBounds(420,50,80,34);

select1.setBounds(160,90,120,20);

select2.setBounds(320,90,120,20);

bt.setBounds(160,130,250,37);

bt.setFont(new Font("宋体",Font.PLAIN,16));

bt.setBackground(new Color(0,178,238));

bt.setForeground(Color.white);

this.add(lb,BorderLayout.NORTH);

this.add(mb,BorderLayout.CENTER);

this.setSize(540, 440);

this.setTitle("用户登录");

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setLocation(620, 280);

this.setResizable(false);

this.setVisible(true);

}

public static void main(String[] args) {

Login login=new Login();

}

}

效果图:

132c68ec01230967d791f37012d61072.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值