一个applet,用appletviewer查看,显示正常,用浏览器查看,却不显示。
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,显示又正常,请高手指点。