欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

用Java语言对QQ进行终极山寨---晴儿QQ诞生记之正在登录界面 QQJavaSwingJDKSUN 

程序员文章站 2022-07-08 09:27:45
...
         今天星期六,呵呵~难得有一天的清闲,那就让我们继续我们的QQ终极逆向吧!前面几章我们已经成功的实现了一个登录界面,登陆界面完成后就是正在登录界面了,上午花了一上午的时间,终于弄出了一种大致的效果出来,还是老规矩,效果图如下:  
          用Java语言对QQ进行终极山寨---晴儿QQ诞生记之正在登录界面
            
    
    
        QQJavaSwingJDKSUN 
         正在登录界面我采用了完全绘制的办法直接绘制出圆角矩形JPanel,然后就是添加其中组件,我采用了GroupLayout组布局,实现了把我需要的组件添加到界面上,代码如下:
         
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.GroupLayout.Alignment;
import com.componentListener.WinEventAdapter;
import com.sun.awt.AWTUtilities;
import com.uiutil.UIUtil;
public class LoginingFrame{
	/**阐述:该文件定义了晴儿QQ即时通软件的正在登录界面
	 * 作者:陈阳(JavaEye博客:http://chen6485.iteye.com/)
	 * 说明:开发环境:MyEclipse6.6 JDK版本:Java(TM)SE Development Kit 6 Update 22
	 */
	public LoginFrame u;
	private static final long serialVersionUID = -3291651336702369751L;
	private JDialog Logining=new JDialog();
	private LoginPanel panel=new LoginPanel();
	private ImageIcon cancel_normal=new ImageIcon(this.getClass().getResource("../image/SysButton/cancel_normal.png"));
	private ImageIcon cancel_rollover=new ImageIcon(this.getClass().getResource("../image/SysButton/cancel_rollover.png"));
	private ImageIcon cancel_press=new ImageIcon(this.getClass().getResource("../image/SysButton/cancel_pressed.png"));
	private ImageIcon pic_login=new ImageIcon(this.getClass().getResource("../image/logining.gif"));//正在登录图片
	private ImageIcon title=new ImageIcon(this.getClass().getResource("../image/title1.png"));//QQ标题
	private ImageIcon top=new ImageIcon(this.getClass().getResource("../image/top.png"));//QQ标题栏
	private Image titleImage=title.getImage();
	private Image topImage=top.getImage();
	private JLabel lab_pic=new JLabel(pic_login);
	private JLabel lab_account=new JLabel();//正在登录的账号标签
	private JLabel lab_welcome=new JLabel("尊敬的晴儿QQ用户,欢迎你回来");//欢迎登录标签
	private JButton cancel=UIUtil.creatButton(cancel_normal, cancel_rollover, cancel_press);
	private WinEventAdapter winMove=new WinEventAdapter(Logining);//注册移动位置监听;
	public LoginingFrame(){
		initComponent();
		init();
	}
	public void init(){
		Logining.setUndecorated(true);
		Logining.setContentPane(panel);
		AWTUtilities.setWindowOpaque(Logining, false);
		Logining.setSize(239,535);
		Logining.setVisible(true);
		Logining.addMouseListener(winMove);
		Logining.addMouseMotionListener(winMove);
		Logining.getRootPane().setDefaultButton(cancel);
	}
	public void initComponent(){
		lab_account.setText(u.name);
		GroupLayout gro=new GroupLayout(panel);//实例化布局方式
		panel.setLayout(gro);
		gro.setAutoCreateGaps(true);
		gro.setAutoCreateContainerGaps(true);
		GroupLayout.SequentialGroup xgroup = gro.createSequentialGroup();
		xgroup.addGroup(gro.createParallelGroup(Alignment.CENTER).addComponent(lab_pic).addComponent(lab_account).addComponent(lab_welcome).addComponent(cancel)); 	
		gro.setHorizontalGroup(xgroup);//添加平行放置的组件
		GroupLayout.SequentialGroup ygroup=gro.createSequentialGroup();
		ygroup.addGroup(gro.createParallelGroup(Alignment.CENTER).addGap(90));
		ygroup.addGroup(gro.createParallelGroup(Alignment.CENTER).addComponent(lab_pic));
		ygroup.addGroup(gro.createParallelGroup(Alignment.CENTER).addComponent(lab_account));
		ygroup.addGroup(gro.createParallelGroup(Alignment.CENTER).addComponent(lab_welcome));
		ygroup.addGroup(gro.createParallelGroup(Alignment.CENTER).addGap(50));
		ygroup.addGroup(gro.createParallelGroup(Alignment.CENTER).addComponent(cancel));
		gro.setVerticalGroup(ygroup);//添加垂直放置的组件
		cancel.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				stopLogin();
			}		
		});
	}
	public void stopLogin(){
		System.exit(0);
	}
	private class LoginPanel extends JPanel{
		private static final long serialVersionUID=-72456689714251903L;
		protected void paintComponent(Graphics g){
			super.paintComponent(g);
			Graphics2D g2 =(Graphics2D)g;
			g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);//使用抗锯齿
			g2.setColor(new Color(214,238,255));
			g2.fillRoundRect(0,0,Logining.getWidth(),Logining.getHeight(),8,8);//用上面的颜色绘制填充整个JDialog
			g2.setColor(new Color(0,81,149));
			g2.drawRoundRect(0,0, Logining.getWidth()-1, Logining.getHeight()-1, 8,8);//用上面的颜色绘制填充最外层的边缘
			g2.setColor(new Color(158,249,255));
			g2.drawRoundRect(1, 1, Logining.getWidth()-3, Logining.getHeight()-3,8,8);//用上面的颜色绘制填充第二个外边缘
			g2.drawImage(topImage, 1, 1, Logining.getWidth()-2, 27, null);
			g2.drawImage(titleImage,3,4,null);
		}
	} 
}

            通过以上代码,我们基本完成了正在登录界面,正在登录界面完成之后就是聊天软件主界面了,好吧,从下一章开始我们一起开始聊天主界面的完成吧!

     
  • 用Java语言对QQ进行终极山寨---晴儿QQ诞生记之正在登录界面
            
    
    
        QQJavaSwingJDKSUN 
  • 大小: 28.3 KB