一个applet,用appletviewer查看,显示正常,用浏览器查看,却不显示。

sleepingtiger 2001-05-22 01:46:00
applet代码如下:

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

public class chatapplet extends Applet
{
Panel mainPanel = new Panel();
BorderLayout borderLayout1 = new BorderLayout();
Panel leftPanel = new Panel();
Panel rightPanel = new Panel();
Label userInfo = new Label();
Panel innerPanel = new Panel();
TextField userText = new TextField();
Button sendButton = new Button();
TextArea messageText = new TextArea();
Label messageInfo = new Label();
Label listInfo = new Label();
List userList=new List();
BorderLayout borderLayout3 = new BorderLayout();
GridBagLayout gbl2 = new GridBagLayout();
GridBagLayout gbl3 = new GridBagLayout();
GridBagLayout gbl1 = new GridBagLayout();

public synchronized void init()
{
super.init();
this.setLayout(borderLayout1);
mainPanel.setLayout(gbl1);
rightPanel.setLayout(borderLayout3);
leftPanel.setLayout(gbl2);
userInfo.setText("Enter User Name(max 10 char)");
innerPanel.setLayout(gbl3);
sendButton.setLabel("Send");
messageInfo.setText("Message Text");
messageText.setEditable(false);
listInfo.setText("User Logged in:");
userList.add("No one logged in");
this.add(mainPanel, BorderLayout.CENTER);
mainPanel.add(leftPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 20, 10, 0), 26, 33));
leftPanel.add(userInfo, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
leftPanel.add(messageText, new GridBagConstraints(0, 3, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 235));
leftPanel.add(innerPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
innerPanel.add(userText, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 10), 221, 7));
innerPanel.add(sendButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
leftPanel.add(messageInfo, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
mainPanel.add(rightPanel, new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 20, 10, 20), 7, 353));
rightPanel.add(listInfo, BorderLayout.NORTH);
rightPanel.add(userList, BorderLayout.CENTER);
}
}

applettest.html文件如下:
<html>
<head>
<title>applet test</title>
</head>
<body>
<p>Welcome! This is a test of communication
<br>
<applet code="chatapplet.class" width="800" height="600"></applet>
</body>
</html>

在浏览器中查看只有一个空的applet区域,提示错误信息:
java.lang.NoSuchMethodError: java/awt/GridBagConstraints: method <init>(IIIIDDIILjava/awt/Insets;II)V not found
at chatapplet.init
at com/ms/applet/AppletPanel.securedCall0
at com/ms/applet/AppletPanel.securedCall
at com/ms/applet/AppletPanel.processSentEvent
at com/ms/applet/AppletPanel.processSentEvent
at com/ms/applet/AppletPanel.run
at java/lang/Thread.run

但是用appletviewer,显示又正常,请高手指点。
...全文
573 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
sleepingtiger 2001-06-09
  • 打赏
  • 举报
回复
TO rabbit:
看来那个GridBagConstraints的构造方法有问题,我试着用另外的方法就成功了,只是我感到奇怪,GridBagConstraints是java.awt包中的,而我用的是jdk1.3,应该不会产生兼容性问题,我查看了帮助文件,并没有提到这个构造方法的使用在版本上有什么限制。
贴出来的代码是在JBuilder4.0中生成的。
rabbit 2001-06-05
  • 打赏
  • 举报
回复
你使用了一个GridBagConstraints在jdk1.1中没有实现的方法。
你可以使用JBuilder2.0,试着编译。
肯定有错。
前几天,我用了Vector的add(Object)方法,在AppletViewer中能成功允许
但在IE5中,始终不行,用JB2后才知道JDK1.1没有Add方法
只有addElement方法。
sleepingtiger 2001-05-23
  • 打赏
  • 举报
回复
致各位高手:
我用ultraedit写的程序,而且特别注意只用java.awt.*包中的组件,防止IE不支持swing。请高手将我的代码复制回去运行一下,帮我好好看看,在下感激不尽。
xzwsun 2001-05-22
  • 打赏
  • 举报
回复
要安装JAVA PLUG_IN插件与swing组件,需要上网下载,然后在CLASSPATH 中设置CLASSPATH=WORPATH\swingall.jar,就可以在IE下显示,还ie的版本需要5.0以上最好为IE5.0
xzwsun 2001-05-22
  • 打赏
  • 举报
回复
要安装JAVA PLUG_IN插件与swing组件,需要上网下载,然后在CLASSPATH 中设置CLASSPATH=WORPATH\swingall.jar,就可以在IE下显示,还ie的版本需要5.0以上最好为IE5.0
kook 2001-05-22
  • 打赏
  • 举报
回复
俺才来的,啥分也没,参与吧,您多少给点
skyyoung 2001-05-22
  • 打赏
  • 举报
回复
用vj++写的吗,引用了微软的类库。改成标准的java类库写吧。

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧