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

📄 sameapplettesta.java

📁 用于演示java的一些applet的例子
💻 JAVA
字号:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Enumeration;

public class SameAppletTesta extends Applet implements ActionListener{
	private TextField tfObj;
	private TextField conObj;
	private String nameObj;
	private TextArea taObj;
	private String enterObj;
	
	public void init(){
		GridBagLayout gridBag = new GridBagLayout();
		GridBagConstraints c = new GridBagConstraints();
		setLayout(gridBag);
		/*指定接收方*/
		Label labelObj = new Label("接收方:",Label.RIGHT);
		gridBag.setConstraints(labelObj,c);
		add(labelObj);
				
		tfObj = new TextField(getParameter("RECEIVERNAME"),10);
		c.fill = GridBagConstraints.HORIZONTAL;
		gridBag.setConstraints(tfObj,c);
		add(tfObj);
		tfObj.addActionListener(this);
		/*发送的消息*/
		Label conLab = new Label("信息:",Label.RIGHT);
		gridBag.setConstraints(conLab,c);
		add(conLab);
		
		conObj = new TextField(16);
		gridBag.setConstraints(conObj,c);
		add(conObj);
		/*发送按钮*/
		Button butObj = new Button("发送");
		c.gridwidth = GridBagConstraints.REMAINDER;
		c.anchor = GridBagConstraints.WEST;
		c.fill = GridBagConstraints.NONE;
		gridBag.setConstraints(butObj,c);
		add(butObj);
		butObj.addActionListener(this);
		/*操作信息提示*/
		taObj = new TextArea(5,40);
		taObj.setEditable(false);
		c.anchor = GridBagConstraints.CENTER;
		c.fill = GridBagConstraints.BOTH;
		c.weightx = 1.0;
		c.weighty = 1.0;
		gridBag.setConstraints(taObj,c);
		add(taObj);
		/*显示当前Applet的名称*/
		nameObj = getParameter("NAME");
		Label sendLabel = new Label("My Name is "+ nameObj +".",Label.CENTER);
		c.weightx = 0.0;
		c.weighty = 0.0;
		gridBag.setConstraints(sendLabel,c);
		add(sendLabel);
		
		enterObj = System.getProperty("line.separator");
		
	}
	public void actionPerformed(ActionEvent event){
		Applet receiver = null;
		String receiverName = tfObj.getText();
		receiver = getAppletContext().getApplet(receiverName);
		if(receiver!= null){
			if(!(receiver instanceof SameAppletTestb)){
				taObj.append("Found applet named "+receiverName+"," +"but it's not a Receiver object"+enterObj);
			}else{
			taObj.append("Found applet named "+receiverName+enterObj +" Sending message to it."+ enterObj);
			((SameAppletTestb)receiver).processRequestFrom(nameObj,conObj.getText());
			}
		}else{
		taObj.append("Couldn't find any applet named" + receiverName + "." + enterObj);
		}
	}	
}

⌨️ 快捷键说明

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