服务器端
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.swtdesigner.SWTResourceManager;
public class server extends Shell { private Text text_1;
private Text text;
private ServerSocket ss;
private Socket s;
private DataOutputStream dos ;
private DataInputStream dis;
private String str;
boolean i =false;
private String [] st;
private String string;
Mywind my = new Mywind(Display.getDefault(),SWT.SHELL_TRIM);
/**
 * Launch the application
 * @param args
 */
public static void main(String args[]) {
try {
Display display = Display.getDefault();
server shell = new server(display, SWT.SHELL_TRIM);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
} catch (Exception e) {
e.printStackTrace();
}
} /**
 * Create the shell
 * @param display
 * @param style
 */
public server(Display display, int style) {
super(display, style);
createContents();
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
setLayout(gridLayout);
} /**
 * Create contents of the window
 */
protected void createContents() {
setText("服务器");
setSize(500, 375); text = new Text(this, SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
new Label(this, SWT.NONE); text_1 = new Text(this, SWT.BORDER);
text_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
new Label(this, SWT.NONE); final Button button = new Button(this, SWT.NONE);
button.setText("发送"); final Composite composite = new Composite(this, SWT.NONE);
composite.setBackground(SWTResourceManager.getColor(64, 128, 128));
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
composite.setLayout(new GridLayout());
composite.addMouseListener(new MouseAdapter(){
@Override
public void mouseDown(MouseEvent e) {
my = new Mywind(e.display,SWT.SHELL_TRIM);
my.open();
Mywind.setbutton().addSelectionListener(new SelectionAdapter(){
@Override
public void widgetSelected(SelectionEvent e) {
try {
string = Mywind.setText_1().getText();
System.out.println(string);
dos.writeUTF(string);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
}
});

try {
 ss = new ServerSocket(8888);
 s=ss.accept();
 i =true;
 composite.setBackground(SWTResourceManager.getColor(64, 128, 255));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
dos = new DataOutputStream(s.getOutputStream());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
dis = new DataInputStream(s.getInputStream());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
new Thread(new Runnable(){
@Override
public void run() {
while(i){
try {
str=dis.readUTF();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(str.equals("bye")){
System.out.println("已经下了");
Display.getDefault().asyncExec(new Runnable(){ @Override
public void run() {
// TODO Auto-generated method stub
composite.setBackground(SWTResourceManager.getColor(64, 128,0));
Display.getDefault().getActiveShell().layout();
}

});
break;
}
Display.getDefault().asyncExec(new Runnable(){
@Override
public void run() {
// TODO Auto-generated method stub
{
composite.addMouseListener(new MouseAdapter(){
@Override
public void mouseDown(MouseEvent e) {
System.out.println(str);
my.open();
Mywind.setText().append(str);
my.getShell().layout();
i=true;
}
});

}

}

});
}
}
}).start();

} @Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}
class Mywind extends Shell {
private Display display;
private int syte;
private static Text text;
private static Text text_1;
private static Button button;
public Mywind(Display display,int syte) {
this.display=display;
this.syte=syte;
init();
}
private void init() {
// TODO Auto-generated method stub
setSize(400, 400);
text = new Text(this,SWT.BORDER);
text.setBounds(0, 0, 400, 150);
text_1 = new Text(this,SWT.BORDER);
text_1.setBounds(0,150, 400, 150);
button = new Button(this,SWT.BORDER);
button.setBounds(0, 300, 40, 40);
button.setText("发送");
}
public static Text setText(){
return text;
}
public static Text setText_1(){
return text_1;
}
public static Button setbutton(){
return button;
}

@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}客户端
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class client extends Shell { private Text text_1;
private Text text;
private Socket s;
private String str;
private DataOutputStream dos ;
private DataInputStream dis;
private String js;
/**
 * Launch the application
 * @param args
 */
public static void main(String args[]) {
try {
Display display = Display.getDefault();
client shell = new client(display, SWT.SHELL_TRIM);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
} catch (Exception e) {
e.printStackTrace();
}
} /**
 * Create the shell
 * @param display
 * @param style
 */
public client(Display display, int style) {
super(display, style);
createContents();
setLayout(new GridLayout());
} /**
 * Create contents of the window
 */
protected void createContents() {
setText("客户端");
setSize(500, 375); text = new Text(this, SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); text_1 = new Text(this, SWT.BORDER);
text_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); final Button button = new Button(this, SWT.NONE);
button.setText("发送");
button.addSelectionListener(new SelectionAdapter(){
@Override
public void widgetSelected(SelectionEvent e) {

try {
str = text_1.getText();
dos.writeUTF(str);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
//
try {
s = new Socket("127.0.0.1",8888);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
dos = new DataOutputStream(s.getOutputStream());
dis = new DataInputStream(s.getInputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
addDisposeListener(new DisposeListener() {
public void widgetDisposed(final DisposeEvent e) {
try {
dos.writeUTF("bye");
dos.close();
dis.close();
s.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
new Thread(new Runnable(){ @Override
public void run() {
// TODO Auto-generated method stub
try {
js =dis.readUTF();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Display.getDefault().asyncExec(new Runnable(){ @Override
public void run() {
// TODO Auto-generated method stub
text.append(js);
}

});
}

}).start();
} @Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}}
那位大侠帮我改一下服务器端得代码呀 !
就是客户端每发过来一次信息。然后点击那个带颜色的面板就会然后弹出来的窗口里面赋的值总是最后客户端发来的信息
我想把他改为。每次客户端发来的信息只要点击带颜色的窗口就会一一显示在那个弹出的窗口上
请大侠们看看代码就知道我说的是什么意思了!
最后大侠们亲自先试一试然后更明白我的意思了!
谢谢大侠们了