[求助]请看下面代码
1 import java.io.*;2 import java.net.*;
3 import java.awt.*;
4 import java.awt.event.*;
5 public class Server
6 {
7 public static void main(String[] args)
8 {
9 ServerService MyServer=new ServerService(6000,10);
10 }
11 }
12 class SerivceThread extends Frame implements Runnable
13 {
14 ServerService FatherListener;
15 Socket ConnectedClient;
16 Thread ConnectedThread;
17 Panel ListenerPanel;
18 TextArea ServerMeg;
19 public ServiceThrea(ServerService sv,Socket s){
20 FatherListener=sv;
21 ConnectedClient=s;
22 ConnectThread=new Thread(this);
23 Title("Server(服务器端)");
24 setLayout(new BorderLayout());
25 ServerMeg=new TextArea(13,50);
26 add("Center",ServerMeg);
27 setResizable(false);
28 pack();
29 setVisible(true);
30 InetAddress ClientAddress=ConnectedClient.getInetAddress();
31 ServerMeg.appendText("Server connect"+" to:\n\n"+ClientAddress.toString()+".\n");
32 }
33 public void run(){
DataInputStream in=new DataInputStream(new BufferedInputStream(ConnectedClient.getInputStream()));
PrintStream out=new PrintStream(new BufferedOutputStream(ConnectedClient.getInputStream()));
out.println("Hello!,Welcome connect to me(server)!\r");
out.flush();
String s=in.readLine();
while(!s.equals("Bye")){
ServerMeg.appendText("client 端输入的信息为:\n"+s);
s=in.reaLine();
ConnectedClient.close();
FatherListener.adMeg("Client"+"closed."+"+\n");
dispose();
}
}
class ServerService extends Frame{
ServerSocket m_sListener;
TextArea ListenerMeg;
public ServerService(int Port,int Count){
try{
m_sListener=new ServerSocket(6000,10);
setTitle("Server Listener(监听器窗口)");
this.addWindowListener(new WinAdpt());
setLayout(new BorerLayout());
ListenerMeg=new TextArea("[监听服务已启动]\n\n\n",10,50);
add("Center",ListenerMeg);
setResizable(false);
pack();
show();
while(true){
Socket Connected=m_sListener.accept();
InetAddress ClientAddress=Connected.getInetAddress();
ListenerMeg.appendText("Client "+" connected "+"from:\n\n"+ClientAddress.toString()+".\n");
ServiceThread MyST=new SerViceThread(this,Connected);
MyST.ConnectThread.start();
}
}
catch (IOException e){}
}
public void addMeg(String s){
listenerMeg.appendText(s);
}
}
class WinAdpt extends WindowAdapter{
public void windowClosing(WindowEvent e){
((Frame)e.getWindow()).dispose();
System.exit(0);
}
}
}
大家看看十九行,那个构造函数,本来构造函数就没反回值,要番回也是它本身,但我运行时它提示要反回值,这我就更不明白了!
请大家帮帮忙!