⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 appletcommunicate.java

📁 java servlet 示例共有17个示例程序
💻 JAVA
字号:
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){
				}
			}});
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -