【求教】这个是怎么回事啊??? http://tieba.baidu.com/p/2038990107 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.awt.*;import java.awt.event.*;import java.net.*;import java.io.*;public class CharClient extends Frame {Socket s=null;TextField tfTxt = new TextField();TextArea taContent = new TextArea(); public static void main(String[] args) {new CharClient().LanchFrame();new CharClient().connect();} public void LanchFrame() {setSize(200, 100);setLocation(100, 100);add(tfTxt, BorderLayout.SOUTH);add(taContent, BorderLayout.NORTH);pack();this.addWindowListener(new WindowAdapter(){ @Overridepublic void windowClosing(WindowEvent arg0) {System.exit(0);}});tfTxt.addActionListener(new tfListener());setVisible(true);}public void connect(){try { s=new Socket("localhost",8888);}catch(Exception e){e.getStackTrace();}}public class tfListener implements ActionListener{ @Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubString str=tfTxt.getText().trim();taContent.setText(str);tfTxt.setText("");try{DataOutputStream dis=new DataOutputStream(s.getOutputStream());dis.writeUTF(str);dis.flush();dis.close();}catch(Exception e1){e1.getStackTrace();}}}} import java.io.*;import java.net.*; public class ChatServer { public static void main(String[] args) {try {ServerSocket ss = new ServerSocket(8888);while(true){Socket s = ss.accept();DataInputStream dos=new DataInputStream(s.getInputStream());String str1=dos.readUTF();System.out.println("qqq");System.out.println(str1);dos.close();} }catch (IOException e) {e.getStackTrace();}catch(Exception e2){e2.getStackTrace();}} } 客户端的socket断开了所以服务端没收到数据将 s=new Socket("localhost",8888);移到 public void actionPerformed(ActionEvent e) {里面 放在try{ 的后面即可 finalize()方法的使用问题 何如把一个List<String>里的值,赋给另一个List 求助 XML 转 model 函数 JTable 如何监听单元格单击事件?? 我一直不太明白的一个关于继承方面的问题 怎样得到在屏幕中鼠标位置 请问如何通过JFileChoose 选择文件??? 請有簡繁轉換的class或gb2312-big5對照表? JTable的刷新问题! sessionbean调用entitybean的时候还需要像Client一样远程调用对象吗?? java中的i++和C语言中的i++ 求帮助,画小球,小球无法显示出来
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class CharClient extends Frame {
Socket s=null;
TextField tfTxt = new TextField();
TextArea taContent = new TextArea(); public static void main(String[] args) {
new CharClient().LanchFrame();
new CharClient().connect();
} public void LanchFrame() {
setSize(200, 100);
setLocation(100, 100);
add(tfTxt, BorderLayout.SOUTH);
add(taContent, BorderLayout.NORTH);
pack();
this.addWindowListener(new WindowAdapter(){ @Override
public void windowClosing(WindowEvent arg0) {
System.exit(0);
}});
tfTxt.addActionListener(new tfListener());
setVisible(true);
}
public void connect(){
try { s=new Socket("localhost",8888);}catch(Exception e){
e.getStackTrace();
}
}
public class tfListener implements ActionListener{ @Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String str=tfTxt.getText().trim();
taContent.setText(str);
tfTxt.setText("");
try{DataOutputStream dis=new DataOutputStream(s.getOutputStream());
dis.writeUTF(str);
dis.flush();
dis.close();
}catch(Exception e1){
e1.getStackTrace();
}
}
}
}
import java.net.*; public class ChatServer { public static void main(String[] args) {
try {
ServerSocket ss = new ServerSocket(8888);
while(true){
Socket s = ss.accept();
DataInputStream dos=new DataInputStream(s.getInputStream());
String str1=dos.readUTF();
System.out.println("qqq");
System.out.println(str1);
dos.close();
}
}catch (IOException e) {
e.getStackTrace();
}
catch(Exception e2){
e2.getStackTrace();
}
} }
所以服务端没收到数据将 s=new Socket("localhost",8888);
移到
public void actionPerformed(ActionEvent e) {
里面
放在try{ 的后面即可