java 简易版 qq 聊天客户端 -1
这个程序时大一是跟着教学课堂做的,做的有点 low,在学校的局域网内聊天玩的,也可以穿文件(这个当时太懒了,就没有加),拿来分享一下。
第一节 客户端登录界面
不知道为什么就客户端登录界面的注释乱码了 ~~~ 扎心
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import com.angelfate.tools.FileUtils;
/**
*
* @Project: chatClient /ClientLogin.java/com.angelfate.ui
* @Description:企业级聊天登录界面:客户端登录界面
* @author 10406
* @date 2018年4月15日 上午10:08:40
* @company AngelFate
* @return ClientLogin
*/
public class ClientLogin extends JFrame{
private ImageIcon loginLogo = null; // 瀹氫箟涓�涓� 鍥剧墖缁勪欢 绌哄��
private JLabel showLogoLabel = null;
private int width =735,height = 550; // 鍥犱负绐楀彛涓�鏍峰ぇ鏈夎竟绾匡紝鎵�浠� 杩欓噷 璁剧疆澶т竴鐐�
private JLabel userJLabel = null,pwdLabel = null;
private JTextField usernameText = null;
private JPasswordField pwdText = null;
private JButton loginBtn = null,restBtn = null;
private JLabel banquan1 = null,banquan2 = null;
/**
* 璋冪敤鏂规硶
*/
private ClientLogin(){
init();
addCompoent();
addListener();
showFrame();
}
/**
* @Descripition:鍒濆鍖栫粍浠堵�
*/
private void init() {
loginLogo = new ImageIcon(this.getClass().getResource("/images/Logo.png")); // 鍒濆鍖栧浘鐗�
showLogoLabel = new JLabel(loginLogo,JLabel.CENTER); // 鍒濆鍖� JLabel 锛屽苟涓旀妸鍥剧墖鏀惧叆JLabel
/*鍒濆鍖栧墿浣欑粍浠�*/
userJLabel = new JLabel("用户名:");
pwdLabel = new JLabel("密 码:");
usernameText = new JTextField();
pwdText = new JPasswordField();
loginBtn = new JButton(" 登 录 ");
restBtn = new JButton(" 重 置 ");
banquan1 = new JLabel("Copyright © 2018 AngelFate. All Rights Reserved.");
banquan2 = new JLabel("AngelFate公司 版权所有.");
}
/**
* 鎶婂悇绉嶇粍浠跺湪璇ユ柟娉曚腑缁勮
*/
private void addCompoent() {
this.setLayout(null); // 璁剧疆瀹瑰櫒鐨勫竷灞�涓虹┖锛屽嵆娓呴櫎榛樿甯冨眬
this.add(showLogoLabel); // 鎶婄粍浠秙howLogoLabel娣诲姞鍒板鍣�
showLogoLabel.setBounds(0, 0,width-10,173);
this.add(userJLabel);
userJLabel.setBounds(200, 200,80,30); // 瀹氫綅锛歺锛寉锛屽锛岄珮
userJLabel.setForeground(Color.green); // 瀛椾綋棰滆壊
userJLabel.setFont(new Font("",1,17)); // 瀛椾綋澶у皬
this.add(usernameText);
usernameText.setBounds(270,200,200,35);
this.add(pwdLabel);
pwdLabel.setBounds(200,260,80,30);
pwdLabel.setForeground(Color.green);
pwdLabel.setFont(new Font("",1,17));
this.add(pwdText);
pwdText.setBounds(270, 260,200,35);
this.add(loginBtn);
loginBtn.setBounds(230, 330,120,40);
loginBtn.setForeground(Color.orange);
loginBtn.setFont(new Font("黑体",Font.BOLD,19));
this.add(restBtn);
restBtn.setBounds(360, 330,120,40);
restBtn.setForeground(Color.orange);
restBtn.setFont(new Font("黑体",Font.BOLD,19));
this.add(banquan1); // 鐗堟潈
banquan1.setBounds(170, 420,550,30);
banquan1.setFont(new Font("宋体",Font.BOLD,13));
this.add(banquan2);
banquan2.setBounds(290, 450,500,30);
banquan2.setFont(new Font("宋体",Font.BOLD,13));
}
/**
* 缁欑粍浠舵坊鍔犲姛鑳斤紙浜嬩欢锛�
*/
private void addListener() {
// 绐楀彛鍏抽棴浜嬩欢
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//缁欑櫥褰曟寜閽坊鍔犱簨浠�
loginBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String username = usernameText.getText(); // 鑾峰彇鐢ㄦ埛鍚嶆枃鏈鐨勫��
String pwd =pwdText.getText(); // 鑾峰彇pwdText鏂囨湰妗嗙殑鍊�
boolean b = FileUtils.checkLogin(username, pwd); // 鏌ョ湅鐢ㄦ埛鏄惁鐧诲綍鎴愬姛
// 瀵� username 杩涜闀垮害鍒ゆ柇锛岃鍔熻兘绠�鍗�
if(b == true) { // 鐧婚檰鎴愬姛锛屾垚鍔熶箣鍚庯紝璺冲線鑱婂ぉ鐣岄潰
JOptionPane.showMessageDialog(null, "登陆成功");
new ChatClientUI(username); // 鏄剧ず鑱婂ぉ鐣岄潰
ClientLogin.this.dispose(); // 鍏抽棴鐧诲綍绐楀彛
}else { // 鐧诲綍澶辫触
//寮瑰嚭娑堟伅瀵硅瘽妗�
JOptionPane.showMessageDialog(null,"用户名或者密码错误!");
}
}
});
//缁欓噸缃寜閽坊鍔犱簨浠�
restBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { // 娓呯┖涓や釜鏂囨湰妗�
usernameText.setText("");
pwdText.setText("");
}
});
}
/**
* 鏄剧ず绐楀彛
*/
private void showFrame() {
/*璁╃獥鍙d粠灞忓箷涓棿寮瑰嚭*/
int screenWidth = (int)this.getToolkit().getScreenSize().getWidth(); //鑾峰彇灞忓箷瀹藉害
int screenHeight = (int)this.getToolkit().getScreenSize().getHeight();//鑾峰彇灞忓箷楂樺害
int x = (screenWidth-width)/2; // 璁剧疆寮瑰嚭瀹藉害鍧愭爣
int y = (screenHeight-height)/2;
this.setLocation(x, y);
this.setSize(width, height);
this.setTitle("企业级聊天登录界面:客户端登录界面");
this.setVisible(true);
this.setResizable(false); // 绂佹绐楀彛缂╂斁
}
public static void main(String[] args) {
new ClientLogin();
}
}
😭 想到贴还没发,看了看存档,java 的易看的懂存档多点,就整理一下分享分享 ~~