请您编译一下这个程序(50分)...........

ezhb 2001-06-19 01:58:00
//我编译的时候老出错,这是为什么呢?请高手看看
//sendApplet.java

import java.applet.Applet;
import java.awt;
import java.net.*;
import java.io.*;

public class sendApplet extends Applet
{
Lable sendlable;
Lable messageinfor;
Button sendButton;
TextField messageText;
TextField sendText;
URLConnection connect;
String message;

public String getAppletInfo()
{
return "sendApplet - Applet to communicate with receiveServlet , Written by ding;";
}

public synchronized void init()
{
super.init();
resize(500,300);
sendlable = new Lable("Please Enter Massage");
messageInfor = new Lable("What you have send:");
sendButton = new Button("Send");
sendText = new TextField(40);
messageText = new TextField(40);
messageText.setEditable(false);


//下面实现一个Panel
Panel mainp = new Panel();
GridBagLayout gbl = new GridBaglayout();
GridBagConstraints gbc = new GridBagConstraints();
gbc.weightx = 0;
gbc.weighty = 0;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 10;
gbc.gridheight= 1;
gbc.anchor = GridBagConstraints.CENTER;
gbc.fill = GridBagConstraints.NONE;
mainp.setLayout(gbl);
gbl.setConstrains(sendable,gbc);
mainp.add(sendlable);
gbc.gridy = 1;
gbc.gridwidth = 9;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbl.setConstraints(sendText,gbc);
mainp.add(sendText);
gbc.gridx = 9;
gbc.gridwidth = 1;
gbc.fill = GridBagConstraints.NONE;
gbl.setConstraints(sendButton,gbc);
mainp.add(sendButton);
gbc.gridx = 0;
gbc.gridy = 2;
gbc.gridwidth = 10;
gbl.setConstraints(messageinfo,gbc);
mainp.add(messageInfo);
gbc.gridy = 3;
gbc.weighty = 100;
gbc.gridheight = 10;
gbc.fill = GridBagConstraints.BOTH;
gbl.setConstraints(messageText,gbc);
mainp.add(messageText);

//把实现的Panel加入Applet
setLayout(new BorderLayout());
Add("Center",mainp);

chatURL = getCodeBase();
}

public synchronized void start()
{
}

public synchronized void stop()
{
}

public synchronized void destroy()
{
}

//方法SEND 把用户在applet 中输入的字符串送给Servlet
//然后把Servlet 的处理结果显示出来

Private void Send()
{
message = sendText.getText();
//清除用户的输入信息
sendText.setText("");
showStatus("Message send!");
//把输入的字符串转化为 x-www-form-urlencoded 格式
String queryString = "/servlet/ReceiveServlet?message="+URLEncoder.encode(message);
p("Attempting to send:"+message);

//建立与Servlet的联接,并取得Servelt的输出信息
try
{
connect = (new URL(chatURL,queryString)).openConnection();
showStatus("open connection!");
//下次连接不用Cache
connect.setDefaultUseCaches(false);
//这次连接也不用Cache
connect.setUseCaches(false);
//打开淂流用于读数据
connect.setDoInput(true);
//不能用于写数据
connect.setDoOutput(false);
//服务器与客户的真正连接
connect.connect();
p("Made connection to "+connect);
showStatus("Open Stream!");
DataInputStream in = new DataInputStream(connect.getInputStream());
showStatus("reading!");
message = in.readLine();

while (message! = null)
{
messageText.setText(message);
message = in.readLine();
}

}
catch(MalformedURLException e2)
{
System.err.println("MalformedURLException!");
e2.printStackTrace(System.err);
showStatus("MalformedURLException!");
}
catch(IOException e1)
{
System.err.println("IOException!");
e2.printStackTrace(System.err);
showStatus("IOException");
}
}
}

//applet 对用户的动作作处理。
public boolean action(Event evt,Object arg)
{
if (evt.target == sendButton)
{
Send();
return true;
}
return super.action(evt,arg);
}

private void p(String debug)
{
System.err.println("app-serv-let:"+debug);
}
}
...全文
18 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
llkh 2001-06-19
import java.applet.Applet;
import java.awt.*;
import java.net.*;
import java.io.*;

public class sendApplet extends Applet
{
Label sendlable;
Label messageInfo;
Button sendButton;
TextField messageText;
TextField sendText;
URLConnection connect;
String message;
URL chatURL;
public String getAppletInfo()
{
return "sendApplet - Applet to communicate with receiveServlet , Written by ding;";
}

public synchronized void init()
{
super.init();
resize(500,300);
sendlable = new Label("Please Enter Massage");
messageInfo = new Label("What you have send:");
sendButton = new Button("Send");
sendText = new TextField(40);
messageText = new TextField(40);
messageText.setEditable(false);


//下面实现一个Panel
Panel mainp = new Panel();
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
gbc.weightx = 0;
gbc.weighty = 0;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 10;
gbc.gridheight= 1;
gbc.anchor = GridBagConstraints.CENTER;
gbc.fill = GridBagConstraints.NONE;
mainp.setLayout(gbl);
gbl.setConstraints(sendlable,gbc);
mainp.add(sendlable);
gbc.gridy = 1;
gbc.gridwidth = 9;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbl.setConstraints(sendText,gbc);
mainp.add(sendText);
gbc.gridx = 9;
gbc.gridwidth = 1;
gbc.fill = GridBagConstraints.NONE;
gbl.setConstraints(sendButton,gbc);
mainp.add(sendButton);
gbc.gridx = 0;
gbc.gridy = 2;
gbc.gridwidth = 10;
gbl.setConstraints(messageInfo,gbc);
mainp.add(messageInfo);
gbc.gridy = 3;
gbc.weighty = 100;
gbc.gridheight = 10;
gbc.fill = GridBagConstraints.BOTH;
gbl.setConstraints(messageText,gbc);
mainp.add(messageText);

//把实现的Panel加入Applet
setLayout(new BorderLayout());
add("Center",mainp);

chatURL = getCodeBase();
}

public synchronized void start()
{
}

public synchronized void stop()
{
}

public synchronized void destroy()
{
}

//方法SEND 把用户在applet 中输入的字符串送给Servlet
//然后把Servlet 的处理结果显示出来

private void Send()
{
message = sendText.getText();
//清除用户的输入信息
sendText.setText("");
showStatus("Message send!");
//把输入的字符串转化为 x-www-form-urlencoded 格式
String queryString = "/servlet/ReceiveServlet?message="+URLEncoder.encode(message);
p("Attempting to send:"+message);

//建立与Servlet的联接,并取得Servelt的输出信息
try
{
connect = (new URL(chatURL,queryString)).openConnection();
showStatus("open connection!");
//下次连接不用Cache
connect.setDefaultUseCaches(false);
//这次连接也不用Cache
connect.setUseCaches(false);
//打开淂流用于读数据
connect.setDoInput(true);
//不能用于写数据
connect.setDoOutput(false);
//服务器与客户的真正连接
connect.connect();
p("Made connection to "+connect);
showStatus("Open Stream!");
DataInputStream in = new DataInputStream(connect.getInputStream());
showStatus("reading!");
message = in.readLine();

while (message != null)
{
messageText.setText(message);
message = in.readLine();
}

}
catch(MalformedURLException e2)
{
System.err.println("MalformedURLException!");
e2.printStackTrace(System.err);
showStatus("MalformedURLException!");
}
catch(IOException e1)
{
System.err.println("IOException!");
e1.printStackTrace(System.err);
showStatus("IOException");
}
}


//applet 对用户的动作作处理。
public boolean action(Event evt,Object arg)
{
if (evt.target == sendButton)
{
Send();
return true;
}
return super.action(evt,arg);
}

private void p(String debug)
{
System.err.println("app-serv-let:"+debug);
}
}

******************************************************
书写错误太多
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2001-06-19 01:58
社区公告
暂无公告