import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.net.URL;
/*
<applet code=AppletCommunicate width=250 height=200></applet>
*/
public class AppletCommunicate extends JApplet
{
	JTextArea msg = new JTextArea(200, 150);
	JButton send = new JButton("通讯");
		
	public void init() {
		Container cp = this.getContentPane();
		cp.add(BorderLayout.NORTH, 	new JLabel("点击按钮从Servlet获取数据"));
		cp.add(BorderLayout.CENTER, msg);
		cp.add(BorderLayout.SOUTH, send);
		
		send.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				try {
					DataInputStream in = new DataInputStream(
						new URL("http://localhost/servlet/b").openStream());
						
					String str = in.readLine();
					if(str != null)
						msg.append("From server:" +str +"\n");
				}catch(IOException e){
				}
			}});
	}
}