Applet代码:
package p9;
import java.applet.Applet;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import org.alicebot.ab.*;
import org.alicebot.ab.utils.IOUtils;
public class CHAT extends Applet implements ActionListener
{
public static TextField tf;
public static TextArea ta;
public static Bot bot;
public static Chat chatSession;
public static String r;
public static String textLine;
public void init()
{
r="C:\\Users\\ASUS\\Desktop\\program-ab-0.0.4.3 (1)";
bot = new Bot("super", r);
chatSession = new Chat(bot);
Color c=Color.ORANGE;
setBackground(c);
tf=new TextField(200);
ta=new TextArea(50,250);
ta.setEditable(false);
setLayout(new FlowLayout());
add(ta);
add(tf);
tf.addActionListener(this);
//setSize(400,400);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent ae)
{
try
{
textLine = "";
textLine = tf.getText();
if ((textLine == ""))
textLine = MagicStrings.null_input;
else
{
ta.append("YOU-> "+textLine+"\n\n");
String request = textLine;
String response = chatSession.multisentenceRespond(request);
ta.append("ROBOT-> " + response+"\n\n");
tf.setText("");
if(request.toLowerCase().equals("bye"))
System.exit(0);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
HTML代码:
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<applet code="p9.CHAT" archive="APPLET.jar" height="400" width="400"></applet>
</body>
</html>
我正在使用Netbeans IDE 8.2。当我尝试运行上述代码时,它在Firefox中仅显示空白屏幕。 APPLET是一个Java类库,已将其添加到Web应用程序中。 当我运行Applet程序时,它可以与AppletViewer一起正常工作,但是当我尝试以html格式加载applet时,则无法加载。 我已经使用了JSP插件和Applet标签。