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

📄 userlogining.java

📁 注:语音聊天部分还未完成
💻 JAVA
字号:
package com.gamvan.club.users.im.userlogin;import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.net.Socket;import java.net.UnknownHostException;import javax.swing.JOptionPane;import javax.swing.JRadioButton;public class UserLogining {	/**	 * 连接数据库的接口类	 * */	private String userName = "";	private String userPass;	private JRadioButton loginStyle3 = null;	public Socket clientSocket = null;	private ObjectInputStream dataIn = null;	private ObjectOutputStream dataOut = null;      	public boolean isLogin() {				            boolean checkResult = false;            if((!getUserName().equals(""))&&(!getUserPass().equals(""))){                connect();//连接到服务器		       		                                                try {                                                                  dataOut.writeObject(getUserName());				                                                                                          dataOut.flush();				                                                                                         dataOut.writeObject(getUserPass());				                                                                                         dataOut.flush();	    	                                  String check = (String)dataIn.readObject();	                       if(check.equalsIgnoreCase("success")){					                                 if(!loginStyle3.isSelected()){						                                                   checkResult = true;					                                            }else{						                                                  checkResult = false;					                                          }			                                    }else if(check.equalsIgnoreCase("successAdmin")){				                                            if(loginStyle3.isSelected()){						                                                   checkResult = true;					                                           }else{						                                                checkResult = false;					                                           }				                                   }else if(check.equalsIgnoreCase("fail")){					                                            checkResult = false;				                                  }							                           } catch (IOException e) {				                                                e.printStackTrace();			                            } catch (ClassNotFoundException e) {				                                  e.printStackTrace();			                           }                     }		               clientSocket = null;			               return checkResult;            	}	private void connect(){		try {			getClientSocket();//连接			getDataIn();//获得套结字输入流			getDataOut();//获得套结字输出流			//发送登陆标识			dataOut.writeObject("login");			dataOut.flush();								} catch (UnknownHostException e) {			 JOptionPane.showMessageDialog(null,"连接服务器出错!!",	                    "系统错误",JOptionPane.ERROR_MESSAGE);	        System.exit(0);		} catch (IOException e) {			 JOptionPane.showMessageDialog(null,"连接服务器出错!!",	                    "系统错误",JOptionPane.ERROR_MESSAGE);	        System.exit(0);		}			}	public Socket getClientSocket() throws UnknownHostException, IOException{		clientSocket = new Socket("192.168.1.111",6544);		return clientSocket;	}	private ObjectInputStream getDataIn() throws IOException{		dataIn = new ObjectInputStream(clientSocket.getInputStream());		return dataIn;			}	private ObjectOutputStream getDataOut() throws IOException{		dataOut = new ObjectOutputStream(clientSocket.getOutputStream());		return dataOut;	}	public String getUserName() {		return userName;			}	public void setUserName(String userName) {		this.userName = userName;			}	public String getUserPass() {		return userPass;			}	public void setUserPass(String userPass) {		this.userPass = userPass;	}	/**	 * 这个方法主要用来接收传递进来的管理员登陆但选按钮的状态,如果选中则检测是不是管理员	 * 如果没选中则检测是不是会员或者过客	 */	public void recevObject(JRadioButton loginStyle3){		this.loginStyle3 = loginStyle3;	}}

⌨️ 快捷键说明

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