java 山寨QQ 实现(一)

By EvilBinary 小E

先看界面

//登录对话框代码

package org.evilbinary.client.ui;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

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

import org.evilbinary.client.QQClient;

public class LoginDialog extends JDialog {
	protected JTextField userName;
	protected JPasswordField userPwd;
	protected boolean isLogin;
	protected QQClient client;
	public LoginDialog() {
		createUI();
		isLogin = false;
		client=null;
		this.setModal(true);

	}

	private void createUI() {
		// this.setFont(MainFrame.font);
		this.setTitle("小E机器人");
		this.setIconImage(this.getToolkit().getImage("image/icon.png"));
		this.setResizable(false);
		this.setSize(340, 250);
		this.setLayout(null);
		JPanel topPanel = new JPanel();
		JPanel midPanel = new JPanel();
		JPanel bottomPanel = new JPanel();
		this.add(topPanel);
		this.add(midPanel);
		this.add(bottomPanel);

		topPanel.setBounds(0, 0, 340, 60);
		// topPanel.setBackground(new Color(245, 237, 253));
		midPanel.setBounds(0, 60, 340, 120);
		// midPanel.setBackground(new Color(100,137,153));
		bottomPanel.setBounds(0, 180, 340, 30);
		// top
		JLabel logo = new JLabel(new ImageIcon("image/logo.gif"));
		logo.setBounds(0, 0, 340, 60);
		this.add(logo);
		// mid
		midPanel.setLayout(new FlowLayout(1, 10, 13));
		userName = new JTextField(13);
		userPwd = new JPasswordField(13);
		userName.setText("10394709");
		userPwd.setText("xxxxxxxxxx");
		userName.setSize(200, 100);
		userName.setBounds(0, 0, 120, 130);
		userPwd.setSize(100, 30);
		JLabel register = new JLabel("申请账号  ");
		register.setCursor(new Cursor(Cursor.HAND_CURSOR));
		register.setForeground(Color.blue);
		JLabel forget = new JLabel("忘了密码?");
		forget.setCursor(new Cursor(Cursor.HAND_CURSOR));
		forget.setForeground(Color.blue);
		midPanel.add(new JLabel("帐号:"));
		midPanel.add(userName);
		midPanel.add(register);
		midPanel.add(new JLabel("密码:"));
		midPanel.add(userPwd);
		midPanel.add(forget);

		JComboBox status = new JComboBox();
		status.addItem("在线");
		status.addItem("Q我");
		status.addItem("离开");
		status.addItem("忙碌");
		status.addItem("勿扰");
		status.addItem("隐身");
		JCheckBox remember = new JCheckBox("记住密码");
		JCheckBox auto = new JCheckBox("自动登录");
		midPanel.add(status);
		midPanel.add(remember);
		midPanel.add(auto);

		// bottom
		bottomPanel.setLayout(null);
		JButton setBtn = new JButton("设置");
		setBtn.setBounds(15, 8, 70, 22);
		JButton loginBtn = new JButton("登录");
		loginBtn.setBounds(250, 8, 70, 22);
		bottomPanel.add(setBtn);
		bottomPanel.add(loginBtn);
		loginBtn.addActionListener(new LoginActionListerner());
		JLabel bottom = new JLabel();
		bottom.setForeground(new Color(191, 225, 249));
		bottom.setBounds(0, 190, 340, 60);
		this.add(bottom);

		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		this.setAlwaysOnTop(true);
	}

	public class LoginActionListerner implements ActionListener {

		public void actionPerformed(ActionEvent event) {
			String userName=LoginDialog.this.userName.getText().trim();
			String passWord=new String(LoginDialog.this.userPwd.getPassword());
//			System.out.println(userName);
//			System.out.println(passWord);
			LoginDialog.this.isLogin=true;
			if(userName.equals("")){ 
				JOptionPane.showMessageDialog(LoginDialog.this, "请您输入账户再登录","Error",0);
			}else{
				if(passWord.equals("")){
					JOptionPane.showMessageDialog(LoginDialog.this, "请输入密码再登录","Error",0);
				}else{
					client=new QQClient(userName,passWord,"?");
					if(client.login()){	
						LoginDialog.this.setVisible(false);
					}else{
						LoginDialog.this.setVisible(true);
					}
				}
			}
			
		}
	}

	public void showDialog() {
		this.setVisible(true);
	}
}

//皮肤是用 com.seaglasslookandfeel   http://code.google.com/p/seaglass/ 这里下载

//皮肤使用方法代码如下

	try {
				UIManager.setLookAndFeel(new SeaGlassLookAndFeel());
				// UIManager.getLookAndFeelDefaults().put("defaultFont", new
				// Font("Microsoft Yahei", Font.PLAIN, 12));
				MainFrame frame = new MainFrame();
			} catch (UnsupportedLookAndFeelException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}



  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值