📄 服务器界面.java
字号:
/*
* 服务器界面.java
*
* Created on 2007年4月26日, 下午9:53
*/
package 服务器端程序包;
import java.awt.Color;
import java.io.*;
import java.net.*;
import java.sql.*;
import java.util.*;
import java.sql.*;
/**
*
* @author 王绿春 南昌大学软件学院04级5班
*/
public class 服务器界面 extends javax.swing.JFrame {
/** Creates new form 服务器界面 */
public 服务器界面() throws SQLException, ClassNotFoundException {
initComponents();
ClientList=new String[100];
int i=0;
ResultSet ResultData=new UpdatePersonalInformation().QueryMember();
while(ResultData.next()){
ClientList[i]=ResultData.getString("QQNumber")+ResultData.getString("NickName");
i++;
Length++;
}
所有用户.setListData(ClientList);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
InformationText = new javax.swing.JTextArea();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
消息框 = new javax.swing.JLabel();
jScrollPane2 = new javax.swing.JScrollPane();
所有用户 = new javax.swing.JList();
jLabel3 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("QQ\u804a\u5929\u670d\u52a1\u5668");
setResizable(false);
InformationText.setColumns(20);
InformationText.setRows(5);
jScrollPane1.setViewportView(InformationText);
jLabel1.setText("\u5728\u7ebf\u7528\u6237\uff1a");
jLabel2.setFont(new java.awt.Font("宋体", 1, 36));
jLabel2.setForeground(new java.awt.Color(0, 0, 153));
jLabel2.setText("QQ\u804a\u5929\u670d\u52a1\u5668");
jButton1.setText("\u5237\u65b0");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton1MouseClicked(evt);
}
});
jButton2.setText("\u5173\u95ed");
jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton2MouseClicked(evt);
}
});
jScrollPane2.setViewportView(所有用户);
jLabel3.setText("\u6240\u6709\u7528\u6237\uff1a");
org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(122, 122, 122)
.add(jLabel2)
.addContainerGap())
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
.add(86, 86, 86)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(org.jdesktop.layout.GroupLayout.LEADING, 消息框, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 318, Short.MAX_VALUE)
.add(jPanel1Layout.createSequentialGroup()
.add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 93, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 133, Short.MAX_VALUE)
.add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 92, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.add(95, 95, 95))
.add(jPanel1Layout.createSequentialGroup()
.add(34, 34, 34)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 122, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(21, 21, 21)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel3)
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap(22, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jLabel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel3))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 183, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jButton1)
.add(jButton2))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(消息框, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 26, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
// TODO 将在此处添加您的处理代码:
System.exit(0);
}//GEN-LAST:event_jButton2MouseClicked
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
// TODO 将在此处添加您的处理代码:
String s="";
int i=0;
for(i=0;i<clientOnlineList.GetLength();i++){
s=s+clientOnlineList.GetMember(i).GetNumber()+"\n";
}
System.out.println("用户"+s);
InformationText.setText(s);
InformationText.setDisabledTextColor(Color.red);
InformationText.setEnabled(false);
}//GEN-LAST:event_jButton1MouseClicked
/**
* @param args the command line arguments
*/
public static void main(String args[]) throws SQLException, ClassNotFoundException
{
服务器界面 ServerFrame=new 服务器界面(); //初始化服务器界面
ServerFrame.setVisible(true); //设置服务器初始化界面可见
ServerFrame.setBounds(450,220,520,400); //设置默认的窗口和它的大小
ServerSocket serverSocket=null; //定义服务器端套接字
Socket clientSocket=null; //定义客户端套接字
clientOnlineList=new OnLineListArray(); //初始化在线列表
try{
serverSocket=new ServerSocket(6666); //创建服务器端套接字
}
catch(IOException e){
System.out.println(e);
}
System.out.println(".....Server is running.....");
ServerFrame.消息框 .setText("服务器正在运行中......");
ServerFrame.InformationText.setEditable(false); //使列表框处于不可编辑状态
while(true)
{
try{
clientSocket=serverSocket.accept(); //侦听客户端连接请求
}
catch(IOException e)
{
System.err.println(e);
}
if(clientSocket!=null){
ServerThreadForClient clientThread=new ServerThreadForClient(clientSocket);
clientThread.start();
}
else{
continue;
}
}
/*ServerFrame.IformationText.setLineWrap(true);
try {
AccessDatabase DataBase=new AccessDatabase();
String sql="select * from QQClientInformation";
ResultSet ResultData=DataBase.ExecuteSelect(sql);
int count=0;
while(ResultData.next())
{
count++;
/*ServerFrame.IformationText.setText("在 线 号 码:");
ServerFrame.IformationText.append(ResultData.getString("QQNumber"));
ServerFrame.IformationText.append(ResultData.getString("QQPassword"));
ServerFrame.IformationText.append(ResultData.getString("NickName"));
System.out.println("--------------记录号--------------");
System.out.println("QQ号码:"+ResultData.getString("QQNumber"));
System.out.println("QQ密码:"+ResultData.getString("QQPassword"));
System.out.println("呢 称:"+ResultData.getString("NickName"));
System.out.println("真实姓名:"+ResultData.getString("TrueName"));
System.out.println("性 别:"+ResultData.getString("Sex"));
System.out.println("年 龄:"+ResultData.getString("Age"));
System.out.println("留 言:"+ResultData.getString("LeavingInformation"));
}
if(count==0)
{
System.out.println("目前没有记录");
}
} catch (SQLException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
*/
/* while(true){
try{
Socket clientSocket=serverSocket.accept();
BufferedReader in=new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
String t=in.readLine();
if(!t.startsWith("253283126")){
String r="N";
PrintWriter ps=new PrintWriter(clientSocket.getOutputStream());
ps.println(new String(new StringBuffer(r)));
ps.flush();
}
else if(!t.substring(9,17).equals("wang2886")){
String s="P";
PrintWriter ps=new PrintWriter(clientSocket.getOutputStream());
ps.println(new String(new StringBuffer(s)));
ps.flush();
}
else{
String k="O";
PrintWriter ps=new PrintWriter(clientSocket.getOutputStream());
ps.println(new String(new StringBuffer(k)));
ps.flush();
}
clientSocket.close();
}catch(IOException e){System.err.println(e);}
} */
}
public void SetText(String s){
this.InformationText.setText(s);
}
// 变量声明 - 不进行修改//GEN-BEGIN:variables
private javax.swing.JTextArea InformationText;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JList 所有用户;
private javax.swing.JLabel 消息框;
// 变量声明结束//GEN-END:variables
public static OnLineListArray clientOnlineList; //定义一个数组,用来存放在线用户的线程映射关系
public static String ClientList[]=null;
public static int Length=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -