http://java.sun.com/products/java-media/

解决方案 »

  1.   

    whuise (情磁场):
        好累!整整调试了二十分钟!
      你的服务器端程序没有问题,但客户端程序的确是编译通过而不能运行。这里我就对客户端程序说一下:
      在MyClient类中,你写了一个构造函数:public void MyClient(),不知你注意没有,构造函数是不可随便设定类型的,而这里你设为void类型,于是主程序并没有调用该构造函数,这可以通过在构造函数第一句加一个输出测试语句来证明。
      解决的办法是,把public void MyClient()
                   改为public MyClient()
      一切解决了!!
      在你的程序中,有不少地方是有警告的,而且在客户端的窗口并没有监听,即窗口不能关闭,所以最好加几句用以监听窗口的代码(鉴于时间,我不加上去了)。
        随便说一句,如果你的JDK是1.2版本以上的话,完全可以运行这个程序,没必要去换编译器,只是为了正确性,那几处警告要注意一下。
      最后,我把端户的源程序再复写一遍,有问题再跟我联系:
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    public class MyClient extends Frame implements ActionListener
    {
    Socket ClientSocket;
    PrintStream os;
    DataInputStream is;
    String s;
    Label MyLabel=new Label("welcome to our host services");
    TextArea textArea;
    Button myButton=new Button("send");
    public MyClient()
    {
    setTitle("Client Window");
    setLayout(new BorderLayout());
    this.addWindowListener(new WinAdptClient(this));
    myButton.addActionListener(this);
    textArea=new TextArea(20,50);
    add("North",MyLabel);
    add("South",myButton);
    add("Center",textArea);
    setResizable(false);
    pack();
    show();
    connect();
    }
    public void connect()
    {
    try{
    ClientSocket=new Socket("Ym",8000);
    os=new PrintStream(new BufferedOutputStream(ClientSocket.getOutputStream()));
    is=new DataInputStream(new BufferedInputStream(ClientSocket.getInputStream()));
    s=is.readLine();
    textArea.appendText(s+"\n");
    }
    catch(Exception e){}
    }
    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource()==myButton)
    {
    try{
    os.print(textArea.getText());
    os.flush();
    }
    catch(Exception ex){}
    }
    }
    public static void main(String args[])
    {
    new MyClient();
    }
    }
    class WinAdptClient extends WindowAdapter
    {
    MyClient m_Parent;
    WinAdptClient(MyClient p)
    {
    m_Parent=p;
    }
    public void windowClosing(WindowEvent e)
    {
    try{
    m_Parent.os.println("Bye");
    m_Parent.os.flush();
    m_Parent.is.close();
    m_Parent.os.close();
    m_Parent.ClientSocket.close();
    m_Parent.dispose();
    System.exit(0);
    }
    catch(Exception ex){}
    }
    }