[求助]有关聊天程序的代码?请问错在哪里呢?
import java.io.*;import java.net.*;
import java.awt.*;
import java.awt.event.*;
public class SocketServerExample extends Frame implements ActionListener
{
Label label=new Label("输入聊天信息");
TextField tf=new TextField(20);
TextArea ta=new TextArea();
Panel panel=new Panel();
ServerSocket server;
Socket Client;
InputStream DataIn;
OutputStream DateOut;
public SocketServerExample()
{
super("这里是服务器");
setSize(300,180);
panel.add(label);
panel.add(tf);
tf.addActionListener(this);
add("North",panel);
add("Center",ta);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);}});
show();
try
{
server=new ServerSocket(5000);
Client=server.accept();
ta.append("已经和客户机连接:"+Client.getInetAddress().getHostName()+"\n\n");
DataIn=Client.getInputStream();
DataOut=Client.getOutputStream();
}
catch(IOException ioe){}
while(true)
{
try
{
byte buff[]=new byte[512];
DataIn.read(buff);
String str=new String(buff);
ta.append("客户机说:"+str+"\n");
}
catch(IOException ioe){}
}
}
public static void main(String args[])
{
new SocketServerExample();}
public void actionPerformed(ActionEvent e)
{
try
{
String str=new String(tf.getText());
byte buf[]=str.getBytes();
tf.setText("");
DataOut.Write(buf);
ta.append("\n服务器说:"+str+"\n");
}
catch(IOException ie){}
}
}
编译时显示:--------------------Configuration: <Default>--------------------
F:\java\myself\SocketServerExample.java:36: 找不到符号
符号: 变量 DataOut
位置: 类 SocketServerExample
DataOut=Client.getOutputStream();
^
F:\java\myself\SocketServerExample.java:61: 找不到符号
符号: 变量 DataOut
位置: 类 SocketServerExample
DataOut.Write(buf);
可是我实在找不出有什么错啊?