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

用Java语言对QQ进行终极山寨---晴儿QQ诞生记之操作主界面 QQJavaSwingSUNJDK 

程序员文章站 2022-05-28 18:51:59
...
         好几天没上Javaeye了,最近几天日子一直很忙碌,弄出来一个晴儿QQ的主界面,效果图如下:  
          用Java语言对QQ进行终极山寨---晴儿QQ诞生记之操作主界面
            
    
    
        QQJavaSwingSUNJDK 
         代码如下:
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.border.EmptyBorder;
import com.component.StatusButton;
import com.component.SysButton;
import com.component.TTMenuItem;
import com.component.TTPanel;
import com.component.TTPopupMenu;
import com.componentListener.WinEventAdapter;
import com.componentUI.TScrollBarUI;
import com.sun.awt.AWTUtilities;
import com.uiresource.Resource;
import com.uiutil.UIUtil;
public class TT{
	/**阐述:该文件定义了晴儿QQ聊天软件的操作主界面
	 * 作者:陈阳(JavaEye博客:http://chen6485.iteye.com/)
	 * 说明:开发环境:MyEclipse6.6 JDK版本:Java(TM)SE Development Kit 6 Update 22
	 */
	private static final long serialVersionUID = -7757220015983708063L;
	private JButton close;
	private JButton max;
	private JButton restore;
	private JButton min;
	private JButton sys;
	private JDialog tt;
	private SysButton zone;
	private SysButton mail;
	private SysButton shop;
	private SysButton money;
	private SysButton news;
	private SysButton message;
	private SysButton color;
	private SysButton set;
	private SysButton manageTool;
	private StatusButton sta;
	private JScrollPane sc;
	private Resource res;
	private TTPanel panel;
	private Dimension screen;
	private JLabel userHead;
	private JLabel userNickname;
	private JLabel userSignatrue;
	private JLabel titleIma;
	private TTPopupMenu stat;
	private ImageIcon face;
	private String status;
	private String nick;
	private ImageIcon title;
	public TT(){
		initComponent();
		init();
	}
	public  void init(){
		screen=Toolkit.getDefaultToolkit().getScreenSize();//获取屏幕长宽
		tt=new JDialog(); 
		WinEventAdapter winMove=new WinEventAdapter(tt);
		tt.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 
		tt.setUndecorated(true);//不启用修饰true
		tt.setSize(239,535);
		tt.setAlwaysOnTop(true);
		tt.addMouseListener(winMove);
		tt.addMouseMotionListener(winMove);
		AWTUtilities.setWindowOpaque(tt, false);
		panel=new TTPanel(tt);
		panel.setLayout(null);
		close.setBounds(tt.getWidth()-39, 0, 38, 18);
		max.setBounds(tt.getWidth()-64, 0, 25, 18);
		min.setBounds(tt.getWidth()-89, 0, 25, 18);
		sta.setBounds(60,25,36,23);
		zone.setBounds(7,75,23,23);
		mail.setBounds(35,75, 23, 23);
		shop.setBounds(63,75,23,23);
		money.setBounds(91,75,23,23);
		news.setBounds(119,75,23,23);
		message.setBounds(tt.getWidth()-56,75,23,23);
		set.setBounds(53,tt.getHeight()-28,23,23);
		manageTool.setBounds(80,tt.getHeight()-28,23,23);
		color.setBounds(tt.getWidth()-28,75,23,23);
		sys.setBounds(5,tt.getHeight()-42,41,41);
		sc.setBounds(2, 100,tt.getWidth()-4,tt.getHeight()-160);
		userNickname.setBounds(100,25,tt.getWidth(),20);
		userSignatrue.setBounds(65,46,139, 22);
		userHead.setBounds(15,25,40,40);
		titleIma.setBounds(2, 2, 90, 18);
		panel.add(close);
		panel.add(max);
		panel.add(min);
        panel.add(sta);		
		panel.add(zone);
		panel.add(mail);
		panel.add(shop);
		panel.add(money);
		panel.add(news);
		panel.add(message);
		panel.add(color);
		panel.add(sys);
		panel.add(sc);
		panel.add(set);
		panel.add(manageTool);
		panel.add(userNickname);
		panel.add(userSignatrue);
		panel.add(userHead);
		panel.add(titleIma);
		tt.setContentPane(panel);
		tt.setVisible(true);
		panel.repaint();
		tt.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 
	}
	public void initComponent(){
		title=new ImageIcon(this.getClass().getResource("../image/title.png"));//QQ标题
		titleIma=new JLabel(title);
		userNickname=new JLabel();
		userNickname.setFont(new Font("黑体",Font.PLAIN,14));
		userSignatrue=new JLabel();
		userHead=new JLabel();
		try{
			Properties prop = new Properties();//Properties类表示了一个持久的属性集
			InputStream is = new FileInputStream("User/10001/Info.ini");
			InputStreamReader reader = new InputStreamReader (is,"GBK"); 
			prop.load(reader);
			if (reader!= null){
				status=prop.getProperty("status");//获取登陆状态
				nick=prop.getProperty("nickName");//获取昵称
				userSignatrue.setText(prop.getProperty("sigNatrue"));//获取个性签名
				String s=prop.getProperty("Ico");//获取头像
				face=new ImageIcon(this.getClass().getResource("../image/face/"+ s +".png"));
				reader.close();
			}else{
				System.out.println("无法读取文件");
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		userHead.setIcon(face);
		userNickname.setText(nick+"["+status+"]");
		stat=new TTPopupMenu();//状态选择下拉菜单
		TTMenuItem status1=new TTMenuItem("我在线上",res.onlineIcon);
		TTMenuItem status2=new TTMenuItem("Q我吧",res.tmeIcon);
		TTMenuItem status3=new TTMenuItem("离开",res.awayIcon);
		TTMenuItem status4=new TTMenuItem("忙碌",res.busyIcon);
		TTMenuItem status5=new TTMenuItem("请勿打扰",res.noIcon);
		TTMenuItem status6=new TTMenuItem("隐身",res.hideIcon);
		TTMenuItem status7=new TTMenuItem("离线",res.hideIcon);
		TTMenuItem status8=new TTMenuItem("关闭所有声音",res.hideIcon);
		TTMenuItem status9=new TTMenuItem("锁定晴儿QQ  Ctrl+Alt+L",null);
		TTMenuItem status10=new TTMenuItem("系统设置",null);
		TTMenuItem status11=new TTMenuItem("我的资料",null);
		TTMenuItem status12=new TTMenuItem("我的晴儿QQ中心",null);
		sc=new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);//好友滚动面板
		//sc.getViewport().setView();
		close=UIUtil.creatButton(res.close_normal, res.close_rollover, res.close_press);//关闭按钮
		max=UIUtil.creatButton(res.max_normal, res.max_rollover, res.max_press);//最大化按钮
		restore=UIUtil.creatButton(res.restore_normal, res.restore_rollover, res.restore_press);//还原大小按钮
		min=UIUtil.creatButton(res.min_normal, res.min_rollover, res.min_press);//最小化按钮
		sys=UIUtil.creatButton(res.sys_normal, res.sys_rollover, res.sys_press);//系统按钮
		zone=new SysButton(res.zone);//空间按钮
		mail=new SysButton(res.mail);//邮件按钮
		shop=new SysButton(res.shop);//商城按钮
		money=new SysButton(res.money);//钱包按钮
		news=new SysButton(res.news);//新闻按钮
		message=new SysButton(res.message);//消息按钮
		color=new SysButton(res.color);//颜色按钮
		set=new SysButton(res.set);//系统设置按钮
		manageTool=new SysButton(res.manageTool);//消息管理器按钮
		sta=new StatusButton(res.online,true);
		sc.setBorder(new EmptyBorder(0,0,0,0));
		sc.getVerticalScrollBar().setUI(new TScrollBarUI());//垂直滚动条
		sc.getHorizontalScrollBar().setUI(new TScrollBarUI());//平行滚动条
		stat.add(status1);
		stat.add(status2);
		stat.add(status3);
		stat.add(status4);
		stat.add(status5);
		stat.add(status6);
		stat.add(status7);
		stat.add(status8);
		stat.add(status9);
		stat.add(status10);
		stat.add(status11);
		stat.add(status12);
		status1.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				sta.setNormalImage(res.online);
				userNickname.setText(nick+"[我在线上]");
			}		
		});
		status2.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				sta.setNormalImage(res.tme);
				userNickname.setText(nick+"[Q我吧]");
			}		
		});
		status3.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				sta.setNormalImage(res.away );
				userNickname.setText(nick+"[离开]");
			}		
		});
		status4.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				sta.setNormalImage(res.busy);
				userNickname.setText(nick+"[忙碌]");
			}		
		});
		status5.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				sta.setNormalImage(res.no);
				userNickname.setText(nick+"[请勿打扰]");
			}		
		});
		status6.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				sta.setIcon(res.hideIcon);
				userNickname.setText(nick+"[隐身]");
			}		
		});
		status7.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				//sta.setIcon(res.onlineIcon);
				userNickname.setText(nick+"[隐身]");
			}		
		});
		status8.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
			}		
		});
		status9.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
			}		
		});
		status10.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
			}		
		});
		status11.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
			}		
		});
		status12.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
			}		
		});
		close.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				System.exit(0);
			}	
		});
		max.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				tt.setSize(screen.width,screen.height-30);
				tt.setLocation(0, 0);
				close.setBounds(tt.getWidth()-39, 0, 38, 18);
				panel.remove(max);
				panel.add(restore);
				restore.setBounds(tt.getWidth()-64, 0, 25, 18);
				min.setBounds(tt.getWidth()-89, 0, 25, 18);
				message.setBounds(tt.getWidth()-56, 75, 23, 23);
				color.setBounds(tt.getWidth()-28, 75, 23, 23);
				sys.setBounds(5,tt.getHeight()-42,41,41);
				sc.setBounds(2, 100,tt.getWidth()-4,tt.getHeight()-160);
				set.setBounds(53,tt.getHeight()-28,23,23);
				manageTool.setBounds(80,tt.getHeight()-28,23,23);
			}	
		});
		min.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				tt.setVisible(false);
			}	
		});
		restore.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				tt.setSize(239,535);
				tt.setLocation(0, 0);
				close.setBounds(tt.getWidth()-39,0,38,18);
				panel.remove(restore);
				panel.add(max);
				max.setBounds(tt.getWidth()-64,0,25,18);
				min.setBounds(tt.getWidth()-89,0,25,18);
				message.setBounds(tt.getWidth()-56,75,23,23);
				color.setBounds(tt.getWidth()-28,75,23,23);
				sys.setBounds(5,tt.getHeight()-42,41,41);
				sc.setBounds(2, 100,tt.getWidth()-4,tt.getHeight()-160);
				set.setBounds(53,tt.getHeight()-28,23,23);
				manageTool.setBounds(80,tt.getHeight()-28,23,23);
			}	
		});
		sta.addMouseListener(new MouseAdapter(){//状态选择按钮事件监听
	    	public void mouseClicked(MouseEvent e){
				if(e.getButton()==MouseEvent.BUTTON1){				
					stat.show(e.getComponent(),-5,20);
				}
	    	}
	    });
	}
	public static void main(String args[]){
		UIUtil.setSysFont();
		new TT();
	}
}

         这段代码贴出来多少有点寒酸,就一套号称可以对商用软件“终极”逆向的代码居然就这水平!用一句网络俏皮话来说,这不是在“坑爹”吗?哎!的确,这段代码中至少有三个问题没有解决,第一:字体问题,由AWTUtilities.setWindowOpaque(window, false)定义出来的圆角面板在绘制字体时会出现质量下降的问题,一时半会还真不知道该怎么解决,呜呜。。。。。。第二:好友区实现的问题,这个好友区应该是通过渲染JList来实现的,至于具体怎么实现,我暂时还没有成熟的代码,悲剧。。。。。。第三:组件布局问题,在这个界面中我采用的是绝对定位的办法来定位组件,这也就出现了一个问题,改变大小时无法移动相应的组件,哎!哎!。。。。。。因为没太多的时间去仔细研究这个,暂时只能实现这个,好了,我得去泡个澡澡再来慢慢研究这几个纠结的问题啦,悄悄的,我走了,没带走一行多余的代码。。。。。。
  • 用Java语言对QQ进行终极山寨---晴儿QQ诞生记之操作主界面
            
    
    
        QQJavaSwingSUNJDK 
  • 大小: 22 KB