Java实现QQ登陆界面,以下是效果截图:
素材:
以下是源代码:
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.*;
public classQqClientLogin2 extends JFrame implements MouseListener{
//北部区域标签,放图片QQ2012
JLabeljlb;
//中部区域
JPaneljp;
JComboBoxcb;//组合框设置状态用的
JLabeljp_jlb1,jp_jlb3,jp_jlb4; //标签"注册账号""找回密码" JTextField jp_jtf; // QQ号码/手机/邮箱
JTextFieldjp_jtf;// QQ号码/手机/邮箱
TextFieldjp_pw; //密码
JCheckBoxjp_jcb1,jp_jcb2;//复选框设置"记住密码""自动登录"
Fontf1=new Font("宋体", Font.PLAIN, 14); //设置字体
JButtonjp_jb1,jp_jb2,jp_jb3;//按钮设置登陆等
public static void main(String[] args) {
QqClientLogin2acl=newQqClientLogin2();
}
public QqClientLogin2() {
jlb=new JLabel(new ImageIcon("image/tou.gif")); //图片路径可要根据你放置的位置修改 不然显示不出来若是和文件放同一个地方则image/ 可以去掉
jp=new JPanel();
jp.setLayout(null);
jp_jlb1=new JLabel(new ImageIcon("image/qqtou.gif"));
jp_jlb1.setBounds(18, 10, 85,85); //设置标签位置前提是要空布局
jp_jtf=new JTextField("QQ号码/手机/邮箱");
jp_jtf.setForeground(Color.LIGHT_GRAY);//设置颜色
jp_jtf.addMouseListener(this);
jp_jtf.setBounds(118, 11, 170,25);
jp_pw=new TextField("密码",24);
jp_pw.setForeground(Color.LIGHT_GRAY);
jp_pw.addMouseListener(this);
jp_pw.setBounds(118, 45, 170,24);
jp_jlb3=new JLabel("注册账号");
jp_jlb3.setFont(f1);
jp_jlb3.setForeground(Color.BLUE);
jp_jlb3.setBounds(300, 10, 70,25);
jp_jlb4=new JLabel("找回密码");
jp_jlb4.setFont(f1);//设置"找回密码"字体
jp_jlb4.setForeground(Color.BLUE); //设置"找回密码"字体颜色
jp_jlb4.setBounds(300, 43, 70,25);
String[]s={"在线","隐身","忙碌","离线"}; //设置状态
cb=new JComboBox(s);
cb.setFont(f1);
cb.setBounds(300, 78, 60,21);
jp_jcb1=new JCheckBox("记住密码");
jp_jcb1.setFont(f1);
jp_jcb1.setBounds(114, 78, 90,20);
jp_jcb2=new JCheckBox("自动登录");
jp_jcb2.setFont(f1);
jp_jcb2.setBounds(206, 78, 90,20);
jp_jb1=new JButton("多账号");
jp_jb1.setFont(f1);
jp_jb1.setBounds(10, 120, 76,21);
jp_jb2=new JButton("设置");
jp_jb2.setFont(f1);
jp_jb2.setBounds(95, 120, 65,21);
jp_jb3=new JButton("登录");
jp_jb3.setFont(f1);
jp_jb3.setBounds(297, 120, 65,21);
//添加各个组件
jp.add(jp_jlb1);
jp.add(jp_jtf);
jp.add(jp_jlb4);
jp.add(jp_pw);
jp.add(jp_jlb3);
jp.add(cb);
jp.add(jp_jcb1);
jp.add(jp_jcb2);
jp.add(jp_jb1);
jp.add(jp_jb2);
jp.add(jp_jb3);
this.add(jlb,"North");//标签放到最北部
this.add(jp,BorderLayout.CENTER);// 放到中部
this.setIconImage(new ImageIcon("image/qq.gif").getImage());//设置窗口上的qq小图片
this.setResizable(false);//不允许放大,改变窗口大小等
this.setSize(380,275);
this.setLocation(500,200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
@Override
public void mouseClicked(MouseEvente) {
// TODO Auto-generated method stub
if(e.getSource()==jp_jtf)
{
jp_jtf.setText("");
jp_jtf.setForeground(Color.BLACK);
}
else if(e.getSource()==jp_pw)
{
jp_pw.setText("");
jp_pw.setForeground(Color.BLACK);
jp_pw.setEchoChar('●');
}
}
@Override
public void mousePressed(MouseEvente) {
// TODO Auto-generated method stub
}
@Override
public voidmouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvente) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvente) {
// TODO Auto-generated method stub
}
}
相关阅读:
Android 高仿QQ 界面滑动效果