http://www.cn-java.com/target/news.php?news_id=1328

解决方案 »

  1.   

    我有的是:早说呀。
    帮人都解决好几个了。
    QQ:12318872
    MAIL:[email protected]
      

  2.   

    程序源码如下:谢谢帮忙
    public class SendApplet extends JApplet {
      boolean isStandalone = false;
      Label sendLabel=new Label();
      Label messageInfo=new Label();
      Button sendButton=new Button();
      TextField sendText=new TextField();
      TextField messageText=new TextField();
      URLConnection connect;
      String message;
      URL chatURL;
      XYLayout xYLayout1 = new XYLayout();
      //Get a parameter value
      public String getParameter(String key, String def) {
        return isStandalone ? System.getProperty(key, def) :
          (getParameter(key) != null ? getParameter(key) : def);
      }  //Construct the applet
      public SendApplet() {
      }
      //Initialize the applet
      public void init() {
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      //Component initialization
      private void jbInit() throws Exception {
        sendLabel.setText("请输入信息:");
        this.getContentPane().setLayout(xYLayout1);
        messageInfo.setText("你输入的信息是:");
        sendButton.setLabel("发送");
        sendButton.addActionListener(new java.awt.event.ActionListener()
                                    {public void actionPerformed(ActionEvent e){sendButton_actionPerformed(e);}
                                    }
                                    );
        messageText.setEditable(false);
        xYLayout1.setWidth(400);
        xYLayout1.setHeight(129);
        sendText.addActionListener(new java.awt.event.ActionListener()
                                  {public void actionPerformed(ActionEvent e){sendText_actionPerformed(e);}
                                  }
                                  );
        this.getContentPane().add(sendLabel,  new XYConstraints(0,0,400,-1));
        this.getContentPane().add(messageInfo,  new XYConstraints(9,58,388,19));
        this.getContentPane().add(sendText,  new XYConstraints(6,24,205,-1));
        this.getContentPane().add(sendButton,  new XYConstraints(210,24,187,22));
        this.getContentPane().add(messageText,  new XYConstraints(5,89,400,-1));
        chatURL=getCodeBase();
      }
      //Get Applet information
      public String getAppletInfo() {
        return "Applet Information";
      }
      //Get parameter info
      public String[][] getParameterInfo() {
        return null;
      }  //static initializer for setting look & feel
      public synchronized void start()
      {
      }
      public synchronized void stop()
      {
      }
      public synchronized void destroy()
      {
      }
      void Send()
      {
         message=sendText.getText();
         sendText.setText("");
         showStatus("Message sent!");
         String queryString="servlettoapplet.ReceiveServlet?message=" + URLEncoder.encode(message);
         try{
            connect=(new URL(chatURL,queryString)).openConnection();
            showStatus("Open Connection!");
            connect.setDefaultUseCaches(false);
            connect.setUseCaches(false);
            connect.setDoInput(true);
            connect.setDoOutput(false);
            connect.connect();
            showStatus("打开流");
            DataInputStream in=new DataInputStream(connect.getInputStream());
            showStatus("读数据");
            message=in.readLine();
            while(message!=null)
            {
               messageText.setText(message);
               message=in.readLine();
            }
         }
         catch(MalformedURLException e2)
         {
            System.err.println("MalformedURLException!");
            e2.printStackTrace(System.err);
            showStatus("MalformedURLException!");
         }
         catch(IOException e1)
         {
            System.err.println("IOException!");
            e1.printStackTrace(System.err);
            showStatus("IOException!");
         }
      }
      public void sendButton_actionPerformed(ActionEvent e)
      {
         Send();
      }
      public void sendText_actionPerformed(ActionEvent e)
      {
         Send();
      }
    }