sameapplettestb.java

来自「用于演示java的一些applet的例子」· Java 代码 · 共 49 行

JAVA
49
字号
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class SameAppletTestb extends Applet implements ActionListener{
	private final String waitingMessage = "Waiting for a message...";
	private Label labObj = new Label(waitingMessage,Label.RIGHT);
	private TextArea taObj;
	private String lineObj;
	private String nameObj;
	public void init(){
		GridBagLayout gridBag = new GridBagLayout();
		GridBagConstraints c = new GridBagConstraints();
		setLayout(gridBag);
		/*添加提示信息和“清除”按钮*/
		Button butObj = new Button("清除");
		gridBag.setConstraints(labObj,c);
		add(labObj);
		c.gridwidth = GridBagConstraints.REMAINDER;
		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);
	}
	public void actionPerformed(ActionEvent event){
		labObj.setText(waitingMessage);
		taObj.setText("");
	}
	public void processRequestFrom(String senderName,String conStr){
		lineObj = System.getProperty("line.separator");
		labObj.setText("  Received message from "+senderName +"!");
		taObj.append(conStr+lineObj);
	}
}

⌨️ 快捷键说明

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