我有 Java Applet 的下一个代码源:
package m2mcom.web;
import m2mcom.entities.AutomatedTelnetClient;
import javax.swing.JApplet;
import javax.swing.SwingUtilities;
import javax.swing.JLabel;
public class Displaytext extends JApplet {
//Called when this applet is loaded into the browser.
public void init() {
//Execute a job on the event-dispatching thread; creating this applet's GUI.
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
AutomatedTelnetClient telnet = new AutomatedTelnetClient();
String answer = telnet.request();
JLabel lbl = new JLabel(answer);
add(lbl);
}
});
} catch (Exception e) {
System.err.println("createGUI didn't complete successfully");
}
}
}
telnet 请求是在 AutomatedTelnetClient 类中发出的,一旦获得响应,会话也会关闭。当我执行 .html 文件时,没有绘制任何内容并且屏幕为空。任何人都知道它为什么会这样。还有其他方法可以将字符串添加到 Applet 中吗?难道问题出在 SwingUtilities 的 inovkeAndWait 上吗?
这是 HTML:
<HTML>
<HEAD>
</HEAD>
<BODY>
<div >
<APPLET CODE="m2mcom.web.Displaytext.class" WIDTH="800" HEIGHT="500">
</APPLET>
</div>
</BODY>
</HTML>