HTML不会显示带有JLabel的Java Applet

时间:2013-01-25 15:03:45

标签: java html applet jlabel

当我执行与我的applet关联的HTML文件时,不会绘制任何内容并且屏幕为空。为什么会这样?如何在Applet中添加String?

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");
    }
}
}

0 个答案:

没有答案