压缩包内是近180多个针对Java初学者编写的简单实例

源代码在线查看: sender.java

软件大小: 238 K
上传用户: RR15133422795
关键词: Java 180 初学者 编写
下载地址: 免注册下载 普通下载 VIP

相关代码

				import java.applet.*;
				import java.awt.*;
				import java.awt.event.*;
				public class Sender extends Applet implements ActionListener
				{
					private String myName;
					private TextField nameField;
					private TextArea status;
					private String newline; //设置各种私有变量,用于表示各种信息
					public void init()
					{
						GridBagLayout gridBag=new GridBagLayout();
						GridBagConstraints c =new GridBagConstraints();
						setLayout(gridBag);
						Label receiverLabel=new Label("接收名称是:",Label.RIGHT);
						gridBag.setConstraints(receiverLabel,c);
						add(receiverLabel);//添加接收信息标签
						nameField=new TextField(getParameter("REVEIVERNAME"),10);
						c.fill=GridBagConstraints.HORIZONTAL;
						gridBag.setConstraints(nameField,c);
						add(nameField);
						nameField.addActionListener(this);
						Button button=new Button("发送信息");
						c.gridwidth=GridBagConstraints.REMAINDER;
						c.anchor=GridBagConstraints.WEST;
						c.fill=GridBagConstraints.NONE;
						gridBag.setConstraints(button,c);
						add(button);//添加按钮信息
						button.addActionListener(this);//添加按键事件
						status=new TextArea(5,60);
						status.setEditable(false);//设置状态栏
						c.anchor=GridBagConstraints.CENTER;
						c.fill=GridBagConstraints.BOTH;
						c.weightx=1.0;
						c.weighty=1.0;
						gridBag.setConstraints(status,c);
						add(status);
						myName=getParameter("NAME");//获得Applet的名字,此时"name"属性是在HTML页面上添加的
						Label senderLabel=new Label("(我的名字是 "+""+")",Label.CENTER);
						c.weightx=0.0;
						c.weighty=0.0;
						gridBag.setConstraints(senderLabel,c);
						add(senderLabel);//完成添加标签			

相关资源