⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 login.java

📁 这个QQ通信系统项目是我之前发过类似的一个大的整合
💻 JAVA
字号:
package client;

import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Toolkit;
import java.awt.Rectangle;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JComboBox;
import javax.swing.JPasswordField;
import javax.swing.JCheckBox;
import javax.swing.JButton;
import java.awt.Font;

import javax.swing.SwingConstants;
import javax.swing.BorderFactory;

public class Login extends JFrame {

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	private JLabel jLabel = null;

	private JLabel jLabel1 = null;

	private JLabel QQ密码 = null;

	private JPasswordField jPasswordField = null;

	private JLabel jLabel4 = null;

	private JComboBox jComboBox1 = null;

	private JCheckBox jCheckBox = null;

	private JLabel jLabel5 = null;

	private JButton jButton2 = null;

	private JPanel jPanel = null;

	private JComboBox jComboBox = null;

	private JLabel jLabel2 = null;

	private JLabel jLabel3 = null;

	private JLabel jLabel6 = null;

	private JButton jButtonqx = null;

	private Controller controller = null;

	private Register register = null;

	private int n = 0;

	/**
	 * This is the default constructor
	 */
	public Login() {
		super();
		initialize();
		controller = new Controller(this);
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setResizable(false);
		this.setBounds(new Rectangle(350, 200, 331, 237));
		this.setBackground(Color.gray);
		this.setForeground(new Color(255, 102, 255));
		this.setIconImage(Toolkit.getDefaultToolkit().getImage(
				getClass().getResource("/picture/1108.gif")));
		this.setContentPane(getJContentPane());
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setTitle("QQ用户登录");
		this.setVisible(true);
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabel5 = new JLabel();
			jLabel5.setBounds(new Rectangle(226, 135, 48, 18));
			jLabel5.setFont(new Font("Dialog", Font.PLAIN, 12));
			jLabel5.setText("自动登录");
			jLabel4 = new JLabel();
			jLabel4.setBounds(new Rectangle(65, 135, 38, 18));
			jLabel4.setFont(new Font("Dialog", Font.PLAIN, 12));
			jLabel4.setText("状态:");
			QQ密码 = new JLabel();
			QQ密码.setBounds(new Rectangle(15, 96, 50, 20));
			QQ密码.setFont(new Font("Dialog", Font.PLAIN, 12));
			QQ密码.setText("QQ密码 ");
			jLabel1 = new JLabel();
			jLabel1.setBounds(new Rectangle(15, 57, 50, 20));
			jLabel1.setFont(new Font("Dialog", Font.PLAIN, 12));
			jLabel1.setText("QQ帐号");
			jLabel = new JLabel();
			jLabel.setIcon(new ImageIcon(getClass().getResource(
					"/picture/about.gif")));
			jLabel.setBounds(new Rectangle(-2, -3, 327, 43));
			jLabel.setText("");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.setBackground(new Color(225, 245, 252));
			jContentPane.add(jLabel, null);
			jContentPane.add(jLabel1, null);
			jContentPane.add(QQ密码, null);
			jContentPane.add(getJPasswordField(), null);
			jContentPane.add(jLabel4, null);
			jContentPane.add(jLabel5, null);
			jContentPane.add(getJButton2(), null);
			jContentPane.add(getJPanel(), null);
			jContentPane.add(getJButtonqx(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jPasswordField
	 * 
	 * @return javax.swing.JPasswordField
	 */
	private JPasswordField getJPasswordField() {
		if (jPasswordField == null) {
			jPasswordField = new JPasswordField();
			jPasswordField.setBounds(new Rectangle(81, 96, 140, 20));
		}
		return jPasswordField;
	}

	/**
	 * This method initializes jComboBox1
	 * 
	 * @return javax.swing.JComboBox
	 */
	private JComboBox getJComboBox1() {
		if (jComboBox1 == null) {
			jComboBox1 = new JComboBox();
			jComboBox1.addItem("在线");
			jComboBox1.addItem("隐身");
			jComboBox1.addItem("离线");
			jComboBox1.setFont(new Font("Dialog", Font.PLAIN, 12));
			jComboBox1.setBounds(new Rectangle(118, 93, 55, 18));
			jComboBox1.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					n = jComboBox1.getSelectedIndex();
					if (n == 0) {
						jLabel6.setIcon(new ImageIcon(getClass().getResource(
								"/picture/online.gif")));
					}
					if (n == 1) {
						jLabel6.setIcon(new ImageIcon(getClass().getResource(
								"/picture/qme.gif")));
					}
					if (n == 2) {
						jLabel6.setIcon(new ImageIcon(getClass().getResource(
								"/picture/nobother.gif")));
					}
				}
			});
		}
		return jComboBox1;
	}

	/**
	 * This method initializes jCheckBox
	 * 
	 * @return javax.swing.JCheckBox
	 */
	private JCheckBox getJCheckBox() {
		if (jCheckBox == null) {
			jCheckBox = new JCheckBox();
			jCheckBox.setBounds(new Rectangle(200, 94, 18, 17));
		}
		return jCheckBox;
	}

	/**
	 * This method initializes jButton2
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getJButton2() {
		if (jButton2 == null) {
			jButton2 = new JButton();
			jButton2.setFont(new Font("Dialog", Font.BOLD, 12));
			jButton2.setPreferredSize(new Dimension(60, 28));
			jButton2.setBounds(new Rectangle(238, 175, 73, 23));
			jButton2.setIcon(new ImageIcon(getClass().getResource(
					"/picture/button4.jpg")));
			jButton2.setHorizontalTextPosition(SwingConstants.CENTER);
			jButton2.setText("登录");
			jButton2.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					String qq = jComboBox.getSelectedItem().toString();
					String password = String.valueOf(jPasswordField
							.getPassword());
					controller.login(qq, password, n);
				}

			});
		}
		return jButton2;
	}

	/**
	 * This method initializes jPanel
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			jLabel6 = new JLabel();
			jLabel6.setBounds(new Rectangle(101, 93, 18, 18));
			jLabel6.setIcon(new ImageIcon(getClass().getResource(
					"/picture/online.gif")));
			jLabel6.setText("");
			jLabel3 = new JLabel();
			jLabel3.setFont(new Font("Dialog", Font.PLAIN, 12));
			jLabel3.setForeground(new Color(51, 51, 255));
			jLabel3.setBounds(new Rectangle(235, 57, 65, 20));
			jLabel3.setText("忘了密码?");
			jLabel3.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseExited(java.awt.event.MouseEvent e) {
					jLabel3.setForeground(Color.BLUE);
				}
			});
			jLabel3
					.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
						public void mouseMoved(java.awt.event.MouseEvent e) {
							jLabel3.setForeground(Color.RED);
						}
					});
			jLabel2 = new JLabel();
			jLabel2.setBounds(new Rectangle(235, 17, 57, 20));
			jLabel2.setFont(new Font("Dialog", Font.PLAIN, 12));
			jLabel2.setForeground(new Color(51, 51, 255));
			jLabel2.setText("申请帐号");
			jLabel2.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseExited(java.awt.event.MouseEvent e) {
					jLabel2.setForeground(Color.BLUE);
				}

				public void mouseClicked(java.awt.event.MouseEvent e) {
					Login.this.setVisible(false);// 关闭登录界面,进入注册界面
					register = new Register(Login.this, controller);
				}
			});
			jLabel2
					.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
						public void mouseMoved(java.awt.event.MouseEvent e) {
							jLabel2.setForeground(Color.RED);
						}
					});
			jPanel = new JPanel();
			jPanel.setLayout(null);
			jPanel.setBackground(new Color(241, 250, 255));
			jPanel.setBorder(BorderFactory.createLineBorder(new Color(153, 204,
					255), 1));
			jPanel.setBounds(new Rectangle(2, 42, 320, 125));
			jPanel.add(getJComboBox(), null);
			jPanel.add(jLabel2, null);
			jPanel.add(jLabel3, null);
			jPanel.add(getJComboBox1(), null);
			jPanel.add(getJCheckBox(), null);
			jPanel.add(jLabel6, null);
		}
		return jPanel;
	}

	/**
	 * This method initializes jComboBox
	 * 
	 * @return javax.swing.JComboBox
	 */
	private JComboBox getJComboBox() {
		if (jComboBox == null) {
			jComboBox = new JComboBox();
			jComboBox.setBounds(new Rectangle(80, 16, 140, 20));
			jComboBox.setFont(new Font("Dialog", Font.PLAIN, 12));
			jComboBox.setToolTipText("提示!!输入帐号只能为数字,且长度在6到12位");
			jComboBox.setEditable(true);
		}
		return jComboBox;
	}

	/**
	 * This method initializes jButtonqx
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getJButtonqx() {
		if (jButtonqx == null) {
			jButtonqx = new JButton();
			jButtonqx.setBounds(new Rectangle(15, 175, 73, 23));
			jButtonqx.setPreferredSize(new Dimension(60, 28));
			jButtonqx.setHorizontalTextPosition(SwingConstants.CENTER);
			jButtonqx.setIcon(new ImageIcon(getClass().getResource(
					"/picture/button4.jpg")));
			jButtonqx.setText("取消");
			jButtonqx.setFont(new Font("Dialog", Font.BOLD, 12));
			jButtonqx.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.exit(0);
				}
			});
		}
		return jButtonqx;
	}

	public Register getRegister() { // 该方法在parseEmbody(Object)中被调用!
		return register;
	}

	public static void main(String[] args) {
		new Login();
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -