clientload.java

来自「java做的局域网仿QQ聊天室,登陆界面等都是仿QQ程序」· Java 代码 · 共 242 行

JAVA
242
字号

import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;

public class ClientLoad extends JFrame
implements ActionListener,KeyListener,MouseListener
{
	private ServerSocket server;
	private Socket client;
	private BufferedReader cin;
    private PrintWriter cout;
    
    private Thread chart=null;
    
    
	//以下为GUI设计的变量声明
	static  ClientLoad clientload;
	private int door=1;
	
	private ImageIcon imageicon1=new ImageIcon("images/whiteurl.gif");
	
	private Font font1=new Font("宋体",Font.PLAIN,12);
	private  JLabel label=new JLabel("");
	private  JLabel label1=new JLabel("QQ帐号");
	private  JLabel label2=new JLabel("  申请号码");
	private  JLabel label3=new JLabel("QQ密码");
	private  JLabel label4=new JLabel("  忘了密码?");
	private  JLabel label5=new JLabel("状态:  ");
	private  JLabel label6=new JLabel("服务器IP:");
	private  JLabel label7=new JLabel("端口:");
	private  JLabel label8=new JLabel("版权所有@克格勃工作中心   张建法制作");
	
	public  static JComboBox username=new JComboBox();
	public  static JPasswordField password=new JPasswordField();
	public  static JTextField ServerIP=new JTextField("localhost");
	public  static JTextField ServerPort=new JTextField("8888");
	
	private  JButton jbtState=new JButton("在线");
	private  JButton jbtCheck=new JButton("查杀",imageicon1);
	private  JButton jbtSet=new JButton("设置");
	private  JButton jbtLogin=new JButton("登录");
	
	private  JCheckBox jcbAutoLogin=new JCheckBox("自动登录");
	
	private  JPanel jpMain=new JPanel();
	private  JPanel jpButton=new JPanel();
	private  JPanel jpAll=new JPanel(null);
	private  JPanel jpServer=new JPanel(null);
	private  JPanel jpInfo=new JPanel();
		
	private  ImagePanel image=new ImagePanel("images/qq.jpg");
	Container container=getContentPane();

	public ClientLoad()
	{
		super("QQ用户登录");
		
		AddButton();
		AddMain();
	    AddServer();
	    AddInfo();
	    this.setSize(332,248);
	    
		jpAll.setBackground(new Color(225,245,253));
		image.setSize(327,48);
		image.setLocation(0,0);
		jpAll.add(image);
		jpMain.setSize(317,113);
		jpMain.setLocation(5,57);
		jpAll.add(jpMain);
		jpButton.setSize(317,25);
		jpButton.setLocation(5,180);
		jpAll.add(jpButton);
		jpServer.setSize(317,80);
		jpServer.setLocation(5,220);
		jpAll.add(jpServer);
		jpInfo.setSize(317,40);
		jpInfo.setLocation(20,320);
		jpAll.add(jpInfo);
		container.add(jpAll,BorderLayout.CENTER);
		
		this.setResizable(false);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setLocationRelativeTo(null);
		this.setVisible(true);
	}
	public void AddInfo()
	{
		jpInfo.setBackground(new Color(225,245,253));
		jpInfo.add(label8);
		
	}
	public void AddServer()
	{
		jpServer.setBackground(new Color(225,245,253));
		jpServer.setLayout(new GridLayout(2,2,10,10));
		jpServer.add(label6);
		jpServer.add(ServerIP);
		jpServer.add(label7);
		ServerPort.setEditable(false);
		jpServer.add(ServerPort);
		jpServer.setBorder(new TitledBorder("服务器设置"));
	}
	public void AddButton()
	{
		jpButton.setBackground(new Color(225,245,253));
		jpButton.setLayout(new GridLayout(1,4,5,10));
		jbtCheck.setFont(font1);
		jbtCheck.setHorizontalAlignment(JButton.RIGHT);
		jpButton.add(jbtCheck);
		jbtSet.setFont(font1);
		jbtSet.addActionListener(this);
		jbtSet.addMouseListener(this);
		jpButton.add(jbtSet);
		jpButton.add(label);
		jbtLogin.setFont(font1);
		jbtLogin.addActionListener(this);
		jbtLogin.addMouseListener(this);
		jpButton.add(jbtLogin);
	}
	public void AddMain()
	{
		
		jpMain.setBackground(new Color(241,250,255));
		jpMain.setLayout(new GridLayout(3,3,0,20));
		label1.setHorizontalAlignment(JLabel.CENTER);
		label1.setFont(font1);
		jpMain.add(label1);
		username.setEditable(true);
		jpMain.add(username);
		label2.setFont(font1);
		label2.setForeground(Color.BLUE);
		label2.addMouseListener(this);
		jpMain.add(label2);
		label3.setHorizontalAlignment(JLabel.CENTER);
		label3.setFont(font1);
		jpMain.add(label3);
		password.addKeyListener(this);
		jpMain.add(password);
		label4.setFont(font1);
		label4.setForeground(Color.BLUE);
		label4.addMouseListener(this);
		jpMain.add(label4);
		label5.setHorizontalAlignment(JLabel.RIGHT);
		label5.setFont(font1);
		jpMain.add(label5);
		jbtState.setBackground(new Color(241,250,255));
		jbtState.setFont(font1);
		jpMain.add(jbtState);
		jcbAutoLogin.setBackground(new Color(241,250,255));
		jcbAutoLogin.setFont(font1);
		jpMain.add(jcbAutoLogin);
		jpMain.setBorder(new TitledBorder(""));
	}
	
	public void stop()
	{
		this.setVisible(false);
	}
	//以下为ActionListenner接口
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==jbtLogin)
		{
				
				ClientMainFrm clientmainfrm=new ClientMainFrm();
				stop();	
		}
		else if(e.getSource()==jbtSet)
		{
			if(door==1) 
			{
				this.setSize(332,380);
				door=0;
			}
			else if(door==0)
			{
				this.setSize(332,248);
				door=1;
			}
	    }
	    else if(e.getSource()==label2)
	    {
	    	AddUser adduser=new AddUser();
	    }
	  }
	  //以下为KeyListenner接口
	  public void keyReleased(KeyEvent e)
	  {
	  	
	  }
	  public void keyTyped(KeyEvent e)
	  {
	  	
	  }
	  public void keyPressed(KeyEvent e)
	  {	
	  	if(e.getKeyCode()==KeyEvent.VK_ENTER)
	  	{
	  		
	  		ClientMainFrm clientmainfrm=new ClientMainFrm();
			stop();	
	  	}
	  }
	//以下为MouseListenner接口
	public void mouseClicked(MouseEvent e)
	{
		if(e.getSource()==label2)
		{
			AddUser adduser=new AddUser();
			
		}
		else if(e.getSource()==label4)
		{
			FindPassword findpassword=new FindPassword();
		}
	}
	public void mousePressed(MouseEvent e){}
	public void mouseReleased(MouseEvent e){}
	public void mouseEntered(MouseEvent e)
	{
		this.setCursor(new Cursor(Cursor.HAND_CURSOR));
	}
	public void mouseExited(MouseEvent e)
	{
		this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
	}
	public static void main(String [] args)
	{
		ClientLoad clientload=new ClientLoad();	
	}
}




  

⌨️ 快捷键说明

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