给定一个程序,Java如何把字符界面变成图形界面啊,,,,大概是怎么改???

importjava.io.*;importjava.net.*;importjava.util.*;publicclassChatServer{publicstatic... import java.io.*;

import java.net.*;

import java.util.*;

public class ChatServer {

public static final int PORT = 8888;

boolean started = false;

ServerSocket ss = null;

List<Client> clientList = new ArrayList<Client>();

public void start() throws IOException

{

ss = new ServerSocket(PORT);

started = true;

System.out.println("begin server!");

while(started) {

Socket s = ss.accept();

System.out.println("a client connected: "+s);

Client c = new Client(s);

new Thread(c).start();

clientList.add(c);

}

ss.close();

}

public static void main(String[] args) throws IOException

{

new ChatServer().start();

}

class Client implements Runnable {

private Socket s;

private boolean bConnected = false;

BufferedReader in = null;

PrintWriter out = null;

public Client(Socket s) {

this.s = s;

bConnected = true;

}

public void send(String str) {

try {

out.println(str);

} catch (Exception e) {

clientList.remove(this);

System.out.println("移除失效连接!");

}

}

public void run()

{

try {

in = new BufferedReader(new InputStreamReader(s.getInputStream()));

out = new PrintWriter(new BufferedWriter(

new OutputStreamWriter(s.getOutputStream())),true);

while(bConnected)

{

String str = in.readLine();

System.out.println(str);

for(int i=0; i<clientList.size(); i++)

{

Client c = clientList.get(i);

c.send(str);

}

/*

if(str.equalsIgnoreCase("exit"))

{

System.out.println("1111");

//clientList.remove(this);

}else

{

for(int i=0; i<clientList.size(); i++)

{

Client c = clientList.get(i);

c.send(str);

}

}

*/

}

} catch (EOFException e) {

System.out.println("Client closed!+EOFException");

//e.printStackTrace();

} catch (SocketException e) {

System.out.println("Client closed!+SocketException");

e.printStackTrace();

}

catch (IOException e) {

e.printStackTrace();

} finally {

try {

if(out != null) out.close();

if(in != null) in.close();

if(s != null) s.close();

} catch (IOException e1) {

e1.printStackTrace();

}

}

}

}

}
展开
 我来答
匿名用户
2016-06-22
展开全部
引用 java.awt.*
java.awt.event.*
javax.swing.*

等包、类,,,,,然后 添加界面组件 。。。。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式