Topic: 请教问题

  Print this page

1.请教问题 Copy to clipboard
Posted by: liminzs
Posted on: 2007-07-03 17:15

我照着书上写了2个通讯程序:
发送程序:
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);
    //jieshoufang
    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);
    //fasongxiaoxi
    Label conLab = new Label("信息:",Label.RIGHT);
    gridBag.setConstraints(conLab,c);
    add(conLab);
    conObj = new TextField(16);
    gridBag.setConstraints(conObj,c);
    add(conObj);
    //anniu
    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);

    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();
    reveiver = 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 massage to it."+enterObj);
        ((SameAppletTestb)receiver).processRequesFrom(nameObj,conObj.getText());
        }
    }else{
      taObj.append("Couldn't find any applet named"+receiverName+"."+enterObj);
    }
  }
}
接收程序:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class SameAppletTestb extends Applet implements ActionListener{
  private final String waitingMessage = "Waiting for a massage...";
  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);
    
    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);
  }
}
htm程序如下:
<html>
<applet code="SameAppletTesta.class" height="350" width="400" name="one">
<param name="receiverName" value="two">
</applet>
<p>
<applet code="SameAppletTestb.class" height="350" width="400">
<param name="name" value="two">
</applet>
</html>
但是程序编译不通,请高手指点哪里错了

2.Re:请教问题 [Re: liminzs] Copy to clipboard
Posted by: ranchgirl
Posted on: 2007-07-03 18:39

但是程序编译不通,请高手指点哪里错了


Compiler did not tell you?!

Read the error message from compiler, please!

Thanks!

3.Re:请教问题 [Re: liminzs] Copy to clipboard
Posted by: liminzs
Posted on: 2007-07-04 08:12

SameAppletTesta.java
12,13,16,37,69显示找不到符号
SameAppletTestb.java
12,13,16,37显示找不到符号


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923