给定一个程序,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();
}
}
}
}
} 展开
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();
}
}
}
}
} 展开
1个回答
2016-06-22
展开全部
引用 java.awt.*
java.awt.event.*
javax.swing.*
等包、类,,,,,然后 添加界面组件 。。。。
java.awt.event.*
javax.swing.*
等包、类,,,,,然后 添加界面组件 。。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询