📄 sameapplettestb.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -